New Feature: ChartAsync

- Added the ChartAsync class, allowing for more sophisticated Charts and SubCharts.
- Symbol searching, timeframe selectors, and more is now possible with this varation of Chart.

`QtChart` and `WxChart` have access to all the methods that `ChartAsync` has, however they utilize their own respective event loops rather than asyncio.

New Feature: `StreamlitChart`
- Chart window that can display static data within a Streamlit application.

Removed the `subscribe_click` method.
This commit is contained in:
louisnw
2023-05-29 21:31:13 +01:00
parent 39e40334d5
commit a58f1e306c
24 changed files with 19390 additions and 3143 deletions

View File

@ -4,15 +4,25 @@ import multiprocessing as mp
from lightweight_charts.js import LWC
class CallbackAPI:
def __init__(self, emit): self.emit = emit
def callback(self, message: str):
messages = message.split('__')
name, chart_id = messages[:2]
args = messages[2:]
self.emit.put((name, chart_id, *args))
class PyWV:
def __init__(self, q, exit, loaded, html, js_api, width, height, x, y, on_top, debug):
def __init__(self, q, exit, loaded, html, width, height, x, y, on_top, debug, emit=None):
self.queue = q
self.exit = exit
self.loaded = loaded
self.debug = debug
self.js_api = js_api
self.webview = webview.create_window('', html=html, on_top=on_top, js_api=js_api,
width=width, height=height, x=x, y=y, background_color='#000000')
js_api = CallbackAPI(emit) if emit else None
self.webview = webview.create_window('', html=html, on_top=on_top, js_api=js_api, width=width, height=height,
x=x, y=y, background_color='#000000')
self.webview.events.loaded += self.on_js_load
self.loop()
@ -22,9 +32,6 @@ class PyWV:
if arg in ('start', 'show', 'hide', 'exit'):
webview.start(debug=self.debug) if arg == 'start' else getattr(self.webview, arg)()
self.exit.set() if arg in ('start', 'exit') else None
elif arg == 'subscribe':
func, c_id = (self.queue.get() for _ in range(2))
self.js_api.click_funcs[str(c_id)] = func
else:
try:
self.webview.evaluate_js(arg)
@ -40,12 +47,11 @@ class Chart(LWC):
on_top: bool = False, debug: bool = False,
inner_width: float = 1.0, inner_height: float = 1.0, dynamic_loading: bool = False):
super().__init__(volume_enabled, inner_width, inner_height, dynamic_loading)
self._js_api_code = 'pywebview.api.onClick'
self._q = mp.Queue()
self._script_func = self._q.put
self._exit = mp.Event()
self._loaded = mp.Event()
self._process = mp.Process(target=PyWV, args=(self._q, self._exit, self._loaded, self._html, self._js_api,
self._process = mp.Process(target=PyWV, args=(self._q, self._exit, self._loaded, self._html,
width, height, x, y, on_top, debug,), daemon=True)
self._process.start()
self._create_chart()
@ -83,9 +89,3 @@ class Chart(LWC):
self._process.terminate()
del self
def subscribe_click(self, function: object):
self._q.put('subscribe')
self._q.put(function)
self._q.put(self.id)
super().subscribe_click(function)