UserProfileGroups: use Page.NAME as group name, and drop hardcoded titles

This commit is contained in:
Laurent Monin
2024-04-26 14:11:08 +02:00
parent 380f67093f
commit 663a33cf50
3 changed files with 7 additions and 18 deletions

View File

@@ -25,8 +25,6 @@
from collections import namedtuple
from picard.i18n import N_
SettingDesc = namedtuple('SettingDesc', ('name', 'fields'))
@@ -35,19 +33,12 @@ class UserProfileGroups():
"""Provides information about the profile groups available for selecting in a user profile,
and the title and settings that apply to each profile group.
"""
_settings_groups = {
'general': {'title': N_("General")},
'metadata': {'title': N_("Metadata")},
'tags': {'title': N_("Tags")},
'cover': {'title': N_("Cover Art")},
'filerenaming': {'title': N_("File Naming")},
'scripting': {'title': N_("Scripting")},
'interface': {'title': N_("User Interface")},
'advanced': {'title': N_("Advanced")},
}
_settings_groups = {}
@classmethod
def append_to_group(cls, group, option, highlights):
def append_to_group(cls, group, option, highlights, title=None):
if group not in cls._settings_groups:
cls._settings_groups[group] = {'title': title or group}
if 'settings' not in cls._settings_groups[group]:
cls._settings_groups[group]['settings'] = []
cls._settings_groups[group]['settings'].append(SettingDesc(option, highlights))
@@ -77,8 +68,7 @@ class UserProfileGroups():
@classmethod
def group_from_page(cls, page):
try:
name = page.PARENT if page.PARENT in cls._settings_groups else page.NAME
return cls._settings_groups[name]
return cls._settings_groups[page.NAME]
except (AttributeError, KeyError):
pass
return None

View File

@@ -137,8 +137,7 @@ class OptionsPage(QtWidgets.QWidget):
raise Exception(f"Cannot register setting for non-existing option {name}")
self._registered_settings.append(option)
if highlights is not None:
page_name = self.PARENT if self.PARENT else self.NAME
UserProfileGroups.append_to_group(page_name, name, tuple(highlights))
UserProfileGroups.append_to_group(self.NAME, name, tuple(highlights), title=self.TITLE)
_pages = ExtensionPoint(label='pages')

View File

@@ -211,7 +211,7 @@ class ProfilesOptionsPage(OptionsPage):
return
self.building_tree = True
for group in UserProfileGroups.values():
title = group['title']
title = _(group['title'])
group_settings = group['settings']
widget_item = QtWidgets.QTreeWidgetItem([title])
widget_item.setFlags(QtCore.Qt.ItemFlag.ItemIsEnabled | QtCore.Qt.ItemFlag.ItemIsUserCheckable | QtCore.Qt.ItemFlag.ItemIsAutoTristate)