From 4f172fe40178342422a71f454454dc583f37882f Mon Sep 17 00:00:00 2001 From: Mateus Eto Date: Tue, 3 Dec 2024 15:31:47 +0900 Subject: [PATCH] Use default bar style if custom style isn't found We save only the index of the style (0 for default) If the number of custom styles change, it would cause a crash. --- src/progress_bar.py | 10 ++++------ src/settings.py | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/progress_bar.py b/src/progress_bar.py index 59c7fe8..14aa850 100644 --- a/src/progress_bar.py +++ b/src/progress_bar.py @@ -185,16 +185,14 @@ def _update_bar_color(self) -> None: return self._current_bar_color = bar_color - if options['customStyle']: - available_styles = ['default', *self._qt.QStyleFactory.keys()] - custom_style = available_styles[options['customStyle']] + available_styles = self._qt.QStyleFactory.keys() - qstyle = self._qt.QStyleFactory.create(custom_style) + if options['customStyle'] and options['customStyle'] <= len(available_styles): + qstyle = self._qt.QStyleFactory.create(available_styles[options['customStyle'] - 1]) self._qprogressbar.setStyle(qstyle) palette = self._qt.QPalette() - fg_color = self._qt.QColor(bar_color) - palette.setColor(self._qt.QPalette.ColorRole.Highlight, fg_color) + palette.setColor(self._qt.QPalette.ColorRole.Highlight, self._qt.QColor(bar_color)) if 'bgColor' in options: bg_color = self._qt.QColor(options['bgColor']) diff --git a/src/settings.py b/src/settings.py index b5e8de4..cddc9f5 100644 --- a/src/settings.py +++ b/src/settings.py @@ -381,7 +381,7 @@ def generate_form() -> Any: tab.spin_box('borderRadiusInput', 'Border radius', [0, 20], 'Add a rounded border to the life bar.') tab.combo_box('styleList', 'Style', ['Default', *aqt.QStyleFactory.keys()], '''Style of \ -the life bar.''') +the life bar. Custom styles coloring may only work after a restart.''') tab.color_select('fgColor', 'Bar color (default)', "Color of the life bar's foreground.") tab.spin_box('thresholdWarn', 'Warn threshold (%)', [0, 99],