From f191de9bef79225d62e88f7ce42ced979830080e Mon Sep 17 00:00:00 2001 From: Laurent Monin Date: Mon, 27 May 2024 15:05:32 +0200 Subject: [PATCH] Options > Interface > Colors: Separate colors in different groups - properly sort colors in each group (locale-aware) - use group boxes - add ColorDescription class with 2 fields: title & group --- picard/ui/colors.py | 54 ++++++++++++++++----------- picard/ui/options/interface_colors.py | 25 +++++++++++-- 2 files changed, 54 insertions(+), 25 deletions(-) diff --git a/picard/ui/colors.py b/picard/ui/colors.py index 946e3f868..dbe215039 100644 --- a/picard/ui/colors.py +++ b/picard/ui/colors.py @@ -37,28 +37,34 @@ class UnknownColorException(Exception): pass +class ColorDescription: + def __init__(self, title, group): + self.title = title + self.group = group + + _COLOR_DESCRIPTIONS = { - 'entity_error': N_("Errored entity"), - 'entity_pending': N_("Pending entity"), - 'entity_saved': N_("Saved entity"), - 'first_cover_hl': N_("First cover art"), - 'log_debug': N_('Log view text (debug)'), - 'log_error': N_('Log view text (error)'), - 'log_info': N_('Log view text (info)'), - 'log_warning': N_('Log view text (warning)'), - 'profile_hl_bg': N_("Profile highlight background"), - 'profile_hl_fg': N_("Profile highlight foreground"), - 'row_highlight': N_("Row Highlight"), - 'tagstatus_added': N_("Tag added"), - 'tagstatus_changed': N_("Tag changed"), - 'tagstatus_removed': N_("Tag removed"), - 'syntax_hl_error': N_("Error syntax highlight"), - 'syntax_hl_escape': N_("Escape syntax highlight"), - 'syntax_hl_func': N_("Function syntax highlight"), - 'syntax_hl_noop': N_("Noop syntax highlight"), - 'syntax_hl_special': N_("Special syntax highlight"), - 'syntax_hl_unicode': N_("Unicode syntax highlight"), - 'syntax_hl_var': N_("Variable syntax highlight"), + 'entity_error': ColorDescription(title=N_("Errored entity"), group=N_("Entities")), + 'entity_pending': ColorDescription(title=N_("Pending entity"), group=N_("Entities")), + 'entity_saved': ColorDescription(title=N_("Saved entity"), group=N_("Entities")), + 'first_cover_hl': ColorDescription(title=N_("First cover art"), group=N_("Others")), + 'log_debug': ColorDescription(title=N_('Log view text (debug)'), group=N_("Logging")), + 'log_error': ColorDescription(title=N_('Log view text (error)'), group=N_("Logging")), + 'log_info': ColorDescription(title=N_('Log view text (info)'), group=N_("Logging")), + 'log_warning': ColorDescription(title=N_('Log view text (warning)'), group=N_("Logging")), + 'profile_hl_bg': ColorDescription(title=N_("Profile highlight background"), group=N_("Profiles")), + 'profile_hl_fg': ColorDescription(title=N_("Profile highlight foreground"), group=N_("Profiles")), + 'row_highlight': ColorDescription(title=N_("Row Highlight"), group=N_("Others")), + 'tagstatus_added': ColorDescription(title=N_("Tag added"), group=N_("Tags")), + 'tagstatus_changed': ColorDescription(title=N_("Tag changed"), group=N_("Tags")), + 'tagstatus_removed': ColorDescription(title=N_("Tag removed"), group=N_("Tags")), + 'syntax_hl_error': ColorDescription(title=N_("Error syntax highlight"), group=N_("Syntax Highlighting")), + 'syntax_hl_escape': ColorDescription(title=N_("Escape syntax highlight"), group=N_("Syntax Highlighting")), + 'syntax_hl_func': ColorDescription(title=N_("Function syntax highlight"), group=N_("Syntax Highlighting")), + 'syntax_hl_noop': ColorDescription(title=N_("Noop syntax highlight"), group=N_("Syntax Highlighting")), + 'syntax_hl_special': ColorDescription(title=N_("Special syntax highlight"), group=N_("Syntax Highlighting")), + 'syntax_hl_unicode': ColorDescription(title=N_("Unicode syntax highlight"), group=N_("Syntax Highlighting")), + 'syntax_hl_var': ColorDescription(title=N_("Variable syntax highlight"), group=N_("Syntax Highlighting")), } @@ -186,6 +192,12 @@ class InterfaceColors: def get_color_description(self, color_key): return _(self.default_colors[color_key].description) + def get_color_title(self, color_key): + return _(self.default_colors[color_key].description.title) + + def get_color_group(self, color_key): + return _(self.default_colors[color_key].description.group) + def set_color(self, color_key, color_value): if color_key in self.default_colors: qcolor = QtGui.QColor(color_value) diff --git a/picard/ui/options/interface_colors.py b/picard/ui/options/interface_colors.py index b95825584..f7113d15b 100644 --- a/picard/ui/options/interface_colors.py +++ b/picard/ui/options/interface_colors.py @@ -34,7 +34,10 @@ from picard.i18n import ( N_, gettext as _, ) -from picard.util import icontheme +from picard.util import ( + icontheme, + strxfrm, +) from picard.ui.colors import interface_colors from picard.ui.forms.ui_options_interface_colors import ( @@ -121,13 +124,27 @@ class InterfaceColorsOptionsPage(OptionsPage): interface_colors.set_default_color(color_key) color_button.update_color(interface_colors.get_qcolor(color_key)) - for color_key, color_value in interface_colors.get_colors().items(): + def colors(): + for color_key, color_value in interface_colors.get_colors().items(): + group = interface_colors.get_color_group(color_key) + title = interface_colors.get_color_title(color_key) + yield color_key, color_value, title, group + + prev_group = None + for color_key, color_value, title, group in sorted(colors(), key=lambda c: (strxfrm(c[3]), strxfrm(c[2]))): + if prev_group != group: + groupbox = QtWidgets.QGroupBox(group) + self.colors_list.addWidget(groupbox) + groupbox_layout = QtWidgets.QVBoxLayout() + groupbox.setLayout(groupbox_layout) + prev_group = group + widget = QtWidgets.QWidget() hlayout = QtWidgets.QHBoxLayout() hlayout.setContentsMargins(0, 0, 0, 0) - label = QtWidgets.QLabel(interface_colors.get_color_description(color_key)) + label = QtWidgets.QLabel(title) label.setSizePolicy(QtWidgets.QSizePolicy.Policy.Expanding, QtWidgets.QSizePolicy.Policy.Minimum) hlayout.addWidget(label) @@ -141,7 +158,7 @@ class InterfaceColorsOptionsPage(OptionsPage): hlayout.addWidget(refresh_button, 0, QtCore.Qt.AlignmentFlag.AlignRight) widget.setLayout(hlayout) - self.colors_list.addWidget(widget) + groupbox_layout.addWidget(widget) spacerItem1 = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Policy.Minimum, QtWidgets.QSizePolicy.Policy.Expanding) self.colors_list.addItem(spacerItem1)