From db0ccaf1311914c2561ff97bc58343f487f08862 Mon Sep 17 00:00:00 2001 From: Laurent Monin Date: Wed, 13 Sep 2023 17:57:31 +0200 Subject: [PATCH] Replace CAATypesSelectorDialog.run() static method with module level function New function is named display_caa_types_selector() All keyword arguments are passed to CAATypesSelectorDialog constructor --- picard/coverart/providers/caa.py | 14 ++++++++------ picard/ui/caa_types_selector.py | 21 ++++++--------------- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/picard/coverart/providers/caa.py b/picard/coverart/providers/caa.py index 699734f060..e88f23fa8b 100644 --- a/picard/coverart/providers/caa.py +++ b/picard/coverart/providers/caa.py @@ -61,7 +61,7 @@ ) from picard.webservice import ratecontrol -from picard.ui.caa_types_selector import CAATypesSelectorDialog +from picard.ui.caa_types_selector import display_caa_types_selector from picard.ui.ui_provider_options_caa import Ui_CaaOptions @@ -176,11 +176,13 @@ def update_caa_types(self): def select_caa_types(self): known_types = {t['name']: translate_caa_type(t['name']) for t in CAA_TYPES} - (types, types_to_omit, ok) = CAATypesSelectorDialog.run( - self, - types_include=self.caa_image_types, types_exclude=self.caa_image_types_to_omit, - default_include=_CAA_IMAGE_TYPE_DEFAULT_INCLUDE, default_exclude=_CAA_IMAGE_TYPE_DEFAULT_EXCLUDE, - known_types=known_types + (types, types_to_omit, ok) = display_caa_types_selector( + parent=self, + types_include=self.caa_image_types, + types_exclude=self.caa_image_types_to_omit, + default_include=_CAA_IMAGE_TYPE_DEFAULT_INCLUDE, + default_exclude=_CAA_IMAGE_TYPE_DEFAULT_EXCLUDE, + known_types=known_types, ) if ok: self.caa_image_types = types diff --git a/picard/ui/caa_types_selector.py b/picard/ui/caa_types_selector.py index 77de29588b..10ba42bee0 100644 --- a/picard/ui/caa_types_selector.py +++ b/picard/ui/caa_types_selector.py @@ -169,7 +169,7 @@ def __init__( types_exclude = [] self._default_include = default_include or [] self._default_exclude = default_exclude or [] - self._known_types = known_types or [] + self._known_types = known_types or {} self.setWindowTitle(_("Cover art types")) self.setWindowModality(QtCore.Qt.WindowModality.WindowModal) @@ -348,17 +348,8 @@ def set_buttons_enabled_state(self): self.arrows_exclude.button_remove.setEnabled(has_items_exclude and has_selected_exclude) self.arrows_exclude.button_remove_all.setEnabled(has_items_exclude) - @staticmethod - def run( - parent=None, - types_include=None, types_exclude=None, - default_include=None, default_exclude=None, - known_types=None): - dialog = CAATypesSelectorDialog( - parent, - types_include=types_include, types_exclude=types_exclude, - default_include=default_include, default_exclude=default_exclude, - known_types=known_types - ) - result = dialog.exec_() - return (dialog.get_selected_types_include(), dialog.get_selected_types_exclude(), result == QtWidgets.QDialog.DialogCode.Accepted) + +def display_caa_types_selector(**kwargs): + dialog = CAATypesSelectorDialog(**kwargs) + result = dialog.exec_() + return (dialog.get_selected_types_include(), dialog.get_selected_types_exclude(), result == QtWidgets.QDialog.DialogCode.Accepted)