From ed79cc9800f013356fb41ae41b407bd7d7fcac8a Mon Sep 17 00:00:00 2001 From: Bob Swift Date: Sun, 11 Jul 2021 12:00:47 -0600 Subject: [PATCH] Add dialog to show which profiles are attached to options on a page - add new dialog - fix settings groups keys --- picard/profile.py | 4 +- picard/ui/options/dialog.py | 89 +++++++++++++++++++++++ picard/ui/ui_options_attached_profiles.py | 34 +++++++++ ui/options_attached_profiles.ui | 56 ++++++++++++++ 4 files changed, 181 insertions(+), 2 deletions(-) create mode 100644 picard/ui/ui_options_attached_profiles.py create mode 100644 ui/options_attached_profiles.ui diff --git a/picard/profile.py b/picard/profile.py index a1238406c..112953db5 100644 --- a/picard/profile.py +++ b/picard/profile.py @@ -78,7 +78,7 @@ class UserProfileGroups(): ], } - SETTINGS_GROUPS["coverart"] = { + SETTINGS_GROUPS["cover"] = { "title": N_("Cover Art"), "settings": [ SettingDesc("save_images_to_tags", N_("Save images to tags")), @@ -92,7 +92,7 @@ class UserProfileGroups(): ], } - SETTINGS_GROUPS["filenaming"] = { + SETTINGS_GROUPS["filerenaming"] = { "title": N_("File Naming"), "settings": [ SettingDesc("windows_compatibility", N_("Windows compatibility")), diff --git a/picard/ui/options/dialog.py b/picard/ui/options/dialog.py index 26cc2a829..d888ed058 100644 --- a/picard/ui/options/dialog.py +++ b/picard/ui/options/dialog.py @@ -32,6 +32,7 @@ from PyQt5 import ( QtCore, + QtGui, QtWidgets, ) @@ -42,6 +43,7 @@ from picard.config import ( TextOption, get_config, ) +from picard.profile import UserProfileGroups from picard.util import ( restore_method, webbrowser2, @@ -78,6 +80,7 @@ from picard.ui.options import ( # noqa: F401 # pylint: disable=unused-import tags_compatibility_id3, tags_compatibility_wave, ) +from picard.ui.ui_options_attached_profiles import Ui_AttachedProfilesDialog from picard.ui.util import StandardButton @@ -140,6 +143,11 @@ class OptionsDialog(PicardDialog, SingletonDialog): self.ui.profiles_buttonbox.addButton(profile_help, QtWidgets.QDialogButtonBox.HelpRole) self.ui.profiles_buttonbox.helpRequested.connect(self.show_profile_help) + self.ui.attached_profiles_button = QtWidgets.QPushButton(_("Attached Profiles")) + self.ui.attached_profiles_button.setToolTip(_("Show which profiles are attached to the options on this page")) + self.ui.profiles_buttonbox.addButton(self.ui.attached_profiles_button, QtWidgets.QDialogButtonBox.ActionRole) + self.ui.attached_profiles_button.clicked.connect(self.show_attached_profiles_dialog) + self.pages = [] for Page in page_classes: try: @@ -188,6 +196,28 @@ class OptionsDialog(PicardDialog, SingletonDialog): """ webbrowser2.open('doc_profile_edit') + def show_attached_profiles_dialog(self): + window_title = _("Profiles Attached to Options") + items = self.ui.pages_tree.selectedItems() + if items: + page = self.item_to_page[items[0]] + name = page.NAME + else: + name = '' + if name not in UserProfileGroups.get_setting_groups_list(): + message_box = QtWidgets.QMessageBox(self) + message_box.setIcon(QtWidgets.QMessageBox.Information) + message_box.setWindowModality(QtCore.Qt.WindowModal) + message_box.setWindowTitle(window_title) + message_box.setText(_("This page does not have any options that can be managed using profiles.")) + message_box.setStandardButtons(QtWidgets.QMessageBox.Ok) + return message_box.exec_() + + profile_dialog = AttachedProfilesDialog(parent=self, option_group=name) + profile_dialog.show() + profile_dialog.raise_() + profile_dialog.activateWindow() + def switch_profile(self, index): profile_id = self.ui.save_to_profile.currentData() config = get_config() @@ -337,3 +367,62 @@ class OptionsDialog(PicardDialog, SingletonDialog): message_box.setStandardButtons(QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No) if message_box.exec_() == QtWidgets.QMessageBox.Yes: function() + + +class AttachedProfilesDialog(PicardDialog): + NAME = 'attachedprofiles' + TITLE = N_('Attached Profiles') + + def __init__(self, parent=None, option_group=None): + super().__init__(parent=parent) + self.option_group = option_group + self.ui = Ui_AttachedProfilesDialog() + self.ui.setupUi(self) + self.ui.buttonBox.addButton(StandardButton(StandardButton.CLOSE), QtWidgets.QDialogButtonBox.RejectRole) + self.ui.buttonBox.rejected.connect(self.close_window) + + self.populate_table() + + self.ui.buttonBox.setFocus() + self.setModal(True) + + def populate_table(self): + model = QtGui.QStandardItemModel() + model.setColumnCount(2) + header_names = [_("Option Setting"), _("Attached Profiles")] + model.setHorizontalHeaderLabels(header_names) + + config = get_config() + profiles = config.profiles[SettingConfigSection.PROFILES_KEY] + settings = config.profiles[SettingConfigSection.SETTINGS_KEY] + + group = UserProfileGroups.SETTINGS_GROUPS[self.option_group] + group_title = group["title"] + group_options = group["settings"] + + window_title = _("Profiles Attached to Options in %s Section") % group_title + self.setWindowTitle(window_title) + + for name, title in group_options: + item = QtGui.QStandardItem(_(title)) + item.setEditable(False) + row = [item] + attached = [] + for profile in profiles: + if name in settings[profile["id"]]: + attached.append("{0}{1}".format(profile["title"], _(" [Enabled]") if profile["enabled"] else "",)) + attached_profiles = "\n".join(attached) if attached else _("None") + item = QtGui.QStandardItem(attached_profiles) + item.setEditable(False) + row.append(item) + model.appendRow(row) + + self.ui.options_list.setModel(model) + self.ui.options_list.resizeColumnsToContents() + self.ui.options_list.resizeRowsToContents() + self.ui.options_list.horizontalHeader().setStretchLastSection(True) + + def close_window(self): + """Close the script metadata editor window. + """ + self.close() diff --git a/picard/ui/ui_options_attached_profiles.py b/picard/ui/ui_options_attached_profiles.py new file mode 100644 index 000000000..fdf833b12 --- /dev/null +++ b/picard/ui/ui_options_attached_profiles.py @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- + +# Automatically generated - don't edit. +# Use `python setup.py build_ui` to update it. + + +from PyQt5 import QtCore, QtGui, QtWidgets + + +class Ui_AttachedProfilesDialog(object): + def setupUi(self, AttachedProfilesDialog): + AttachedProfilesDialog.setObjectName("AttachedProfilesDialog") + AttachedProfilesDialog.resize(800, 450) + self.vboxlayout = QtWidgets.QVBoxLayout(AttachedProfilesDialog) + self.vboxlayout.setContentsMargins(9, 9, 9, 9) + self.vboxlayout.setSpacing(6) + self.vboxlayout.setObjectName("vboxlayout") + self.options_list = QtWidgets.QTableView(AttachedProfilesDialog) + self.options_list.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers) + self.options_list.setSelectionMode(QtWidgets.QAbstractItemView.SingleSelection) + self.options_list.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows) + self.options_list.setObjectName("options_list") + self.vboxlayout.addWidget(self.options_list) + self.buttonBox = QtWidgets.QDialogButtonBox(AttachedProfilesDialog) + self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.NoButton) + self.buttonBox.setObjectName("buttonBox") + self.vboxlayout.addWidget(self.buttonBox) + + self.retranslateUi(AttachedProfilesDialog) + QtCore.QMetaObject.connectSlotsByName(AttachedProfilesDialog) + + def retranslateUi(self, AttachedProfilesDialog): + _translate = QtCore.QCoreApplication.translate + AttachedProfilesDialog.setWindowTitle(_("Profiles Attached to Options")) diff --git a/ui/options_attached_profiles.ui b/ui/options_attached_profiles.ui new file mode 100644 index 000000000..7c6c09b37 --- /dev/null +++ b/ui/options_attached_profiles.ui @@ -0,0 +1,56 @@ + + + AttachedProfilesDialog + + + + 0 + 0 + 800 + 450 + + + + Profiles Attached to Options + + + + 6 + + + 9 + + + 9 + + + 9 + + + 9 + + + + + QAbstractItemView::NoEditTriggers + + + QAbstractItemView::SingleSelection + + + QAbstractItemView::SelectRows + + + + + + + QDialogButtonBox::NoButton + + + + + + + +