Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into centralize_options
Browse files Browse the repository at this point in the history
  • Loading branch information
zas committed Apr 25, 2024
2 parents 9bf11ba + 1222821 commit 70d2f9d
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 39 deletions.
27 changes: 12 additions & 15 deletions picard/ui/options/maintenance.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# Picard, the next-generation MusicBrainz tagger
#
# Copyright (C) 2021-2022 Bob Swift
# Copyright (C) 2021-2022, 2024 Bob Swift
# Copyright (C) 2021-2023 Philipp Wolfer
# Copyright (C) 2021-2024 Laurent Monin
#
Expand Down Expand Up @@ -85,23 +85,21 @@ def __init__(self, parent=None):
self.ui = Ui_MaintenanceOptionsPage()
self.ui.setupUi(self)
self.ui.description.setText(_(
"This allows you to remove unused option settings from the configuration INI file.\n\n"
"Settings that are found in the configuration file that do not appear on any option "
"settings page will be listed below. If your configuration file does not contain any "
"settings page are listed below. If your configuration file does not contain any "
"unused option settings, then the list will be empty and the removal checkbox will be "
"disabled.\n\n"
"Note that unused option settings could come from plugins that have been uninstalled, "
"so please be careful to not remove settings that you may want to use later when "
"the plugin is reinstalled. Options belonging to plugins that are installed but "
"currently disabled will not be listed for possible removal.\n\n"
"To remove one or more settings, first enable the removal by checking the \"Remove "
"selected options\" box. You can then select the settings to remove by checking the "
"box next to the setting. When you choose \"Make It So!\" to save your option "
"currently disabled are not listed for possible removal.\n\n"
"To remove one or more settings, select the settings that you want to remove by "
"checking the box next to the setting, and enable the removal by checking the \"Remove "
"selected options\" box. When you choose \"Make It So!\" to save your option "
"settings, the selected items will be removed."
))
self.ui.tableWidget.setHorizontalHeaderLabels([_("Option"), _("Value")])
self.ui.select_all.stateChanged.connect(self.select_all_changed)
self.ui.enable_cleanup.stateChanged.connect(self.enable_cleanup_changed)
self.ui.open_folder_button.clicked.connect(self.open_config_dir)
self.ui.save_backup_button.clicked.connect(self.save_backup)
self.ui.load_backup_button.clicked.connect(self.load_backup)
Expand Down Expand Up @@ -172,7 +170,7 @@ def load(self):

self.ui.option_counts.setText(
_("The configuration file currently contains %(totalcount)d option "
"settings, %(unusedcount)d which are unused.") % {
"settings (%(unusedcount)d unused).") % {
'totalcount': len(file_options),
'unusedcount': len(orphan_options),
})
Expand Down Expand Up @@ -200,9 +198,7 @@ def load(self):
self.ui.tableWidget.setCellWidget(row, 1, tableitem)
self.ui.tableWidget.resizeColumnsToContents()
self.ui.select_all.setCheckState(QtCore.Qt.CheckState.Unchecked)
if not len(orphan_options):
self.ui.select_all.setEnabled(False)
self.enable_cleanup_changed()
self._set_cleanup_state()

def open_config_dir(self):
config = get_config()
Expand Down Expand Up @@ -393,10 +389,11 @@ def make_setting_value_text(self, key):
value = config.setting.raw_value(key)
return repr(value)

def enable_cleanup_changed(self):
state = self.ui.enable_cleanup.checkState() == QtCore.Qt.CheckState.Checked
def _set_cleanup_state(self):
state = self.ui.tableWidget.rowCount() > 0
self.ui.select_all.setEnabled(state)
self.ui.tableWidget.setEnabled(state)
self.ui.enable_cleanup.setChecked(False)
self.ui.enable_cleanup.setEnabled(state)


register_options_page(MaintenanceOptionsPage)
1 change: 1 addition & 0 deletions picard/ui/options/releases.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def __init__(self, *args):
self.setSingleStep(self._step)
self.setTickInterval(self._step)
self.setPageStep(self._pagestep)
self.tagger = QtCore.QCoreApplication.instance()

def showEvent(self, event):
super().showEvent(event)
Expand Down
1 change: 1 addition & 0 deletions picard/ui/searchdialog/album.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ def __init__(self, parent, force_advanced_search=None, existing_album=None):
self.cover_cells = []
self.fetching = False
self.scrolled.connect(self.fetch_coverarts)
self.resized.connect(self.fetch_coverarts)

@staticmethod
def show_releasegroup_search(releasegroup_id, existing_album=None):
Expand Down
29 changes: 21 additions & 8 deletions picard/ui/tablebaseddialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,18 @@

class ResultTable(QtWidgets.QTableWidget):

def __init__(self, parent):
super().__init__(parent)
def __init__(self, parent=None, parent_dialog=None):
super().__init__(parent=parent)
self.parent_dialog = parent_dialog
self.setSelectionMode(QtWidgets.QAbstractItemView.SelectionMode.ExtendedSelection)
self.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectionBehavior.SelectRows)
self.setEditTriggers(QtWidgets.QAbstractItemView.EditTrigger.NoEditTriggers)
self.horizontalHeader().setStretchLastSection(True)
self.horizontalHeader().setSectionResizeMode(QtWidgets.QHeaderView.ResizeMode.Stretch)
self.horizontalHeader().setSectionResizeMode(QtWidgets.QHeaderView.ResizeMode.Interactive)

@throttle(1000) # only emit scrolled signal once per second
def emit_scrolled(x):
parent.scrolled.emit()
self.horizontalScrollBar().valueChanged.connect(emit_scrolled)
self.verticalScrollBar().valueChanged.connect(emit_scrolled)
self.horizontalScrollBar().valueChanged.connect(self.emit_scrolled)
self.verticalScrollBar().valueChanged.connect(self.emit_scrolled)
self.setHorizontalScrollMode(QtWidgets.QAbstractItemView.ScrollMode.ScrollPerPixel)

def prepare(self, headers):
Expand All @@ -73,6 +71,20 @@ def prepare(self, headers):
self.setRowCount(0)
self.setSortingEnabled(False)

@throttle(1000) # only emit scrolled signal once per second
def emit_scrolled(self, value):
if self.parent_dialog:
self.parent_dialog.scrolled.emit()

@throttle(1000) # only emit resized signal once per second
def emit_resized(self):
if self.parent_dialog:
self.parent_dialog.resized.emit()

def resizeEvent(self, event):
self.emit_resized()
super().resizeEvent(event)


class SortableTableWidgetItem(QtWidgets.QTableWidgetItem):

Expand All @@ -88,6 +100,7 @@ class TableBasedDialog(PicardDialog):

defaultsize = QtCore.QSize(720, 360)
scrolled = pyqtSignal()
resized = pyqtSignal()

def __init__(self, parent):
super().__init__(parent)
Expand Down Expand Up @@ -155,7 +168,7 @@ def add_widget_to_center_layout(self, widget):
widget.show()

def create_table_obj(self):
return ResultTable(self)
return ResultTable(parent_dialog=self)

def create_table(self):
self.table = self.create_table_obj()
Expand Down
24 changes: 19 additions & 5 deletions picard/ui/ui_options_maintenance.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,6 @@ def setupUi(self, MaintenanceOptionsPage):
self.option_counts.setText("")
self.option_counts.setObjectName("option_counts")
self.vboxlayout.addWidget(self.option_counts)
self.enable_cleanup = QtWidgets.QCheckBox(parent=MaintenanceOptionsPage)
self.enable_cleanup.setObjectName("enable_cleanup")
self.vboxlayout.addWidget(self.enable_cleanup)
self.description = QtWidgets.QLabel(parent=MaintenanceOptionsPage)
self.description.setText("")
self.description.setAlignment(QtCore.Qt.AlignmentFlag.AlignLeading|QtCore.Qt.AlignmentFlag.AlignLeft|QtCore.Qt.AlignmentFlag.AlignTop)
Expand All @@ -109,9 +106,18 @@ def setupUi(self, MaintenanceOptionsPage):
self.line.setFrameShadow(QtWidgets.QFrame.Shadow.Sunken)
self.line.setObjectName("line")
self.vboxlayout.addWidget(self.line)
self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
self.horizontalLayout_2.setContentsMargins(-1, 0, -1, -1)
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
self.select_all = QtWidgets.QCheckBox(parent=MaintenanceOptionsPage)
self.select_all.setObjectName("select_all")
self.vboxlayout.addWidget(self.select_all)
self.horizontalLayout_2.addWidget(self.select_all)
spacerItem2 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Policy.Expanding, QtWidgets.QSizePolicy.Policy.Minimum)
self.horizontalLayout_2.addItem(spacerItem2)
self.enable_cleanup = QtWidgets.QCheckBox(parent=MaintenanceOptionsPage)
self.enable_cleanup.setObjectName("enable_cleanup")
self.horizontalLayout_2.addWidget(self.enable_cleanup)
self.vboxlayout.addLayout(self.horizontalLayout_2)
self.tableWidget = QtWidgets.QTableWidget(parent=MaintenanceOptionsPage)
self.tableWidget.setSizeAdjustPolicy(QtWidgets.QAbstractScrollArea.SizeAdjustPolicy.AdjustToContents)
self.tableWidget.setEditTriggers(QtWidgets.QAbstractItemView.EditTrigger.NoEditTriggers)
Expand All @@ -124,6 +130,14 @@ def setupUi(self, MaintenanceOptionsPage):

self.retranslateUi(MaintenanceOptionsPage)
QtCore.QMetaObject.connectSlotsByName(MaintenanceOptionsPage)
MaintenanceOptionsPage.setTabOrder(self.config_file, self.open_folder_button)
MaintenanceOptionsPage.setTabOrder(self.open_folder_button, self.autobackup_dir)
MaintenanceOptionsPage.setTabOrder(self.autobackup_dir, self.browse_autobackup_dir)
MaintenanceOptionsPage.setTabOrder(self.browse_autobackup_dir, self.load_backup_button)
MaintenanceOptionsPage.setTabOrder(self.load_backup_button, self.save_backup_button)
MaintenanceOptionsPage.setTabOrder(self.save_backup_button, self.select_all)
MaintenanceOptionsPage.setTabOrder(self.select_all, self.enable_cleanup)
MaintenanceOptionsPage.setTabOrder(self.enable_cleanup, self.tableWidget)

def retranslateUi(self, MaintenanceOptionsPage):
self.label.setText(_("Configuration file:"))
Expand All @@ -132,5 +146,5 @@ def retranslateUi(self, MaintenanceOptionsPage):
self.browse_autobackup_dir.setText(_("Browse…"))
self.load_backup_button.setText(_("Load backup…"))
self.save_backup_button.setText(_("Save backup…"))
self.enable_cleanup.setText(_("Remove selected options"))
self.select_all.setText(_("Select all"))
self.enable_cleanup.setText(_("Remove selected options"))
53 changes: 42 additions & 11 deletions ui/options_maintenance.ui
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,6 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="enable_cleanup">
<property name="text">
<string>Remove selected options</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="description">
<property name="text">
Expand Down Expand Up @@ -185,11 +178,38 @@
</widget>
</item>
<item>
<widget class="QCheckBox" name="select_all">
<property name="text">
<string>Select all</string>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="topMargin">
<number>0</number>
</property>
</widget>
<item>
<widget class="QCheckBox" name="select_all">
<property name="text">
<string>Select all</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="enable_cleanup">
<property name="text">
<string>Remove selected options</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QTableWidget" name="tableWidget">
Expand All @@ -214,6 +234,17 @@
</item>
</layout>
</widget>
<tabstops>
<tabstop>config_file</tabstop>
<tabstop>open_folder_button</tabstop>
<tabstop>autobackup_dir</tabstop>
<tabstop>browse_autobackup_dir</tabstop>
<tabstop>load_backup_button</tabstop>
<tabstop>save_backup_button</tabstop>
<tabstop>select_all</tabstop>
<tabstop>enable_cleanup</tabstop>
<tabstop>tableWidget</tabstop>
</tabstops>
<resources/>
<connections/>
</ui>

0 comments on commit 70d2f9d

Please sign in to comment.