implement context manager
This commit is contained in:
@ -11,7 +11,7 @@ from .toolbox import ToolBox
|
|||||||
from .drawings import Box, HorizontalLine, TrendLine, TwoPointDrawing, VerticalSpan
|
from .drawings import Box, HorizontalLine, TrendLine, TwoPointDrawing, VerticalSpan
|
||||||
from .topbar import TopBar
|
from .topbar import TopBar
|
||||||
from .util import (
|
from .util import (
|
||||||
Pane, Events, IDGen, as_enum, jbool, js_json, TIME, NUM, FLOAT,
|
BulkRunScript, Pane, Events, IDGen, as_enum, jbool, js_json, TIME, NUM, FLOAT,
|
||||||
LINE_STYLE, MARKER_POSITION, MARKER_SHAPE, CROSSHAIR_MODE,
|
LINE_STYLE, MARKER_POSITION, MARKER_SHAPE, CROSSHAIR_MODE,
|
||||||
PRICE_SCALE_MODE, marker_position, marker_shape, js_data,
|
PRICE_SCALE_MODE, marker_position, marker_shape, js_data,
|
||||||
)
|
)
|
||||||
@ -34,6 +34,7 @@ class Window:
|
|||||||
self.script_func = script_func
|
self.script_func = script_func
|
||||||
self.scripts = []
|
self.scripts = []
|
||||||
self.final_scripts = []
|
self.final_scripts = []
|
||||||
|
self.bulk_run = BulkRunScript(script_func)
|
||||||
|
|
||||||
if run_script:
|
if run_script:
|
||||||
self.run_script = run_script
|
self.run_script = run_script
|
||||||
@ -63,7 +64,10 @@ class Window:
|
|||||||
if self.script_func is None:
|
if self.script_func is None:
|
||||||
raise AttributeError("script_func has not been set")
|
raise AttributeError("script_func has not been set")
|
||||||
if self.loaded:
|
if self.loaded:
|
||||||
self.script_func(script)
|
if self.bulk_run.enabled:
|
||||||
|
self.bulk_run.add_script(script)
|
||||||
|
else:
|
||||||
|
self.script_func(script)
|
||||||
elif run_last:
|
elif run_last:
|
||||||
self.final_scripts.append(script)
|
self.final_scripts.append(script)
|
||||||
else:
|
else:
|
||||||
@ -666,8 +670,6 @@ class AbstractChart(Candlestick, Pane):
|
|||||||
Creates and returns a Line object.
|
Creates and returns a Line object.
|
||||||
"""
|
"""
|
||||||
self._lines.append(Line(self, name, color, style, width, price_line, price_label))
|
self._lines.append(Line(self, name, color, style, width, price_line, price_label))
|
||||||
# TODO check legend still works without this
|
|
||||||
# self._lines[-1]._push_to_legend()
|
|
||||||
return self._lines[-1]
|
return self._lines[-1]
|
||||||
|
|
||||||
def create_histogram(
|
def create_histogram(
|
||||||
|
|||||||
@ -12,6 +12,7 @@ class Pane:
|
|||||||
from lightweight_charts import Window
|
from lightweight_charts import Window
|
||||||
self.win: Window = window
|
self.win: Window = window
|
||||||
self.run_script = window.run_script
|
self.run_script = window.run_script
|
||||||
|
self.bulk_run = window.bulk_run
|
||||||
if hasattr(self, 'id'):
|
if hasattr(self, 'id'):
|
||||||
return
|
return
|
||||||
self.id = Window._id_gen.generate()
|
self.id = Window._id_gen.generate()
|
||||||
@ -171,3 +172,20 @@ class Events:
|
|||||||
'''),
|
'''),
|
||||||
wrapper=lambda func, c, *args: func(c, *[float(a) for a in args])
|
wrapper=lambda func, c, *args: func(c, *[float(a) for a in args])
|
||||||
)
|
)
|
||||||
|
|
||||||
|
class BulkRunScript:
|
||||||
|
def __init__(self, script_func):
|
||||||
|
self.enabled = False
|
||||||
|
self.scripts = []
|
||||||
|
self.script_func = script_func
|
||||||
|
|
||||||
|
def __enter__(self):
|
||||||
|
self.enabled = True
|
||||||
|
|
||||||
|
def __exit__(self, *args):
|
||||||
|
self.enabled = False
|
||||||
|
self.script_func('\n'.join(self.scripts))
|
||||||
|
self.scripts = []
|
||||||
|
|
||||||
|
def add_script(self, script):
|
||||||
|
self.scripts.append(script)
|
||||||
|
|||||||
0
src/general/series-handler.ts
Normal file
0
src/general/series-handler.ts
Normal file
Reference in New Issue
Block a user