Skip to content

Commit

Permalink
- Added missing docstrings (line.set(), chart.hide(), chart.exit()).
Browse files Browse the repository at this point in the history
- 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).
  • Loading branch information
louisnw01 committed May 12, 2023
1 parent 5b0a8cd commit d8424d6
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 12 deletions.
25 changes: 22 additions & 3 deletions lightweight_charts/chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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

Expand All @@ -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):
"""
Expand Down
7 changes: 5 additions & 2 deletions lightweight_charts/pywebview.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import datetime

import webview
from multiprocessing import Queue

Expand Down Expand Up @@ -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):
Expand All @@ -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

4 changes: 2 additions & 2 deletions lightweight_charts/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, '')
Expand Down
15 changes: 10 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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',
)

0 comments on commit d8424d6

Please sign in to comment.