Add set() method to menu widget
- https://github.com/louisnw01/lightweight-charts-python/issues/300
This commit is contained in:
@ -49,10 +49,20 @@ class SwitcherWidget(Widget):
|
|||||||
class MenuWidget(Widget):
|
class MenuWidget(Widget):
|
||||||
def __init__(self, topbar, options, default, separator, align, func):
|
def __init__(self, topbar, options, default, separator, align, func):
|
||||||
super().__init__(topbar, value=default, func=func)
|
super().__init__(topbar, value=default, func=func)
|
||||||
|
self.options = list(options)
|
||||||
self.run_script(f'''
|
self.run_script(f'''
|
||||||
{self.id} = {topbar.id}.makeMenu({list(options)}, "{default}", {jbool(separator)}, "{self.id}", "{align}")
|
{self.id} = {topbar.id}.makeMenu({list(options)}, "{default}", {jbool(separator)}, "{self.id}", "{align}")
|
||||||
''')
|
''')
|
||||||
|
|
||||||
|
def set(self, option):
|
||||||
|
if option not in self.options:
|
||||||
|
raise ValueError(f"Option {option} not in menu options ({self.options})")
|
||||||
|
self.value = option
|
||||||
|
self.run_script(f'''
|
||||||
|
{self.id}.updateMenu("{option}")
|
||||||
|
''')
|
||||||
|
self.win.handlers[self.id](option)
|
||||||
|
|
||||||
|
|
||||||
class ButtonWidget(Widget):
|
class ButtonWidget(Widget):
|
||||||
def __init__(self, topbar, button, separator, align, func):
|
def __init__(self, topbar, button, separator, align, func):
|
||||||
|
|||||||
Reference in New Issue
Block a user