- 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).
This commit is contained in:
@ -15,12 +15,16 @@ class Line:
|
||||
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 @@ class Chart:
|
||||
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 @@ class Chart:
|
||||
: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):
|
||||
"""
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import datetime
|
||||
|
||||
import webview
|
||||
from multiprocessing import Queue
|
||||
|
||||
@ -62,7 +61,9 @@ class Webview(LWC):
|
||||
|
||||
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
|
||||
|
||||
|
||||
@ -6,9 +6,9 @@ except ImportError:
|
||||
|
||||
|
||||
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, '')
|
||||
|
||||
15
setup.py
15
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',
|
||||
)
|
||||
long_description=long_description,
|
||||
url='https://github.com/louisnw01/lightweight-charts-python',
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user