From 78bfa97e03aaf4bd48b05f0fbbd70c4a163cdf98 Mon Sep 17 00:00:00 2001 From: un-pogaz <46523284+un-pogaz@users.noreply.github.com> Date: Sat, 1 Feb 2025 08:28:00 +0100 Subject: [PATCH] move "Look & Feel/Edit_metadata" to its own widget --- src/calibre/gui2/preferences/look_feel.py | 65 +---- src/calibre/gui2/preferences/look_feel.ui | 263 +---------------- .../look_feel_tabs/edit_metadata.py | 77 +++++ .../look_feel_tabs/edit_metadata.ui | 274 ++++++++++++++++++ 4 files changed, 358 insertions(+), 321 deletions(-) create mode 100644 src/calibre/gui2/preferences/look_feel_tabs/edit_metadata.py create mode 100644 src/calibre/gui2/preferences/look_feel_tabs/edit_metadata.ui diff --git a/src/calibre/gui2/preferences/look_feel.py b/src/calibre/gui2/preferences/look_feel.py index 488a569f06..4cf696b74b 100644 --- a/src/calibre/gui2/preferences/look_feel.py +++ b/src/calibre/gui2/preferences/look_feel.py @@ -5,80 +5,20 @@ __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' __docformat__ = 'restructuredtext en' -from functools import partial - from qt.core import QIcon, QKeySequence, QListWidgetItem, Qt -from calibre.gui2 import gprefs -from calibre.gui2.custom_column_widgets import get_field_list as em_get_field_list from calibre.gui2.preferences import ConfigWidgetBase, test_widget from calibre.gui2.preferences.coloring import EditRules -from calibre.gui2.preferences.look_feel_tabs import ( - DisplayedFields, - export_layout, - import_layout, - move_field_down, - move_field_up, - reset_layout, - selected_rows_metadatas, -) +from calibre.gui2.preferences.look_feel_tabs import selected_rows_metadatas from calibre.gui2.preferences.look_feel_ui import Ui_Form from calibre.gui2.widgets import BusyCursor -class EMDisplayedFields(DisplayedFields): # {{{ - def __init__(self, db, parent=None): - DisplayedFields.__init__(self, db, parent) - - def initialize(self, use_defaults=False, pref_data_override=None): - self.beginResetModel() - self.fields = [[x[0], x[1]] for x in - em_get_field_list(self.db, use_defaults=use_defaults, pref_data_override=pref_data_override)] - self.endResetModel() - self.changed = True - - def commit(self): - if self.changed: - self.db.new_api.set_pref('edit_metadata_custom_columns_to_display', self.fields) -# }}} - - class ConfigWidget(ConfigWidgetBase, Ui_Form): def genesis(self, gui): self.gui = gui - db = gui.library_view.model().db - - r = self.register - - choices = [(_('Default'), 'default'), (_('Compact metadata'), 'alt1'), - (_('All on 1 tab'), 'alt2')] - r('edit_metadata_single_layout', gprefs, - choices=[(_('Default'), 'default'), (_('Compact metadata'), 'alt1'), - (_('All on 1 tab'), 'alt2')]) - r('edit_metadata_ignore_display_order', db.prefs) - r('edit_metadata_elision_point', gprefs, - choices=[(_('Left'), 'left'), (_('Middle'), 'middle'), - (_('Right'), 'right')]) - r('edit_metadata_elide_labels', gprefs) - r('edit_metadata_single_use_2_cols_for_custom_fields', gprefs) - r('edit_metadata_bulk_cc_label_length', gprefs) - r('edit_metadata_single_cc_label_length', gprefs) - r('edit_metadata_templates_only_F2_on_booklist', gprefs) - - self.em_display_model = EMDisplayedFields(self.gui.current_db, self.em_display_order) - self.em_display_model.dataChanged.connect(self.changed_signal) - self.em_display_order.setModel(self.em_display_model) - mu = partial(move_field_up, self.em_display_order, self.em_display_model) - md = partial(move_field_down, self.em_display_order, self.em_display_model) - self.em_display_order.set_movement_functions(mu, md) - self.em_up_button.clicked.connect(mu) - self.em_down_button.clicked.connect(md) - self.em_export_layout_button.clicked.connect(partial(export_layout, self, model=self.em_display_model)) - self.em_import_layout_button.clicked.connect(partial(import_layout, self, model=self.em_display_model)) - self.em_reset_layout_button.clicked.connect(partial(reset_layout, model=self.em_display_model)) - self.edit_rules = EditRules(self.tabWidget) self.edit_rules.changed.connect(self.changed_signal) self.tabWidget.addTab(self.edit_rules, QIcon.ic('format-fill-color.png'), _('Column &coloring')) @@ -108,7 +48,6 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form): def initialize(self): ConfigWidgetBase.initialize(self) - self.em_display_model.initialize() db = self.gui.current_db mi = selected_rows_metadatas() self.edit_rules.initialize(db.field_metadata, db.prefs, mi, 'column_color_rules') @@ -116,14 +55,12 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form): def restore_defaults(self): ConfigWidgetBase.restore_defaults(self) - self.em_display_model.restore_defaults() self.edit_rules.clear() self.icon_rules.clear() self.changed_signal.emit() def commit(self, *args): with BusyCursor(): - self.em_display_model.commit() self.edit_rules.commit(self.gui.current_db.prefs) self.icon_rules.commit(self.gui.current_db.prefs) diff --git a/src/calibre/gui2/preferences/look_feel.ui b/src/calibre/gui2/preferences/look_feel.ui index c2a8de4f12..db5d1388da 100644 --- a/src/calibre/gui2/preferences/look_feel.ui +++ b/src/calibre/gui2/preferences/look_feel.ui @@ -46,7 +46,7 @@ &Book details - + :/images/edit_input.png:/images/edit_input.png @@ -54,257 +54,6 @@ Edit &metadata - - - - - - - Edit metadata (single) &layout: - - - opt_edit_metadata_single_layout - - - - - - - Choose a different layout for the Edit metadata dialog. The compact metadata layout favors editing custom metadata over changing covers and formats. - - - - - - - - - Select the custom columns (for this library) to display in the edit metadata dialogs and their order: - - - - - - Move down. Keyboard shortcut: Ctrl-Down arrow - - - - :/images/arrow-down.png:/images/arrow-down.png - - - - - - - Move up. Keyboard shortcut: Ctrl-Up arrow - - - - :/images/arrow-up.png:/images/arrow-up.png - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - true - - - - - - - - - Click this button to reset the list to its default order. - - - Reset list - - - - - - - <p>Click this button to set the list to one -previously exported. This could be useful if you have several libraries with -similar structure and you want to use the same column order for each one. Columns -in the imported list that aren't in the current library are ignored. Columns in -the library that are not in the imported list are put at the end and marked -as displayable.</p> - - - Import list - - - - - - - <p>Click this button to write the current display -settings to a file. This could be useful if you have several libraries with similar -structure and you want to use the same column order for each one.</p> - - - Export list - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - - - - - - <p>Check this box to make the edit metadata dialogs ignore the -above specifications, showing all the columns in the default order. This is -useful for temporarily seeing all your columns in the dialogs without losing -the display and order specifications.</p> - - - Show &all columns in default order when editing metadata - - - - - - - If checked then labels wider than the label width -will be elided, otherwise they will be word wrapped. - - - &Elide labels when editing custom columns - - - - - - - - - - - - - - - - Elision point: - - - opt_edit_metadata_elision_point - - - - - - - Choose where in the label to put the... - - - - - - - - - <p>Check this box to allow only the F2 (Edit) key to -open the template editor in the book list for a "Column built from other -columns". Editing with mouse clicks and the Tab key will be disabled.</p> - - - Only the &F2 (Edit) key edits column templates in the book list - - - - - - - - - - - Use &two columns for custom columns in the Default layout - - - - - - - &Bulk edit custom column label length: - - - opt_edit_metadata_bulk_cc_label_length - - - - - - - The maximum width of a custom column label for the bulk metadata edit dialog in average characters. - - - chars - - - - - - - &Single edit custom column label length: - - - opt_edit_metadata_single_cc_label_length - - - - - - - The maximum width of a custom column label for the single metadata edit dialog in average characters. - - - chars - - - - - - - - @@ -368,11 +117,6 @@ columns". Editing with mouse clicks and the Tab key will be disabled.</p - - ListViewWithMoveByKeyPress - QListView -
calibre/gui2/preferences.h
-
ScrollingTabWidget QTabWidget @@ -399,6 +143,11 @@ columns". Editing with mouse clicks and the Tab key will be disabled.</p ConfigWidgetBase
calibre/gui2/preferences/look_feel_tabs/book_details.h
+ + EditMetadataTab + ConfigWidgetBase +
calibre/gui2/preferences/look_feel_tabs/edit_metadata.h
+
TbDisplayTab ConfigWidgetBase diff --git a/src/calibre/gui2/preferences/look_feel_tabs/edit_metadata.py b/src/calibre/gui2/preferences/look_feel_tabs/edit_metadata.py new file mode 100644 index 0000000000..727cc6e7aa --- /dev/null +++ b/src/calibre/gui2/preferences/look_feel_tabs/edit_metadata.py @@ -0,0 +1,77 @@ +#!/usr/bin/env python + +__license__ = 'GPL v3' +__copyright__ = '2025, Kovid Goyal ' +__docformat__ = 'restructuredtext en' + + +from functools import partial + +from calibre.gui2 import gprefs +from calibre.gui2.custom_column_widgets import get_field_list as em_get_field_list +from calibre.gui2.preferences import LazyConfigWidgetBase +from calibre.gui2.preferences.look_feel_tabs import DisplayedFields, export_layout, import_layout, move_field_down, move_field_up, reset_layout +from calibre.gui2.preferences.look_feel_tabs.edit_metadata_ui import Ui_Form +from calibre.gui2.widgets import BusyCursor + + +class EMDisplayedFields(DisplayedFields): + def __init__(self, db, parent=None): + DisplayedFields.__init__(self, db, parent) + + def initialize(self, use_defaults=False, pref_data_override=None): + self.beginResetModel() + self.fields = [[x[0], x[1]] for x in + em_get_field_list(self.db, use_defaults=use_defaults, pref_data_override=pref_data_override)] + self.endResetModel() + self.changed = True + + def commit(self): + if self.changed: + self.db.new_api.set_pref('edit_metadata_custom_columns_to_display', self.fields) + + +class EditMetadataTab(LazyConfigWidgetBase, Ui_Form): + + def genesis(self, gui): + self.gui = gui + db = self.gui.library_view.model().db + r = self.register + + r('edit_metadata_single_layout', gprefs, + choices=[(_('Default'), 'default'), (_('Compact metadata'), 'alt1'), + (_('All on 1 tab'), 'alt2')]) + r('edit_metadata_ignore_display_order', db.prefs) + r('edit_metadata_elision_point', gprefs, + choices=[(_('Left'), 'left'), (_('Middle'), 'middle'), + (_('Right'), 'right')]) + r('edit_metadata_elide_labels', gprefs) + r('edit_metadata_single_use_2_cols_for_custom_fields', gprefs) + r('edit_metadata_bulk_cc_label_length', gprefs) + r('edit_metadata_single_cc_label_length', gprefs) + r('edit_metadata_templates_only_F2_on_booklist', gprefs) + + self.em_display_model = EMDisplayedFields(self.gui.current_db, self.em_display_order) + self.em_display_model.dataChanged.connect(self.changed_signal) + self.em_display_order.setModel(self.em_display_model) + mu = partial(move_field_up, self.em_display_order, self.em_display_model) + md = partial(move_field_down, self.em_display_order, self.em_display_model) + self.em_display_order.set_movement_functions(mu, md) + self.em_up_button.clicked.connect(mu) + self.em_down_button.clicked.connect(md) + self.em_export_layout_button.clicked.connect(partial(export_layout, self, model=self.em_display_model)) + self.em_import_layout_button.clicked.connect(partial(import_layout, self, model=self.em_display_model)) + self.em_reset_layout_button.clicked.connect(partial(reset_layout, model=self.em_display_model)) + + def lazy_initialize(self): + self.em_display_model.initialize() + + def commit(self): + with BusyCursor(): + self.em_display_model.commit() + return LazyConfigWidgetBase.commit(self) + + def restore_defaults(self): + LazyConfigWidgetBase.restore_defaults(self) + self.em_display_model.restore_defaults() + self.changed_signal.emit() diff --git a/src/calibre/gui2/preferences/look_feel_tabs/edit_metadata.ui b/src/calibre/gui2/preferences/look_feel_tabs/edit_metadata.ui new file mode 100644 index 0000000000..ad2d167446 --- /dev/null +++ b/src/calibre/gui2/preferences/look_feel_tabs/edit_metadata.ui @@ -0,0 +1,274 @@ + + + Form + + + + :/images/edit_input.png:/images/edit_input.png + + + Edit &metadata + + + + + + + + Edit metadata (single) &layout: + + + opt_edit_metadata_single_layout + + + + + + + Choose a different layout for the Edit metadata dialog. The compact metadata layout favors editing custom metadata over changing covers and formats. + + + + + + + + + Select the custom columns (for this library) to display in the edit metadata dialogs and their order: + + + + + + Move down. Keyboard shortcut: Ctrl-Down arrow + + + + :/images/arrow-down.png:/images/arrow-down.png + + + + + + + Move up. Keyboard shortcut: Ctrl-Up arrow + + + + :/images/arrow-up.png:/images/arrow-up.png + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + true + + + + + + + + + Click this button to reset the list to its default order. + + + Reset list + + + + + + + <p>Click this button to set the list to one +previously exported. This could be useful if you have several libraries with +similar structure and you want to use the same column order for each one. Columns +in the imported list that aren't in the current library are ignored. Columns in +the library that are not in the imported list are put at the end and marked +as displayable.</p> + + + Import list + + + + + + + <p>Click this button to write the current display +settings to a file. This could be useful if you have several libraries with similar +structure and you want to use the same column order for each one.</p> + + + Export list + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + + + + <p>Check this box to make the edit metadata dialogs ignore the +above specifications, showing all the columns in the default order. This is +useful for temporarily seeing all your columns in the dialogs without losing +the display and order specifications.</p> + + + Show &all columns in default order when editing metadata + + + + + + + If checked then labels wider than the label width +will be elided, otherwise they will be word wrapped. + + + &Elide labels when editing custom columns + + + + + + + + + + + + + + + + Elision point: + + + opt_edit_metadata_elision_point + + + + + + + Choose where in the label to put the... + + + + + + + + + <p>Check this box to allow only the F2 (Edit) key to +open the template editor in the book list for a "Column built from other +columns". Editing with mouse clicks and the Tab key will be disabled.</p> + + + Only the &F2 (Edit) key edits column templates in the book list + + + + + + + + + + + Use &two columns for custom columns in the Default layout + + + + + + + &Bulk edit custom column label length: + + + opt_edit_metadata_bulk_cc_label_length + + + + + + + The maximum width of a custom column label for the bulk metadata edit dialog in average characters. + + + chars + + + + + + + &Single edit custom column label length: + + + opt_edit_metadata_single_cc_label_length + + + + + + + The maximum width of a custom column label for the single metadata edit dialog in average characters. + + + chars + + + + + + + + + + + + ListViewWithMoveByKeyPress + QListView +
calibre/gui2/preferences.h
+
+
+ + + +