- Fixed an issue which caused JavaScript variables of the same name to be declared twice.
- Refactoring to allow the widget classes to use the subscribe_click method.
This commit is contained in:
@ -1,4 +1,3 @@
|
||||
import datetime
|
||||
import webview
|
||||
from multiprocessing import Queue
|
||||
|
||||
@ -7,29 +6,15 @@ from lightweight_charts.js import LWC
|
||||
_q = Queue()
|
||||
_result_q = Queue()
|
||||
|
||||
DEBUG = True
|
||||
|
||||
|
||||
class API:
|
||||
def __init__(self):
|
||||
self.click_func = None
|
||||
|
||||
def onClick(self, data):
|
||||
if isinstance(data['time'], int):
|
||||
data['time'] = datetime.datetime.fromtimestamp(data['time'])
|
||||
else:
|
||||
data['time'] = datetime.datetime(data['time']['year'], data['time']['month'], data['time']['day'])
|
||||
self.click_func(data) if self.click_func else None
|
||||
|
||||
|
||||
class Webview(LWC):
|
||||
def __init__(self, chart):
|
||||
super().__init__(chart.volume_enabled)
|
||||
self.chart = chart
|
||||
self.started = False
|
||||
self._click_func_code('pywebview.api.onClick(data)')
|
||||
|
||||
self.js_api = API()
|
||||
self.webview = webview.create_window('', html=self._html, on_top=chart.on_top, js_api=self.js_api,
|
||||
self.webview = webview.create_window('', html=self._html, on_top=chart.on_top, js_api=self._js_api,
|
||||
width=chart.width, height=chart.height, x=chart.x, y=chart.y)
|
||||
self.webview.events.loaded += self._on_js_load
|
||||
|
||||
@ -49,13 +34,6 @@ class Webview(LWC):
|
||||
else:
|
||||
webview.start(debug=self.chart.debug)
|
||||
|
||||
def subscribe_click(self, function):
|
||||
if self._stored('subscribe_click', function):
|
||||
return None
|
||||
|
||||
self.js_api.click_func = function
|
||||
self.run_script('isSubscribed = true')
|
||||
|
||||
def create_line(self, color: str = 'rgba(214, 237, 255, 0.6)', width: int = 2):
|
||||
return super().create_line(color, width).id
|
||||
|
||||
|
||||
Reference in New Issue
Block a user