diff options
author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2018-01-03 18:30:52 +0100 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2018-01-03 18:30:52 +0100 |
commit | 8351a36cbcbe8529ec1c0bb60d77bf65fb59fe12 (patch) | |
tree | bde5b8890f0bb80adfe2f9dea4bd42fa70fa03cf /raphodo/nameeditor.py | |
parent | c5fc6c6030d7d9d1b2af3d5165bebed3decd741b (diff) |
New upstream version 0.9.7upstream/0.9.7
Diffstat (limited to 'raphodo/nameeditor.py')
-rwxr-xr-x | raphodo/nameeditor.py | 143 |
1 files changed, 92 insertions, 51 deletions
diff --git a/raphodo/nameeditor.py b/raphodo/nameeditor.py index 5bb570e..83b16b4 100755 --- a/raphodo/nameeditor.py +++ b/raphodo/nameeditor.py @@ -275,10 +275,12 @@ class PrefEditor(QTextEdit): cursor.insertText('<{}>'.format(pref_value)) def _setHighlighter(self) -> None: - self.highlighter = PrefHighlighter(list(self.string_to_pref_mapper.keys()), - self.pref_color, - self.document()) + self.highlighter = PrefHighlighter( + list(self.string_to_pref_mapper.keys()), self.pref_color, self.document() + ) + # when color coding of text in the editor is complete, + # generate the preference list self.highlighter.blockHighlighted.connect(self.generatePrefList) def setPrefMapper(self, pref_mapper: Dict[Tuple[str, str, str], str], @@ -289,7 +291,7 @@ class PrefEditor(QTextEdit): self.pref_color = pref_color self._setHighlighter() - def _parseTextFragment(self, text_fragment) -> List[str]: + def _parseTextFragment(self, text_fragment) -> None: if self.subfolder: text_fragments = text_fragment.split(os.sep) for index, text_fragment in enumerate(text_fragments): @@ -421,7 +423,8 @@ def make_subfolder_menu_entry(prefs: Tuple[str]) -> str: desc = prefs[0] elements = prefs[1:] return _("%(description)s - %(elements)s") % dict( - description=desc, elements=os.sep.join(elements)) + description=desc, elements=os.sep.join(elements) + ) def make_rename_menu_entry(prefs: Tuple[str]) -> str: @@ -603,20 +606,26 @@ class PresetComboBox(QComboBox): self.removeItem(index) self.preset_edited = self.new_preset = False - def setRemoveAllCustomEnabled(self, enabled: bool) -> None: + def _setRowEnabled(self, enabled: bool, offset: int) -> None: assert self.edit_mode # Our big assumption here is that the model is a QStandardItemModel model = self.model() count = self.count() if self.preset_edited: - row = count - 2 + row = count - offset - 1 else: - row = count - 1 + row = count - offset item = model.item(row, 0) # type: QStandardItem if not enabled: item.setFlags(Qt.NoItemFlags) else: - item.setFlags(Qt.ItemIsSelectable|Qt.ItemIsEnabled) + item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled) + + def setRemoveAllCustomEnabled(self, enabled: bool) -> None: + self._setRowEnabled(enabled=enabled, offset=1) + + def setSaveNewCustomPresetEnabled(self, enabled: bool) -> None: + self._setRowEnabled(enabled=enabled, offset=2) def getComboBoxIndex(self, preset_index: int) -> int: """ @@ -636,11 +645,10 @@ class PresetComboBox(QComboBox): assert self.preset_separator return preset_index + 1 - def getPresetIndex(self, combobox_index: int) -> int: """ Opposite of getComboBoxIndex: calculates the preset index based on the - given combox box index (which includes separators etc.) + given combo box index (which includes separators etc.) :param combobox_index: the index into the combobox entries the user sees :return: the index into the presets (built-in & custom) """ @@ -726,9 +734,9 @@ def make_sample_rpd_file(sample_job_code: str, downloads_today_tracker = DownloadsTodayTracker( day_start=prefs.day_start, - downloads_today=prefs.downloads_today) - sequences = gn.Sequences(downloads_today_tracker, - prefs.stored_sequence_no) + downloads_today=prefs.downloads_today + ) + sequences = gn.Sequences(downloads_today_tracker, prefs.stored_sequence_no) if sample_rpd_file is not None: if sample_rpd_file.metadata is None: logging.debug('Sample file is missing its metadata') @@ -754,6 +762,7 @@ def make_sample_rpd_file(sample_job_code: str, return sample_rpd_file + class EditorCombobox(QComboBox): """ Regular combobox, but ignores the mouse wheel @@ -762,6 +771,7 @@ class EditorCombobox(QComboBox): def wheelEvent(self, event: QWheelEvent) -> None: event.ignore() + class PrefDialog(QDialog): """ Dialog window to allow editing of file renaming and subfolder generation @@ -840,7 +850,8 @@ class PrefDialog(QDialog): # <b>. These are used to format the text the users sees warning_msg = _( '<b><font color="red">Warning:</font></b> <i>There is insufficient data to fully ' - 'generate the name. Please use other renaming options.</i>') + 'generate the name. Please use other renaming options.</i>' + ) self.is_subfolder = generation_type in ( NameGenerationType.photo_subfolder, NameGenerationType.video_subfolder @@ -850,14 +861,16 @@ class PrefDialog(QDialog): # Translators: please do not modify, change the order of or leave out html formatting # tags like <i> and <b>. These are used to format the text the users sees. # In this case, the </i> really is supposed to come before the <i>. - subfolder_msg = _("The character</i> %(separator)s <i>creates a new subfolder " - "level.") % dict(separator=os.sep) + subfolder_msg = _( + "The character</i> %(separator)s <i>creates a new subfolder level." + ) % dict(separator=os.sep) # Translators: please do not modify, change the order of or leave out html formatting # tags like <i> and <b>. These are used to format the text the users sees # In this case, the </i> really is supposed to come before the <i>. - subfolder_first_char_msg = _("There is no need start or end with the folder " - "separator </i> %(separator)s<i>, because it is added " - "automatically.") % dict(separator=os.sep) + subfolder_first_char_msg = _( + "There is no need start or end with the folder separator </i> %(separator)s<i>, " + "because it is added automatically." + ) % dict(separator=os.sep) messages = (warning_msg, subfolder_msg, subfolder_first_char_msg) else: # Translators: please do not modify or leave out html formatting tags like <i> and @@ -893,7 +906,7 @@ class PrefDialog(QDialog): self.setLayout(layout) layout.addLayout(flayout) - layout.addSpacing(QFontMetrics(QFont()).height() / 2) + layout.addSpacing(int(QFontMetrics(QFont()).height() / 2)) layout.addWidget(self.editor) layout.addWidget(self.messageWidget) @@ -1136,20 +1149,27 @@ class PrefDialog(QDialog): self.updateComboBoxCurrentIndex() def updateComboBoxCurrentIndex(self) -> None: + """ + Sets the combo value to match the current preference value + """ + combobox_index, pref_list_index = self.getPresetMatch() if pref_list_index >= 0: + # the editor contains an existing preset self.preset.setCurrentIndex(combobox_index) if self.preset.preset_edited or self.preset.new_preset: self.preset.resetPresetList() + self.preset.setSaveNewCustomPresetEnabled(enabled=False) if pref_list_index >= len(self.builtin_pref_names): self.current_custom_name = self.preset.currentText() else: self.current_custom_name = None elif not (self.preset.new_preset or self.preset.preset_edited): - if self.current_custom_name is None: - self.preset.setPresetNew() - else: - self.preset.setPresetEdited(self.current_custom_name) + if self.current_custom_name is None: + self.preset.setPresetNew() + else: + self.preset.setPresetEdited(self.current_custom_name) + self.preset.setSaveNewCustomPresetEnabled(enabled=True) else: self.preset.setCurrentIndex(0) @@ -1228,6 +1248,7 @@ class PrefDialog(QDialog): self.saveNewPreset(preset_name=preset_name) if len(self.preset_names) == 1: self.preset.setRemoveAllCustomEnabled(True) + self.preset.setSaveNewCustomPresetEnabled(enabled=False) else: # User cancelled creating a new preset self.updateComboBoxCurrentIndex() @@ -1264,8 +1285,10 @@ class PrefDialog(QDialog): self.movePresetToFront(index=index) else: self._updateCombinedPrefs() - self.prefs.set_preset(preset_type=self.preset_type, preset_names=self.preset_names, - preset_pref_lists=self.preset_pref_lists) + self.prefs.set_preset( + preset_type=self.preset_type, preset_names=self.preset_names, + preset_pref_lists=self.preset_pref_lists + ) def movePresetToFront(self, index: int) -> None: """ @@ -1287,8 +1310,10 @@ class PrefDialog(QDialog): self.preset_names.insert(0, preset_name) self.preset_pref_lists.insert(0, pref_list) self._updateCombinedPrefs() - self.prefs.set_preset(preset_type=self.preset_type, preset_names=self.preset_names, - preset_pref_lists=self.preset_pref_lists) + self.prefs.set_preset( + preset_type=self.preset_type, preset_names=self.preset_names, + preset_pref_lists=self.preset_pref_lists + ) def saveNewPreset(self, preset_name: str) -> None: """ @@ -1306,8 +1331,10 @@ class PrefDialog(QDialog): self.preset_names.insert(0, preset_name) self.preset_pref_lists.insert(0, user_pref_list) self._updateCombinedPrefs() - self.prefs.set_preset(preset_type=self.preset_type, preset_names=self.preset_names, - preset_pref_lists=self.preset_pref_lists) + self.prefs.set_preset( + preset_type=self.preset_type, preset_names=self.preset_names, + preset_pref_lists=self.preset_pref_lists + ) def clearCustomPresets(self) -> None: """ @@ -1321,8 +1348,10 @@ class PrefDialog(QDialog): self.preset_pref_lists = [] self.current_custom_name = None self._updateCombinedPrefs() - self.prefs.set_preset(preset_type=self.preset_type, preset_names=self.preset_names, - preset_pref_lists=self.preset_pref_lists) + self.prefs.set_preset( + preset_type=self.preset_type, preset_names=self.preset_names, + preset_pref_lists=self.preset_pref_lists + ) def udpateCachedPrefLists(self) -> None: self.preset_names, self.preset_pref_lists = self.prefs.get_preset( @@ -1339,8 +1368,9 @@ class PrefDialog(QDialog): if the current user pref list matches an entry in it. Else Tuple of (-1, -1). """ - index = match_pref_list(pref_lists=self.combined_pref_lists, - user_pref_list=self.editor.user_pref_list) + index = match_pref_list( + pref_lists=self.combined_pref_lists, user_pref_list=self.editor.user_pref_list + ) if index >= 0: combobox_name = self.combined_pref_names[index] return self.preset.findText(combobox_name), index @@ -1362,22 +1392,27 @@ class PrefDialog(QDialog): msgBox.setIcon(QMessageBox.Question) msgBox.setWindowTitle(title) if self.preset.new_preset: - message = _("<b>Do you want to save the changes in a new custom preset?</b><br><br>" - "Creating a custom preset is not required, but can help you keep " - "organized.<br><br>" - "The changes to the preferences will still be applied regardless of " - "whether you create a new custom preset or not.") + message = _( + "<b>Do you want to save the changes in a new custom preset?</b><br><br>" + "Creating a custom preset is not required, but can help you keep " + "organized.<br><br>" + "The changes to the preferences will still be applied regardless of " + "whether you create a new custom preset or not." + ) msgBox.setStandardButtons(QMessageBox.Yes|QMessageBox.No) updateButton = newButton = None else: assert self.preset.preset_edited - message = _("<b>Do you want to save the changes in a custom preset?</b><br><br>" - "If you like, you can create a new custom preset or update the " - "existing custom preset.<br><br>" - "The changes to the preferences will still be applied regardless of " - "whether you save a custom preset or not.") - updateButton = msgBox.addButton(_('Update Custom Preset "%s"') % - self.current_custom_name, QMessageBox.YesRole) + message = _( + "<b>Do you want to save the changes in a custom preset?</b><br><br>" + "If you like, you can create a new custom preset or update the " + "existing custom preset.<br><br>" + "The changes to the preferences will still be applied regardless of " + "whether you save a custom preset or not." + ) + updateButton = msgBox.addButton( + _('Update Custom Preset "%s"') % self.current_custom_name, QMessageBox.YesRole + ) newButton = msgBox.addButton(_('Save New Custom Preset'), QMessageBox.YesRole) msgBox.addButton(QMessageBox.No) @@ -1418,12 +1453,18 @@ if __name__ == '__main__': prefs = Preferences() - prefDialog = PrefDialog(DICT_IMAGE_RENAME_L0, PHOTO_RENAME_MENU_DEFAULTS_CONV[1], - NameGenerationType.photo_name, prefs) + # prefDialog = PrefDialog(DICT_IMAGE_RENAME_L0, PHOTO_RENAME_MENU_DEFAULTS_CONV[1], + # NameGenerationType.photo_name, prefs) # prefDialog = PrefDialog(DICT_VIDEO_RENAME_L0, VIDEO_RENAME_MENU_DEFAULTS_CONV[1], # NameGenerationType.video_name, prefs) - # prefDialog = PrefDialog(DICT_SUBFOLDER_L0, PHOTO_SUBFOLDER_MENU_DEFAULTS_CONV[2], - # NameGenerationType.photo_subfolder, prefs) + prefDialog = PrefDialog( + DICT_SUBFOLDER_L0, PHOTO_SUBFOLDER_MENU_DEFAULTS_CONV[2], + NameGenerationType.photo_subfolder, prefs + ) + # prefDialog = PrefDialog( + # DICT_VIDEO_SUBFOLDER_L0, VIDEO_SUBFOLDER_MENU_DEFAULTS_CONV[2], + # NameGenerationType.video_subfolder, prefs + # ) prefDialog.show() app.exec_() |