From d8424d6da388a6bcde6514056c783351f8a0160e Mon Sep 17 00:00:00 2001 From: louisnw Date: Fri, 12 May 2023 12:56:53 +0100 Subject: [PATCH] - Added missing docstrings (line.set(), chart.hide(), chart.exit()). - Updated chart.exit() to destroy objects and terminate the webview process. - Fixed WxChart not expanding correctly and removed its width and height parameters. - Fixed KeyboardInterrupt error message when using show(block=True). --- lightweight_charts/chart.py | 25 ++++++++++++++++++++++--- lightweight_charts/pywebview.py | 7 +++++-- lightweight_charts/widgets.py | 4 ++-- setup.py | 15 ++++++++++----- 4 files changed, 39 insertions(+), 12 deletions(-) diff --git a/lightweight_charts/chart.py b/lightweight_charts/chart.py index 439a859..3ec2e9b 100644 --- a/lightweight_charts/chart.py +++ b/lightweight_charts/chart.py @@ -15,12 +15,16 @@ def __init__(self, chart, line_id): self.id = line_id def set(self, data: pd.DataFrame): + """ + Sets the line data.\n + :param data: columns: date/time, price + """ self._chart._go('_set_line_data', self.id, data) def update(self, series: pd.Series): """ Updates the line data.\n - :param series: columns: date/time, price + :param series: labels: date/time, price """ self._chart._go('_update_line_data', self.id, series) @@ -41,7 +45,8 @@ def __init__(self, volume_enabled: bool = True, width: int = 800, height: int = self._exit = mp.Event() try: - mp.Process(target=_loop, args=(self,), daemon=True).start() + self._process = mp.Process(target=_loop, args=(self,), daemon=True) + self._process.start() except: pass @@ -57,13 +62,27 @@ def show(self, block: bool = False): :param block: blocks execution until the chart is closed. """ self._go('show') - self._exit.wait() if block else None + if block: + try: + self._exit.wait() + except KeyboardInterrupt: + return + self._exit.clear() def hide(self): + """ + Hides the chart window.\n + """ self._go('hide') def exit(self): + """ + Exits and destroys the chart window.\n + """ self._go('exit') + self._exit.wait() + self._process.terminate() + del self def run_script(self, script: str): """ diff --git a/lightweight_charts/pywebview.py b/lightweight_charts/pywebview.py index 62295f2..05263fd 100644 --- a/lightweight_charts/pywebview.py +++ b/lightweight_charts/pywebview.py @@ -1,5 +1,4 @@ import datetime - import webview from multiprocessing import Queue @@ -62,7 +61,9 @@ def create_line(self, color: str = 'rgba(214, 237, 255, 0.6)', width: int = 2): def hide(self): self.webview.hide() - def exit(self): self.webview.destroy() + def exit(self): + self.webview.destroy() + del self def _loop(chart, controller=None): @@ -75,5 +76,7 @@ def _loop(chart, controller=None): return if func == 'show': chart._exit.set() + elif func == 'exit': + chart._exit.set() chart._result_q.put(result) if result is not None else None diff --git a/lightweight_charts/widgets.py b/lightweight_charts/widgets.py index cd27e0a..0dc3325 100644 --- a/lightweight_charts/widgets.py +++ b/lightweight_charts/widgets.py @@ -6,9 +6,9 @@ class WxChart(LWC): - def __init__(self, parent, width, height, volume_enabled=True): + def __init__(self, parent, volume_enabled=True): super().__init__(volume_enabled) - self.webview = wx.html2.WebView.New(parent, size=(width, height)) + self.webview = wx.html2.WebView.New(parent) self.webview.Bind(wx.html2.EVT_WEBVIEW_LOADED, self._on_js_load) self.webview.SetPage(self._html, '') diff --git a/setup.py b/setup.py index 16c49c3..f8373bb 100644 --- a/setup.py +++ b/setup.py @@ -1,15 +1,20 @@ from setuptools import setup, find_packages +with open('README.md', 'r', encoding='utf-8') as f: + long_description = f.read() + setup( name='lightweight_charts', - version='1.0.0', + version='1.0.1', packages=find_packages(), + python_requires='>=3.9', install_requires=[ 'pandas', 'pywebview', ], - # Additional package metadata - author='louisnw01', + author='louisnw', + license='MIT', description="Python framework for TradingView's Lightweight Charts JavaScript library.", - url='https://github.com/SORT-THIS-OUT', -) \ No newline at end of file + long_description=long_description, + url='https://github.com/louisnw01/lightweight-charts-python', +)