Add dialog to show which profiles are attached to options on a page

- add new dialog
- fix settings groups keys
This commit is contained in:
Bob Swift
2021-07-11 12:00:47 -06:00
parent 06961f2d70
commit ed79cc9800
4 changed files with 181 additions and 2 deletions

View File

@@ -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")),

View File

@@ -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()

View File

@@ -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"))

View File

@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>AttachedProfilesDialog</class>
<widget class="QDialog" name="AttachedProfilesDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>450</height>
</rect>
</property>
<property name="windowTitle">
<string>Profiles Attached to Options</string>
</property>
<layout class="QVBoxLayout">
<property name="spacing">
<number>6</number>
</property>
<property name="leftMargin">
<number>9</number>
</property>
<property name="topMargin">
<number>9</number>
</property>
<property name="rightMargin">
<number>9</number>
</property>
<property name="bottomMargin">
<number>9</number>
</property>
<item>
<widget class="QTableView" name="options_list">
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::NoButton</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>