Set maximum examples, tooltip and usage notes as class properties.

This commit is contained in:
Bob Swift
2021-04-24 10:01:26 -06:00
committed by Philipp Wolfer
parent be18bcbfb8
commit 2a85fa2a1f
5 changed files with 20 additions and 12 deletions

View File

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

View File

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

View File

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

View File

@@ -167,9 +167,9 @@
</widget>
</item>
<item>
<widget class="QLabel" name="label_2">
<widget class="QLabel" name="example_selection_note">
<property name="text">
<string>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.</string>
<string/>
</property>
<property name="wordWrap">
<bool>true</bool>

View File

@@ -295,7 +295,7 @@
<item>
<widget class="QPushButton" name="example_filename_sample_files_button">
<property name="toolTip">
<string>Up to 10 items chosen at random from files selected in the main window</string>
<string/>
</property>
<property name="text">
<string>Reload Examples</string>