From 2a85fa2a1fc53c8d305ba035ae65c5a4afcd360b Mon Sep 17 00:00:00 2001 From: Bob Swift Date: Sat, 24 Apr 2021 10:01:26 -0600 Subject: [PATCH] Set maximum examples, tooltip and usage notes as class properties. --- picard/ui/scripteditor.py | 14 +++++++++++--- picard/ui/ui_options_renaming.py | 10 +++++----- picard/ui/ui_scripteditor.py | 2 +- ui/options_renaming.ui | 4 ++-- ui/scripteditor.ui | 2 +- 5 files changed, 20 insertions(+), 12 deletions(-) diff --git a/picard/ui/scripteditor.py b/picard/ui/scripteditor.py index 437c610df..973e13cec 100644 --- a/picard/ui/scripteditor.py +++ b/picard/ui/scripteditor.py @@ -81,6 +81,13 @@ $if(%_multiartist%,%artist% - ,) class ScriptEditorExamples(): """File naming script examples. """ + max_samples = 10 # pick up to 10 samples + notes_text = N_( + "If you select files from the Cluster pane or Album pane prior to opening the Options screen, " + "up to %u files will be randomly chosen from your selection as file naming examples. If you " + "have not selected any files, then some default examples will be provided.") % max_samples + tooltip_text = N_("Reload up to %u items chosen at random from files selected in the main window") % max_samples + def __init__(self, parent=None, tagger=None): """File naming script examples. @@ -98,16 +105,15 @@ class ScriptEditorExamples(): """Get a new sample of randomly selected / loaded files to use as renaming examples. """ import random - max_samples = 10 # pick up to 10 samples if self.tagger.tagger.window.selected_objects: # If files/albums/tracks are selected, sample example files from them files = self.tagger.tagger.get_files_from_objects(self.tagger.tagger.window.selected_objects) - length = min(max_samples, len(files)) + length = min(self.max_samples, len(files)) files = [file for file in random.sample(files, k=length)] else: # If files/albums/tracks are not selected, sample example files from the pool of loaded files files = self.tagger.tagger.files - length = min(max_samples, len(files)) + length = min(self.max_samples, len(files)) files = [files[key] for key in random.sample(files.keys(), k=length)] if not files: @@ -283,6 +289,8 @@ class ScriptEditorPage(PicardDialog): self.ui = Ui_ScriptEditor() self.ui.setupUi(self) + self.ui.example_filename_sample_files_button.setToolTip(self.examples.tooltip_text) + self.installEventFilter(self) self.ui.file_naming_editor_save.clicked.connect(self.save_script) diff --git a/picard/ui/ui_options_renaming.py b/picard/ui/ui_options_renaming.py index c53bab689..7b261627a 100644 --- a/picard/ui/ui_options_renaming.py +++ b/picard/ui/ui_options_renaming.py @@ -87,10 +87,11 @@ class Ui_RenamingOptionsPage(object): self.horizontalLayout_2.addWidget(self.example_filename_after) self.verticalLayout.addLayout(self.horizontalLayout_2) self.verticalLayout_5.addWidget(self.groupBox) - self.label_2 = QtWidgets.QLabel(RenamingOptionsPage) - self.label_2.setWordWrap(True) - self.label_2.setObjectName("label_2") - self.verticalLayout_5.addWidget(self.label_2) + self.example_selection_note = QtWidgets.QLabel(RenamingOptionsPage) + self.example_selection_note.setText("") + self.example_selection_note.setWordWrap(True) + self.example_selection_note.setObjectName("example_selection_note") + self.verticalLayout_5.addWidget(self.example_selection_note) self.horizontalLayout = QtWidgets.QHBoxLayout() self.horizontalLayout.setSpacing(2) self.horizontalLayout.setObjectName("horizontalLayout") @@ -125,6 +126,5 @@ class Ui_RenamingOptionsPage(object): self.groupBox.setTitle(_("Files will be named like this:")) self.example_filename_before_label.setText(_("Before")) self.example_filename_after_label.setText(_("After")) - self.label_2.setText(_("If you select files from the Cluster pane or Album pane prior to opening the Options screen, up to 10 files will be randomly chosen from your selection as file naming examples. If you have not selected any files, then some default examples will be provided.")) self.example_filename_sample_files_button.setText(_("Reload examples")) self.open_script_editor.setText(_("Open the file naming script editor")) diff --git a/picard/ui/ui_scripteditor.py b/picard/ui/ui_scripteditor.py index b175e02a1..bbf876e80 100644 --- a/picard/ui/ui_scripteditor.py +++ b/picard/ui/ui_scripteditor.py @@ -139,6 +139,7 @@ class Ui_ScriptEditor(object): self.horizontalLayout_4.setContentsMargins(-1, 0, -1, -1) self.horizontalLayout_4.setObjectName("horizontalLayout_4") self.example_filename_sample_files_button = QtWidgets.QPushButton(self.frame_4) + self.example_filename_sample_files_button.setToolTip("") self.example_filename_sample_files_button.setObjectName("example_filename_sample_files_button") self.horizontalLayout_4.addWidget(self.example_filename_sample_files_button) spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum) @@ -216,7 +217,6 @@ class Ui_ScriptEditor(object): self.file_naming_word_wrap.setText(_("Word wrap script")) self.show_documentation.setToolTip(_("Open the scripting documentation in a sidebar")) self.show_documentation.setText(_("Show Documentation")) - self.example_filename_sample_files_button.setToolTip(_("Up to 10 items chosen at random from files selected in the main window")) self.example_filename_sample_files_button.setText(_("Reload Examples")) self.import_script.setToolTip(_("Import a file to replace the current script")) self.import_script.setText(_("Import")) diff --git a/ui/options_renaming.ui b/ui/options_renaming.ui index f9b1bcbff..4d30098d4 100644 --- a/ui/options_renaming.ui +++ b/ui/options_renaming.ui @@ -167,9 +167,9 @@ - + - If you select files from the Cluster pane or Album pane prior to opening the Options screen, up to 10 files will be randomly chosen from your selection as file naming examples. If you have not selected any files, then some default examples will be provided. + true diff --git a/ui/scripteditor.ui b/ui/scripteditor.ui index a48536a34..d77201e04 100644 --- a/ui/scripteditor.ui +++ b/ui/scripteditor.ui @@ -295,7 +295,7 @@ - Up to 10 items chosen at random from files selected in the main window + Reload Examples