- Added support for PyQt.
- Refactored widgets to catch ModuleNotFoundErrors.
This commit is contained in:
10
README.md
10
README.md
@ -1,5 +1,6 @@
|
|||||||
# lightweight_charts_python
|
# lightweight_charts_python
|
||||||
|
|
||||||
|
|
||||||
lightweight-charts-python aims to provide a simple and pythonic way to access and implement [TradingView's Lightweight Charts](https://www.tradingview.com/lightweight-charts/).
|
lightweight-charts-python aims to provide a simple and pythonic way to access and implement [TradingView's Lightweight Charts](https://www.tradingview.com/lightweight-charts/).
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
@ -147,16 +148,19 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
df = pd.read_csv('ohlcv.csv')
|
df = pd.read_csv('ohlcv.csv')
|
||||||
|
|
||||||
chart.layout(background_color='#090008', text_color='#FFFFFF', font_size=16, font_family='Helvetica')
|
chart.layout(background_color='#090008', text_color='#FFFFFF', font_size=16,
|
||||||
|
font_family='Helvetica')
|
||||||
|
|
||||||
chart.candle_style(up_color='#00ff55', down_color='#ed4807', border_up_color='#FFFFFF', border_down_color='#FFFFFF',
|
chart.candle_style(up_color='#00ff55', down_color='#ed4807',
|
||||||
|
border_up_color='#FFFFFF', border_down_color='#FFFFFF',
|
||||||
wick_up_color='#FFFFFF', wick_down_color='#FFFFFF')
|
wick_up_color='#FFFFFF', wick_down_color='#FFFFFF')
|
||||||
|
|
||||||
chart.volume_config(up_color='#00ff55', down_color='#ed4807')
|
chart.volume_config(up_color='#00ff55', down_color='#ed4807')
|
||||||
|
|
||||||
chart.watermark('1D', color='rgba(180, 180, 240, 0.7)')
|
chart.watermark('1D', color='rgba(180, 180, 240, 0.7)')
|
||||||
|
|
||||||
chart.crosshair(mode='normal', vert_color='#FFFFFF', vert_style='dotted', horz_color='#FFFFFF', horz_style='dotted')
|
chart.crosshair(mode='normal', vert_color='#FFFFFF', vert_style='dotted',
|
||||||
|
horz_color='#FFFFFF', horz_style='dotted')
|
||||||
|
|
||||||
chart.legend(visible=True, font_size=14)
|
chart.legend(visible=True, font_size=14)
|
||||||
|
|
||||||
|
|||||||
@ -1,8 +1,4 @@
|
|||||||
from .chart import Chart
|
from .chart import Chart
|
||||||
from .js import LWC
|
from .js import LWC
|
||||||
|
|
||||||
try:
|
|
||||||
import wx.html2
|
|
||||||
from .widgets import WxChart
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|||||||
@ -1,14 +1,22 @@
|
|||||||
from lightweight_charts.js import LWC
|
|
||||||
try:
|
try:
|
||||||
import wx.html2
|
import wx.html2
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
|
try:
|
||||||
|
from PyQt5.QtWebEngineWidgets import QWebEngineView
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
from lightweight_charts.js import LWC
|
||||||
|
|
||||||
|
|
||||||
class WxChart(LWC):
|
class WxChart(LWC):
|
||||||
def __init__(self, parent, volume_enabled=True):
|
def __init__(self, parent, volume_enabled=True):
|
||||||
super().__init__(volume_enabled)
|
super().__init__(volume_enabled)
|
||||||
self.webview = wx.html2.WebView.New(parent)
|
try:
|
||||||
|
self.webview = wx.html2.WebView.New(parent)
|
||||||
|
except NameError:
|
||||||
|
raise ModuleNotFoundError('wx.html2 was not found, and must be installed to use WxChart.')
|
||||||
|
|
||||||
self.webview.Bind(wx.html2.EVT_WEBVIEW_LOADED, self._on_js_load)
|
self.webview.Bind(wx.html2.EVT_WEBVIEW_LOADED, self._on_js_load)
|
||||||
self.webview.SetPage(self._html, '')
|
self.webview.SetPage(self._html, '')
|
||||||
@ -17,7 +25,7 @@ class WxChart(LWC):
|
|||||||
|
|
||||||
def run_script(self, script): self.webview.RunScript(script)
|
def run_script(self, script): self.webview.RunScript(script)
|
||||||
|
|
||||||
def _on_js_load(self, e: wx.html2.WebViewEvent):
|
def _on_js_load(self, e):
|
||||||
if not self.second_load:
|
if not self.second_load:
|
||||||
self.second_load = True
|
self.second_load = True
|
||||||
return
|
return
|
||||||
@ -25,4 +33,26 @@ class WxChart(LWC):
|
|||||||
for func, args, kwargs in self.js_queue:
|
for func, args, kwargs in self.js_queue:
|
||||||
getattr(super(), func)(*args, **kwargs)
|
getattr(super(), func)(*args, **kwargs)
|
||||||
|
|
||||||
def get_webview(self): return self.webview
|
def get_webview(self): return self.webview
|
||||||
|
|
||||||
|
|
||||||
|
class QtChart(LWC):
|
||||||
|
def __init__(self, widget=None, volume_enabled=True):
|
||||||
|
super().__init__(volume_enabled)
|
||||||
|
try:
|
||||||
|
self.webview = QWebEngineView(widget)
|
||||||
|
except NameError:
|
||||||
|
raise ModuleNotFoundError('QWebEngineView was not found, and must be installed to use QtChart.')
|
||||||
|
|
||||||
|
self.webview.loadFinished.connect(self._on_js_load)
|
||||||
|
self.webview.page().setHtml(self._html)
|
||||||
|
|
||||||
|
def run_script(self, script): self.webview.page().runJavaScript(script)
|
||||||
|
|
||||||
|
def _on_js_load(self):
|
||||||
|
self.loaded = True
|
||||||
|
for func, args, kwargs in self.js_queue:
|
||||||
|
getattr(super(), func)(*args, **kwargs)
|
||||||
|
|
||||||
|
def get_webview(self): return self.webview
|
||||||
|
|
||||||
|
|||||||
3
setup.py
3
setup.py
@ -5,7 +5,7 @@ with open('README.md', 'r', encoding='utf-8') as f:
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='lightweight_charts',
|
name='lightweight_charts',
|
||||||
version='1.0.1',
|
version='1.0.3',
|
||||||
packages=find_packages(),
|
packages=find_packages(),
|
||||||
python_requires='>=3.9',
|
python_requires='>=3.9',
|
||||||
install_requires=[
|
install_requires=[
|
||||||
@ -16,5 +16,6 @@ setup(
|
|||||||
license='MIT',
|
license='MIT',
|
||||||
description="Python framework for TradingView's Lightweight Charts JavaScript library.",
|
description="Python framework for TradingView's Lightweight Charts JavaScript library.",
|
||||||
long_description=long_description,
|
long_description=long_description,
|
||||||
|
long_description_content_type='text/markdown',
|
||||||
url='https://github.com/louisnw01/lightweight-charts-python',
|
url='https://github.com/louisnw01/lightweight-charts-python',
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user