Enhancements:

- Added the `screen` parameter to `Chart`, allowing for monitor selection. This should be an index from 0 (0 = primary monitor, 1=  second monitor, etc.)
- `vertical_span` method, allowing for vertical lines/spans to be drawn across the chart.
- `set_visible_range` method, which will set the visible range of the chart based on two given dates.
- `resize` method, which resizes the chart to the given size.
- `sync` will now sync both charts, regardless of which one is scrolled/zoomed.
This commit is contained in:
louisnw
2023-08-31 21:25:00 +01:00
parent 769fd8ac0a
commit a7c1dc8a30
11 changed files with 191 additions and 69 deletions

View File

@ -17,7 +17,7 @@ class CallbackAPI:
class PyWV:
def __init__(self, q, start_ev, exit_ev, loaded, emit_queue, return_queue, html, debug,
width, height, x, y, on_top, maximize):
width, height, x, y, screen, on_top, maximize):
self.queue = q
self.return_queue = return_queue
self.exit = exit_ev
@ -26,18 +26,20 @@ class PyWV:
self.html = html
self.windows = []
self.create_window(width, height, x, y, on_top, maximize)
self.create_window(width, height, x, y, screen, on_top, maximize)
start_ev.wait()
webview.start(debug=debug)
self.exit.set()
def create_window(self, width, height, x, y, on_top, maximize):
def create_window(self, width, height, x, y, screen=0, on_top=False, maximize=False):
screen = webview.screens[screen]
if maximize:
width, height = webview.screens[0].width, webview.screens[0].height
width, height = screen.width, screen.height
self.windows.append(webview.create_window(
'', html=self.html, on_top=on_top, js_api=self.callback_api,
width=width, height=height, x=x, y=y, background_color='#000000'))
'', html=self.html, js_api=self.callback_api,
width=width, height=height, x=x, y=y, screen=screen,
on_top=on_top, background_color='#000000'))
self.windows[-1].events.loaded += lambda: self.loop(self.loaded[len(self.windows)-1])
def loop(self, loaded):
@ -68,29 +70,29 @@ class Chart(abstract.AbstractChart):
_q, _emit_q, _return_q = (mp.Queue() for _ in range(3))
_loaded_list = [mp.Event() for _ in range(MAX_WINDOWS)]
def __init__(self, width: int = 800, height: int = 600, x: int = None, y: int = None,
def __init__(self, width: int = 800, height: int = 600, x: int = None, y: int = None, screen: int = 0,
on_top: bool = False, maximize: bool = False, debug: bool = False, toolbox: bool = False,
inner_width: float = 1.0, inner_height: float = 1.0, scale_candles_only: bool = False):
self._i = Chart._window_num
self._loaded = Chart._loaded_list[self._i]
window = abstract.Window(lambda s: self._q.put((self._i, s)), 'pywebview.api.callback')
abstract.Window._return_q = Chart._return_q
Chart._window_num += 1
self.is_alive = True
window = abstract.Window(lambda s: self._q.put((self._i, s)), 'pywebview.api.callback')
if self._i == 0:
super().__init__(window, inner_width, inner_height, scale_candles_only, toolbox)
Chart._main_window_handlers = self.win.handlers
self._process = mp.Process(target=PyWV, args=(
self._q, self._start, self._exit, Chart._loaded_list,
self._emit_q, self._return_q, abstract.TEMPLATE, debug,
width, height, x, y, on_top, maximize,
width, height, x, y, screen, on_top, maximize,
), daemon=True)
self._process.start()
else:
window.handlers = Chart._main_window_handlers
super().__init__(window, inner_width, inner_height, scale_candles_only, toolbox)
self._q.put(('create_window', (abstract.TEMPLATE, on_top, width, height, x, y)))
self._q.put(('create_window', (width, height, x, y, screen, on_top, maximize)))
def show(self, block: bool = False):
"""