From c106132abe6def6ad921245f8c65b5bce4c50214 Mon Sep 17 00:00:00 2001 From: Mateus Etto Date: Thu, 18 Apr 2024 14:31:21 +0900 Subject: [PATCH] Add option to invert bar movement --- src/database.py | 2 +- src/deck_manager.py | 4 +++- src/defaults.py | 1 + src/progress_bar.py | 1 + src/settings.py | 4 ++++ 5 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/database.py b/src/database.py index d96a273..911a836 100644 --- a/src/database.py +++ b/src/database.py @@ -20,7 +20,7 @@ class GlobalConf: 'globalSettingsShortcut', 'deckSettingsShortcut', 'pauseShortcut', 'recoverShortcut', 'behavUndo', 'behavBury', 'behavSuspend', 'stopOnLostFocus', 'shareDrain', 'barThresholdWarn', 'barFgColorWarn', 'barThresholdDanger', 'barFgColorDanger', - 'startEmpty', + 'startEmpty', 'invert', } def __init__(self, mw: AnkiQt): diff --git a/src/deck_manager.py b/src/deck_manager.py index 706933f..ad9fab4 100644 --- a/src/deck_manager.py +++ b/src/deck_manager.py @@ -254,7 +254,9 @@ def _update_progress_bar_style(self) -> None: 'borderRadius': conf['barBorderRadius'], 'text': conf['barText'], 'textColor': conf['barTextColor'], - 'customStyle': conf['barStyle']} + 'customStyle': conf['barStyle'], + 'invert': conf['invert'], + } if conf['enableBgColor']: progress_bar_style['bgColor'] = conf['barBgColor'] self._progress_bar.set_style(progress_bar_style) diff --git a/src/defaults.py b/src/defaults.py index b28a3b5..e25d32d 100644 --- a/src/defaults.py +++ b/src/defaults.py @@ -47,6 +47,7 @@ 'stopOnAnswer': False, 'stopOnLostFocus': True, 'startEmpty': False, + 'invert': False, 'enable': True, 'enableBgColor': False, 'globalSettingsShortcut': 'Ctrl+Shift+L', diff --git a/src/progress_bar.py b/src/progress_bar.py index 078147b..f17462b 100644 --- a/src/progress_bar.py +++ b/src/progress_bar.py @@ -102,6 +102,7 @@ def set_style(self, options: dict[str, Any]) -> None: self._qprogressbar.setFormat(text_format['format']) self._current_bar_color = '' self._update_bar_color() + self._qprogressbar.setInvertedAppearance(options['invert']) def dock_at(self, position_index: Literal[0, 1]) -> None: """Docks the bar at the specified position in the Anki window. diff --git a/src/settings.py b/src/settings.py index 357d164..2dc584d 100644 --- a/src/settings.py +++ b/src/settings.py @@ -223,6 +223,7 @@ def save() -> None: 'behavUndo': basic_tab.behavUndo.get_value(), 'behavBury': basic_tab.behavBury.get_value(), 'behavSuspend': basic_tab.behavSuspend.get_value(), + 'invert': bar_style_tab.invert.get_value(), 'barPosition': bar_style_tab.positionList.get_value(), 'barHeight': bar_style_tab.heightInput.get_value(), 'barBorderRadius': bar_style_tab.borderRadiusInput.get_value(), @@ -343,6 +344,8 @@ def _global_bar_style_tab(aqt: Any, conf: dict[str, Any]) -> Any: def generate_form() -> Any: tab = Form(aqt) + tab.check_box('invert', 'Invert bar movement', + 'Reduce life from left to right instead of right to left.') tab.combo_box('positionList', 'Position', POSITION_OPTIONS, 'Place to show the life bar.') tab.spin_box('heightInput', 'Height', [1, 40], @@ -373,6 +376,7 @@ def generate_form() -> Any: return tab.widget def load_data(widget: Any, conf: dict[str, Any]) -> None: + widget.invert.set_value(conf['invert']) widget.positionList.set_value(conf['barPosition']) widget.heightInput.set_value(conf['barHeight']) widget.borderRadiusInput.set_value(conf['barBorderRadius'])