Enhancements:

- added the `align` parameter to all topbar widgets, allowing for individual widgets to be placed either on the left or right hand side of the topbar.
- Disabled QtChart’s context menu by default.

Bug Fixes:
- The `screenshot` method now works for subcharts.
- Tables will still render if a `NoneType` is passed to them as a value.
- Qt and Wx charts no longer throw an error when using the toolbox.
This commit is contained in:
louisnw
2023-09-14 10:51:10 +01:00
parent 8f65a7fc96
commit b1f007f6d0
12 changed files with 104 additions and 71 deletions

View File

@ -1,9 +1,12 @@
import asyncio
from typing import Dict
from typing import Dict, Literal
from .util import jbool, Pane
ALIGN = Literal['left', 'right']
class Widget(Pane):
def __init__(self, topbar, value, func=None):
super().__init__(topbar.win)
@ -21,9 +24,9 @@ class Widget(Pane):
class TextWidget(Widget):
def __init__(self, topbar, initial_text):
def __init__(self, topbar, initial_text, align):
super().__init__(topbar, value=initial_text)
self.run_script(f'{self.id} = {topbar.id}.makeTextBoxWidget("{initial_text}")')
self.run_script(f'{self.id} = {topbar.id}.makeTextBoxWidget("{initial_text}", "{align}")')
def set(self, string):
self.value = string
@ -31,22 +34,23 @@ class TextWidget(Widget):
class SwitcherWidget(Widget):
def __init__(self, topbar, options, default, func):
def __init__(self, topbar, options, default, align, func):
super().__init__(topbar, value=default, func=func)
self.run_script(f'{self.id} = {topbar.id}.makeSwitcher({list(options)}, "{default}", "{self.id}")')
self.run_script(f'{self.id} = {topbar.id}.makeSwitcher({list(options)}, "{default}", "{self.id}", "{align}")')
class MenuWidget(Widget):
def __init__(self, topbar, options, default, separator, func):
def __init__(self, topbar, options, default, separator, align, func):
super().__init__(topbar, value=default, func=func)
self.run_script(
f'{self.id} = {topbar.id}.makeMenu({list(options)}, "{default}", {jbool(separator)}, "{self.id}")')
self.run_script(f'''
{self.id} = {topbar.id}.makeMenu({list(options)}, "{default}", {jbool(separator)}, "{self.id}", "{align}")
''')
class ButtonWidget(Widget):
def __init__(self, topbar, button, separator, func):
def __init__(self, topbar, button, separator, align, func):
super().__init__(topbar, value=button, func=func)
self.run_script(f'{self.id} = {topbar.id}.makeButton("{button}", "{self.id}", {jbool(separator)})')
self.run_script(f'{self.id} = {topbar.id}.makeButton("{button}", "{self.id}", {jbool(separator)}, "{align}")')
def set(self, string):
self.value = string
@ -82,20 +86,25 @@ class TopBar(Pane):
return widget
raise KeyError(f'Topbar widget "{item}" not found.')
def get(self, widget_name): return self._widgets.get(widget_name)
def get(self, widget_name):
return self._widgets.get(widget_name)
def switcher(self, name, options: tuple, default: str = None, func: callable = None):
def switcher(self, name, options: tuple, default: str = None,
align: ALIGN = 'left', func: callable = None):
self._create()
self._widgets[name] = SwitcherWidget(self, options, default if default else options[0], func)
self._widgets[name] = SwitcherWidget(self, options, default if default else options[0], align, func)
def menu(self, name, options: tuple, default: str = None, separator: bool = True, func: callable = None):
def menu(self, name, options: tuple, default: str = None, separator: bool = True,
align: ALIGN = 'left', func: callable = None):
self._create()
self._widgets[name] = MenuWidget(self, options, default if default else options[0], separator, func)
self._widgets[name] = MenuWidget(self, options, default if default else options[0], separator, align, func)
def textbox(self, name: str, initial_text: str = ''):
def textbox(self, name: str, initial_text: str = '',
align: ALIGN = 'left'):
self._create()
self._widgets[name] = TextWidget(self, initial_text)
self._widgets[name] = TextWidget(self, initial_text, align)
def button(self, name, button_text: str, separator: bool = True, func: callable = None):
def button(self, name, button_text: str, separator: bool = True,
align: ALIGN = 'left', func: callable = None):
self._create()
self._widgets[name] = ButtonWidget(self, button_text, separator, func)
self._widgets[name] = ButtonWidget(self, button_text, separator, align, func)