diff --git a/src/calibre/gui2/preferences/__init__.py b/src/calibre/gui2/preferences/__init__.py index 92689d62f6..39ca726937 100644 --- a/src/calibre/gui2/preferences/__init__.py +++ b/src/calibre/gui2/preferences/__init__.py @@ -114,6 +114,9 @@ class ConfigWidgetInterface: def do_on_child_tabs(self, method, *args): r = False for t in self.child_tabs: + tab_opened = getattr(t, 'tab_opened', True) + if method in ('commit', 'refresh_gui') and not tab_opened: + continue r = r | bool(getattr(t, method)(*args)) return r @@ -291,7 +294,7 @@ class ConfigWidgetBase(QWidget, ConfigWidgetInterface): self.settings = {} self.child_tabs = [] for v in self.__dict__.values(): - if isinstance(v, ConfigTabWidget): + if isinstance(v, LazyConfigWidgetBase): self.child_tabs.append(v) def register(self, name, config_obj, gui_name=None, choices=None, @@ -349,11 +352,30 @@ def get_plugin(category, name): (category, name)) -class ConfigTabWidget(ConfigWidgetBase): +class LazyConfigWidgetBase(ConfigWidgetBase): + ''' + Use this for dialogs that are tabs, accessed either from the left or on the + top. It directly replaces ConfigWidgetBase, supporting the lazy operations. + ''' + + def __init__(self, parent=None): + super().__init__(parent) + self.tab_opened = False def set_changed_signal(self, changed_signal): self.changed_signal.connect(changed_signal) + def showEvent(self, event): + # called when the widget is actually displays. We can't do something like + # lazy_genesis because Qt does "things" before showEvent() is called. In + # particular, the register function doesn't work with combo boxes if + # genesis isn't called before everythign else. Why is a mystery. + if not self.tab_opened: + if hasattr(self, 'lazy_initialize'): + self.lazy_initialize() + self.tab_opened = True + super().showEvent(event) + class ConfigDialog(QDialog): diff --git a/src/calibre/gui2/preferences/look_feel.ui b/src/calibre/gui2/preferences/look_feel.ui index 3a88668f44..c55a609c84 100644 --- a/src/calibre/gui2/preferences/look_feel.ui +++ b/src/calibre/gui2/preferences/look_feel.ui @@ -1307,487 +1307,15 @@ columns". Editing with mouse clicks and the Tab key will be disabled.</p &Tag browser - + Di&splay - - - - - User categories and Saved searches cannot be moved - - - Select the categories to display in the Tag browser, and their &order - - - tb_display_order - - - - - - - - 0 - 200 - - - - true - - - - - - - Move up. User categories and Saved searches cannot be moved. Keyboard shortcut: Ctrl-Up arrow - - - - :/images/arrow-up.png:/images/arrow-up.png - - - - - - - Qt::Vertical - - - - 50 - 40 - - - - - - - - Move down. User categories and Saved searches cannot be moved. Keyboard shortcut: Ctrl-Down arrow - - - - :/images/arrow-down.png:/images/arrow-down.png - - - - - - - - - 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 - - - - - - - - - - - - Show the average rating per item indication in the Tag browser - - - Show &average ratings - - - true - - - - - - - Show an icon if the item has an attached link - - - Show &links icons - - - true - - - - - - - Show &tooltips - - - - - - - <p>Show counts for items in the Tag browser. Such as the number of books -by each author, the number of authors, etc. If you turn it off, you can still -see the counts by hovering your mouse over any item.</p> - - - Show &counts - - - - - - - Show an icon if the item has an attached note - - - Show &notes icons - - - true - - - - - - - Use &alternating row colors - - - - - - - <p>When checked, calibre will automatically hide any category -(a column, custom or standard) that has no items to show. For example, some -categories might not have values when using Virtual libraries. Checking this -box will cause these empty categories to be hidden.</p> - - - Hide empt&y categories (columns) - - - - - - - If checked the notes and links icons will be placed at the right, after -the count and in columns. If unchecked, the icons will be placed immediately after the text, -to the left of the count and not in columns. - - - Place icons on the &right, in columns - - - true - - - - - - - <p>When checked, Find in the Tag browser will show all items -that match the search instead of the first one. If Hide empty categories is -also checked then only categories containing a matched item will be shown.</p> - - - Find &shows all items that match - - - - - - - <p>Ensure the last "used" item in the Tag browser is visible when opening a library. -An item is "used" when it is expanded, collapsed, or clicked.</p> - - - Expand tr&ee to show last used item - - - - - - - - - - - <p>When checked, the Tag browser can get keyboard focus, allowing -use of the keyboard to navigate the tree using the arrow keys. The Enter key simulates -a click on the selected item. The keyboard shortcut 'Tag browser / -Give the Tag browser keyboard focus' changes the keyboard focus without -using the mouse.</p> - - - Allow the Tag browser to have keyboard &focus - - - - - - - margin-left: 1.5em - - - <p style="text-indent: 2em; font-size:smaller"> -If you enable this option then you should set a keyboard shortcut to -focus the Tag browser under -<code>Preferences-&gt;Shortcuts-&gt;Tag browser-&gt;Give -the Tag browser keyboard focus</code></p> - - - true - - - - - - - - - QFormLayout::ExpandingFieldsGrow - - - - - Spacing between &items: - - - opt_tag_browser_item_padding - - - - - - - <p>The spacing between consecutive items in the Tag browser. -In units of (ex) which is the approximate height of the letter 'x' in the -currently used font.</p> - - - ex - - - 1 - - - -1.000000000000000 - - - 2.000000000000000 - - - 0.100000000000000 - - - - - - - + &Partitioning and collapsing - - - - - - - QFormLayout::ExpandingFieldsGrow - - - - - &Category partitioning method: - - - opt_tags_browser_partition_method - - - - - - - <p>Choose how Tag browser subcategories are displayed when -there are more items than the limit. Select by first -letter to see an A, B, C list. Choose partitioned to -have a list of fixed-sized groups. Set to disabled -if you never want subcategories</p> - - - - - - - Combine letters &when fewer items than: - - - opt_tags_browser_collapse_fl_at - - - - - - - <p>If collapsing by first letter, combine adjacent letters together if -there are fewer items under a letter than specified here. If the partition method is -not set to first letter, this value is ignored. Set to zero to disable.</p> - - - 10000 - - - - - - - Co&llapse when more items than: - - - opt_tags_browser_collapse_at - - - - - - - <p>If a Tag browser category has more than this number of items, it is divided -up into subcategories. If the partition method is set to disable, this value is ignored.</p> - - - 10000 - - - - - - - - - <p>Check the box for categories that are to -be partitioned using the criteria above. Uncheck the box if you don't want to -partition a category even if the number of items is larger than -the value shown above. This option can be used to -avoid collapsing hierarchical categories that have only -a few top-level elements.</p> - - - Select categories to &partition: - - - tb_cats_to_partition - - - - - - - - 0 - 200 - - - - 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 for each one.</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 for each one.</p> - - - Export list - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - @@ -1800,7 +1328,7 @@ structure and you want to use the same for each one.</p> - + :/images/cover_flow.png:/images/cover_flow.png @@ -1808,13 +1336,8 @@ structure and you want to use the same for each one.</p> Cover &browser - - - - - - + :/images/quickview.png:/images/quickview.png @@ -1822,108 +1345,6 @@ structure and you want to use the same for each one.</p> &Quickview - - - - - - - <p>Check this box to make Quickview show books only in the -current Virtual library. If unchecked, Quickview ignores Virtual libraries. If -unchecked then only row changes are taken into account.</p> - - - &Apply Virtual libraries - - - - - - - <p>Check this box to make Quickview change the column being examined -when the column in the book list is changed using the cursor arrow keys</p> - - - &Change Quickview item when book list column changes - - - - - - - <p>Pressing Enter in a cell changes both the book and the -column being examined (the left-hand panel)</p> - - - &Pressing Enter changes the examined column - - - - - - - <p>Double-clicking in a cell changes both the book and the -column being examined (the left-hand panel)</p> - - - &Double click changes examined column - - - - - - - - - Select columns to display - - - - - - Move up. Keyboard shortcut: Ctrl-Up arrow - - - - :/images/arrow-up.png:/images/arrow-up.png - - - - - - - Move down. Keyboard shortcut: Ctrl-Down arrow - - - - :/images/arrow-down.png:/images/arrow-down.png - - - - - - - true - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - @@ -1961,6 +1382,16 @@ column being examined (the left-hand panel)</p> QWidget
calibre/gui2/preferences/look_feel.h
+ + TbDisplayTab + ConfigWidget +
calibre/gui2/preferences/look_feel_tabs.tb_display.h
+
+ + TbPartitioningTab + ConfigWidget +
calibre/gui2/preferences/look_feel_tabs.tb_partitioning.h
+
TbIconRulesTab ConfigWidget @@ -1976,6 +1407,11 @@ column being examined (the left-hand panel)</p> ConfigWidget
calibre/gui2/preferences/look_feel_tabs.cover_view.h
+ + QuickviewTab + ConfigWidget +
calibre/gui2/preferences/look_feel_tabs.tb_quickview.h
+
@@ -1997,21 +1433,5 @@ column being examined (the left-hand panel)</p> - - opt_tag_browser_allow_keyboard_focus - toggled(bool) - tb_focus_label - setVisible(bool) - - - 275 - 528 - - - 358 - 555 - - - diff --git a/src/calibre/gui2/preferences/look_feel_tabs/__init__.py b/src/calibre/gui2/preferences/look_feel_tabs/__init__.py index 6cae188d2a..7078cbb484 100644 --- a/src/calibre/gui2/preferences/look_feel_tabs/__init__.py +++ b/src/calibre/gui2/preferences/look_feel_tabs/__init__.py @@ -5,9 +5,17 @@ __license__ = 'GPL v3' __copyright__ = '2011, Kovid Goyal ' __docformat__ = 'restructuredtext en' +import json from qt.core import QAbstractListModel, QIcon, QItemSelectionModel, Qt +from calibre.gui2 import ( + choose_files, + choose_save_file, + config, + error_dialog, + gprefs, +) from calibre.gui2.book_details import get_field_list @@ -100,6 +108,36 @@ class DisplayedFields(QAbstractListModel): # {{{ self.changed = True return idx +def export_layout(in_widget, model=None): + filename = choose_save_file(in_widget, 'tb_display_import_export_field_list', + _('Save column list to file'), + filters=[(_('Column list'), ['json'])]) + if filename: + try: + with open(filename, 'w') as f: + json.dump(model.fields, f, indent=1) + except Exception as err: + error_dialog(in_widget, _('Export field layout'), + _('

Could not write field list. Error:
%s')%err, show=True) + +def import_layout(in_widget, model=None): + filename = choose_files(in_widget, 'tb_display_import_export_field_list', + _('Load column list from file'), + filters=[(_('Column list'), ['json'])]) + if filename: + try: + with open(filename[0]) as f: + fields = json.load(f) + model.initialize(pref_data_override=fields) + in_widget.changed_signal.emit() + except Exception as err: + error_dialog(in_widget, _('Import layout'), + _('

Could not read field list. Error:
%s')%err, show=True) + +def reset_layout(in_widget, model=None): + model.initialize(use_defaults=True) + in_widget.changed_signal.emit() + def move_field_up(widget, model): idx = widget.currentIndex() diff --git a/src/calibre/gui2/preferences/look_feel_tabs/cover_view.py b/src/calibre/gui2/preferences/look_feel_tabs/cover_view.py index 16e35bd010..de6090af6e 100644 --- a/src/calibre/gui2/preferences/look_feel_tabs/cover_view.py +++ b/src/calibre/gui2/preferences/look_feel_tabs/cover_view.py @@ -2,7 +2,7 @@ __license__ = 'GPL v3' -__copyright__ = '2010, Kovid Goyal ' +__copyright__ = '2025, Kovid Goyal ' __docformat__ = 'restructuredtext en' @@ -10,15 +10,15 @@ from qt.core import QKeySequence from calibre.gui2 import config, gprefs from calibre.gui2.dialogs.template_dialog import TemplateDialog -from calibre.gui2.preferences import ConfigTabWidget, ConfigWidgetBase, set_help_tips +from calibre.gui2.preferences import LazyConfigWidgetBase, ConfigWidgetBase, set_help_tips from calibre.gui2.preferences.look_feel_tabs.cover_view_ui import Ui_Form -class CoverView(ConfigTabWidget, Ui_Form): +class CoverView(LazyConfigWidgetBase, Ui_Form): def genesis(self, gui): self.gui = gui - db = gui.library_view.model().db + db = self.gui.library_view.model().db r = self.register r('books_autoscroll_time', gprefs) @@ -41,7 +41,7 @@ class CoverView(ConfigTabWidget, Ui_Form): self.fs_help_msg.setText(self.fs_help_msg.text()%( QKeySequence(QKeySequence.StandardKey.FullScreen).toString(QKeySequence.SequenceFormat.NativeText))) - def initialize(self): + def lazy_initialize(self): ConfigWidgetBase.initialize(self) set_help_tips(self.opt_cover_browser_narrow_view_position, _( 'This option controls the position of the cover browser when using the Narrow user ' @@ -56,6 +56,9 @@ class CoverView(ConfigTabWidget, Ui_Form): if t.exec(): self.opt_cover_browser_title_template.setText(t.rule[1]) + def commit(self): + return ConfigWidgetBase.commit(self) + def refresh_gui(self, gui): gui.cover_flow.setShowReflections(gprefs['cover_browser_reflections']) gui.cover_flow.setPreserveAspectRatio(gprefs['cb_preserve_aspect_ratio']) diff --git a/src/calibre/gui2/preferences/look_feel_tabs/tb_display.py b/src/calibre/gui2/preferences/look_feel_tabs/tb_display.py new file mode 100644 index 0000000000..cb14c74b21 --- /dev/null +++ b/src/calibre/gui2/preferences/look_feel_tabs/tb_display.py @@ -0,0 +1,118 @@ +#!/usr/bin/env python + + +__license__ = 'GPL v3' +__copyright__ = '2025, Kovid Goyal ' +__docformat__ = 'restructuredtext en' + +from functools import partial + +from calibre.db.categories import is_standard_category +from calibre.gui2 import config, gprefs +from calibre.gui2.preferences import ConfigWidgetBase, LazyConfigWidgetBase +from calibre.gui2.preferences.look_feel_tabs import ( + DisplayedFields, + import_layout, + export_layout, + move_field_down, + move_field_up, + reset_layout + ) +from calibre.gui2.preferences.look_feel_tabs.tb_display_ui import Ui_Form + +class TBDisplayedFields(DisplayedFields): # {{{ + # The code in this class depends on the fact that the tag browser is + # initialized before this class is instantiated. + + def __init__(self, db, parent=None, category_icons=None): + DisplayedFields.__init__(self, db, parent, category_icons=category_icons) + from calibre.gui2.ui import get_gui + self.gui = get_gui() + + def initialize(self, use_defaults=False, pref_data_override=None): + tv = self.gui.tags_view + cat_ord = tv.model().get_ordered_categories(use_defaults=use_defaults, + pref_data_override=pref_data_override) + if use_defaults: + hc = [] + self.changed = True + elif pref_data_override: + hc = [k for k,v in pref_data_override if not v] + self.changed = True + else: + hc = tv.hidden_categories + + self.beginResetModel() + self.fields = [[x, x not in hc] for x in cat_ord] + self.endResetModel() + + def commit(self): + if self.changed: + self.db.prefs.set('tag_browser_hidden_categories', [k for k,v in self.fields if not v]) + self.db.prefs.set('tag_browser_category_order', [k for k,v in self.fields]) +# }}} + + +class TbDisplayTab(LazyConfigWidgetBase, Ui_Form): + + def genesis(self, gui): + self.gui = gui + r = self.register + r('tag_browser_old_look', gprefs) + r('tag_browser_hide_empty_categories', gprefs) + r('tag_browser_always_autocollapse', gprefs) + r('tag_browser_restore_tree_expansion', gprefs) + r('tag_browser_show_tooltips', gprefs) + r('tag_browser_allow_keyboard_focus', gprefs) + r('tag_browser_show_counts', gprefs) + r('tag_browser_item_padding', gprefs) + r('show_avg_rating', config) + r('show_links_in_tag_browser', gprefs) + r('show_notes_in_tag_browser', gprefs) + r('icons_on_right_in_tag_browser', gprefs) + + self.tb_display_model = TBDisplayedFields(self.gui.current_db, self.tb_display_order, + category_icons=self.gui.tags_view.model().category_custom_icons) + self.tb_display_model.dataChanged.connect(self.changed_signal) + self.tb_display_order.setModel(self.tb_display_model) + self.tb_reset_layout_button.clicked.connect(partial(reset_layout, self, model=self.tb_display_model)) + self.tb_export_layout_button.clicked.connect(partial(export_layout, self, model=self.tb_display_model)) + self.tb_import_layout_button.clicked.connect(partial(import_layout, self, model=self.tb_display_model)) + self.tb_up_button.clicked.connect(self.tb_up_button_clicked) + self.tb_down_button.clicked.connect(self.tb_down_button_clicked) + self.tb_display_order.set_movement_functions(self.tb_up_button_clicked, self.tb_down_button_clicked) + + def lazy_initialize(self): + self.tb_display_model.initialize() + self.tb_focus_label.setVisible(self.opt_tag_browser_allow_keyboard_focus.isChecked()) + + def tb_down_button_clicked(self): + idx = self.tb_display_order.currentIndex() + if idx.isValid(): + row = idx.row() + model = self.tb_display_model + fields = model.fields + key = fields[row][0] + if not is_standard_category(key): + return + if row < len(fields) and is_standard_category(fields[row+1][0]): + move_field_down(self.tb_display_order, model) + + def tb_up_button_clicked(self): + idx = self.tb_display_order.currentIndex() + if idx.isValid(): + row = idx.row() + model = self.tb_display_model + fields = model.fields + key = fields[row][0] + if not is_standard_category(key): + return + move_field_up(self.tb_display_order, model) + + def restore_defaults(self): + ConfigWidgetBase.restore_defaults(self) + self.display_model.restore_defaults() + + def commit(self): + self.tb_display_model.commit() + return ConfigWidgetBase.commit(self) diff --git a/src/calibre/gui2/preferences/look_feel_tabs/tb_display.ui b/src/calibre/gui2/preferences/look_feel_tabs/tb_display.ui new file mode 100644 index 0000000000..893b1f93bb --- /dev/null +++ b/src/calibre/gui2/preferences/look_feel_tabs/tb_display.ui @@ -0,0 +1,360 @@ + + + Form + + + + 0 + 0 + 1096 + 791 + + + + Form + + + + + + User categories and Saved searches cannot be moved + + + Select the categories to display in the Tag browser, and their &order + + + tb_display_order + + + + + + + + 0 + 200 + + + + true + + + + + + + Move up. User categories and Saved searches cannot be moved. Keyboard shortcut: Ctrl-Up arrow + + + + :/images/arrow-up.png:/images/arrow-up.png + + + + + + + Qt::Vertical + + + + 50 + 40 + + + + + + + + Move down. User categories and Saved searches cannot be moved. Keyboard shortcut: Ctrl-Down arrow + + + + :/images/arrow-down.png:/images/arrow-down.png + + + + + + + + + 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 + + + + + + + + + + + + Show the average rating per item indication in the Tag browser + + + Show &average ratings + + + true + + + + + + + Show an icon if the item has an attached link + + + Show &links icons + + + true + + + + + + + Show &tooltips + + + + + + + <p>Show counts for items in the Tag browser. Such as the number of books +by each author, the number of authors, etc. If you turn it off, you can still +see the counts by hovering your mouse over any item.</p> + + + Show &counts + + + + + + + Show an icon if the item has an attached note + + + Show &notes icons + + + true + + + + + + + Use &alternating row colors + + + + + + + <p>When checked, calibre will automatically hide any category +(a column, custom or standard) that has no items to show. For example, some +categories might not have values when using Virtual libraries. Checking this +box will cause these empty categories to be hidden.</p> + + + Hide empt&y categories (columns) + + + + + + + If checked the notes and links icons will be placed at the right, after +the count and in columns. If unchecked, the icons will be placed immediately after the text, +to the left of the count and not in columns. + + + Place icons on the &right, in columns + + + true + + + + + + + <p>When checked, Find in the Tag browser will show all items +that match the search instead of the first one. If Hide empty categories is +also checked then only categories containing a matched item will be shown.</p> + + + Find &shows all items that match + + + + + + + <p>Ensure the last "used" item in the Tag browser is visible when opening a library. +An item is "used" when it is expanded, collapsed, or clicked.</p> + + + Expand tr&ee to show last used item + + + + + + + + + + + <p>When checked, the Tag browser can get keyboard focus, allowing +use of the keyboard to navigate the tree using the arrow keys. The Enter key simulates +a click on the selected item. The keyboard shortcut 'Tag browser / +Give the Tag browser keyboard focus' changes the keyboard focus without +using the mouse.</p> + + + Allow the Tag browser to have keyboard &focus + + + + + + + margin-left: 1.5em + + + <p style="text-indent: 2em; font-size:smaller"> +If you enable this option then you should set a keyboard shortcut to +focus the Tag browser under +<code>Preferences-&gt;Shortcuts-&gt;Tag browser-&gt;Give +the Tag browser keyboard focus</code></p> + + + true + + + + + + + + + QFormLayout::ExpandingFieldsGrow + + + + + Spacing between &items: + + + opt_tag_browser_item_padding + + + + + + + <p>The spacing between consecutive items in the Tag browser. +In units of (ex) which is the approximate height of the letter 'x' in the +currently used font.</p> + + + ex + + + 1 + + + -1.000000000000000 + + + 2.000000000000000 + + + 0.100000000000000 + + + + + + + + + + ListViewWithMoveByKeyPress + QListView +

calibre/gui2/preferences.h
+ + + ListWidgetWithMoveByKeyPress + QListWidget +
calibre/gui2/preferences.h
+
+ + + + opt_tag_browser_allow_keyboard_focus + toggled(bool) + tb_focus_label + setVisible(bool) + + + 275 + 528 + + + 358 + 555 + + + + + diff --git a/src/calibre/gui2/preferences/look_feel_tabs/tb_icon_rules.py b/src/calibre/gui2/preferences/look_feel_tabs/tb_icon_rules.py index 5b9f7bed85..f8b836172c 100644 --- a/src/calibre/gui2/preferences/look_feel_tabs/tb_icon_rules.py +++ b/src/calibre/gui2/preferences/look_feel_tabs/tb_icon_rules.py @@ -2,7 +2,7 @@ __license__ = 'GPL v3' -__copyright__ = '2010, Kovid Goyal ' +__copyright__ = '2025, Kovid Goyal ' __docformat__ = 'restructuredtext en' import copy @@ -14,7 +14,7 @@ from qt.core import QAbstractItemView, QApplication, QIcon, QMenu, Qt, QTableWid from calibre.constants import config_dir from calibre.db.constants import TEMPLATE_ICON_INDICATOR from calibre.gui2 import gprefs -from calibre.gui2.preferences import ConfigTabWidget, ConfigWidgetBase +from calibre.gui2.preferences import ConfigWidgetBase, LazyConfigWidgetBase from calibre.gui2.preferences.look_feel_tabs.tb_icon_rules_ui import Ui_Form DELETED_COLUMN = 0 @@ -98,7 +98,7 @@ class ChildrenTableWidgetItem(QTableWidgetItem): self.setIcon(QIcon.cached_icon(icon)) -class TbIconRulesTab(ConfigTabWidget, Ui_Form): +class TbIconRulesTab(LazyConfigWidgetBase, Ui_Form): def genesis(self, gui): self.gui = gui @@ -147,7 +147,7 @@ class TbIconRulesTab(ConfigTabWidget, Ui_Form): except Exception: pass - def lazy_populate_content(self): + def lazy_initialize(self): field_metadata = self.gui.current_db.field_metadata category_icons = self.gui.tags_view.model().category_custom_icons v = gprefs['tags_browser_value_icons'] @@ -256,7 +256,6 @@ class TbIconRulesTab(ConfigTabWidget, Ui_Form): self.rules_table.sortByColumn(FOR_CHILDREN_COLUMN, Qt.SortOrder(self.for_children_order)) def commit(self): - rr = ConfigWidgetBase.commit(self) v = copy.deepcopy(gprefs['tags_browser_value_icons']) for r in range(self.rules_table.rowCount()): cat_item = self.rules_table.item(r, CATEGORY_COLUMN) @@ -275,4 +274,4 @@ class TbIconRulesTab(ConfigTabWidget, Ui_Form): if len(v[category]) == 0: v.pop(category, None) gprefs['tags_browser_value_icons'] = v - return rr + return ConfigWidgetBase.commit(self) diff --git a/src/calibre/gui2/preferences/look_feel_tabs/tb_partitioning.py b/src/calibre/gui2/preferences/look_feel_tabs/tb_partitioning.py new file mode 100644 index 0000000000..73a3691b3b --- /dev/null +++ b/src/calibre/gui2/preferences/look_feel_tabs/tb_partitioning.py @@ -0,0 +1,98 @@ +#!/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.preferences import ConfigWidgetBase, LazyConfigWidgetBase +from calibre.gui2.preferences.look_feel_tabs import DisplayedFields, export_layout, import_layout, reset_layout +from calibre.gui2.preferences.look_feel_tabs.tb_partitioning_ui import Ui_Form + + +class TBPartitionedFields(DisplayedFields): # {{{ + # The code in this class depends on the fact that the tag browser is + # initialized before this class is instantiated. + + def __init__(self, db, parent=None, category_icons=None): + DisplayedFields.__init__(self, db, parent, category_icons=category_icons) + from calibre.gui2.ui import get_gui + self.gui = get_gui() + + def filter_user_categories(self, tv): + cats = tv.model().categories + answer = {} + filtered = set() + for key,name in cats.items(): + if key.startswith('@'): + key = key.partition('.')[0] + name = key[1:] + if key not in filtered: + answer[key] = name + filtered.add(key) + return answer + + def initialize(self, use_defaults=False, pref_data_override=None): + tv = self.gui.tags_view + cats = self.filter_user_categories(tv) + ans = [] + if use_defaults: + ans = [[k, True] for k in cats.keys()] + self.changed = True + elif pref_data_override: + po = {k:v for k,v in pref_data_override} + ans = [[k, po.get(k, True)] for k in cats.keys()] + self.changed = True + else: + # Check if setting not migrated yet + cats_to_partition = frozenset(self.db.prefs.get('tag_browser_dont_collapse', gprefs.get('tag_browser_dont_collapse')) or ()) + for key in cats: + ans.append([key, key not in cats_to_partition]) + self.beginResetModel() + self.fields = ans + self.endResetModel() + + def commit(self): + if self.changed: + # Migrate to a per-library setting + self.db.prefs.set('tag_browser_dont_collapse', [k for k,v in self.fields if not v]) +# }}} + + +class TbPartitioningTab(LazyConfigWidgetBase, Ui_Form): + + def genesis(self, gui): + self.gui = gui + r = self.register + + choices = [(_('Disabled'), 'disable'), (_('By first letter'), 'first letter'), + (_('Partitioned'), 'partition')] + r('tags_browser_partition_method', gprefs, choices=choices) + r('tags_browser_collapse_at', gprefs) + r('tags_browser_collapse_fl_at', gprefs) + + self.tb_categories_to_part_model = TBPartitionedFields(self.gui.current_db, + self.tb_cats_to_partition, + category_icons=self.gui.tags_view.model().category_custom_icons) + self.tb_categories_to_part_model.dataChanged.connect(self.changed_signal) + self.tb_cats_to_partition.setModel(self.tb_categories_to_part_model) + self.tb_partition_reset_button.clicked.connect(partial(reset_layout, self, + model=self.tb_categories_to_part_model)) + self.tb_partition_export_layout_button.clicked.connect(partial(export_layout, self, + model=self.tb_categories_to_part_model)) + self.tb_partition_import_layout_button.clicked.connect(partial(import_layout, self, + model=self.tb_categories_to_part_model)) + + def lazy_initialize(self): + self.tb_categories_to_part_model.initialize() + + def commit(self): + self.tb_categories_to_part_model.commit() + return ConfigWidgetBase.commit(self) + + + diff --git a/src/calibre/gui2/preferences/look_feel_tabs/tb_partitioning.ui b/src/calibre/gui2/preferences/look_feel_tabs/tb_partitioning.ui new file mode 100644 index 0000000000..e93be6e29c --- /dev/null +++ b/src/calibre/gui2/preferences/look_feel_tabs/tb_partitioning.ui @@ -0,0 +1,176 @@ + + + Form + + + + 0 + 0 + 1035 + 547 + + + + Form + + + + + + + + QFormLayout::ExpandingFieldsGrow + + + + + &Category partitioning method: + + + opt_tags_browser_partition_method + + + + + + + <p>Choose how Tag browser subcategories are displayed when +there are more items than the limit. Select by first +letter to see an A, B, C list. Choose partitioned to +have a list of fixed-sized groups. Set to disabled +if you never want subcategories</p> + + + + + + + Combine letters &when fewer items than: + + + opt_tags_browser_collapse_fl_at + + + + + + + <p>If collapsing by first letter, combine adjacent letters together if +there are fewer items under a letter than specified here. If the partition method is +not set to first letter, this value is ignored. Set to zero to disable.</p> + + + 10000 + + + + + + + Co&llapse when more items than: + + + opt_tags_browser_collapse_at + + + + + + + <p>If a Tag browser category has more than this number of items, it is divided +up into subcategories. If the partition method is set to disable, this value is ignored.</p> + + + 10000 + + + + + + + + + <p>Check the box for categories that are to +be partitioned using the criteria above. Uncheck the box if you don't want to +partition a category even if the number of items is larger than +the value shown above. This option can be used to +avoid collapsing hierarchical categories that have only +a few top-level elements.</p> + + + Select categories to &partition: + + + tb_cats_to_partition + + + + + + + + 0 + 200 + + + + 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 for each one.</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 for each one.</p> + + + Export list + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + \ No newline at end of file diff --git a/src/calibre/gui2/preferences/look_feel_tabs/tb_quickview.py b/src/calibre/gui2/preferences/look_feel_tabs/tb_quickview.py new file mode 100644 index 0000000000..17dc7f4f03 --- /dev/null +++ b/src/calibre/gui2/preferences/look_feel_tabs/tb_quickview.py @@ -0,0 +1,74 @@ +#!/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.actions.show_quickview import get_quickview_action_plugin +from calibre.gui2.dialogs.quickview import get_qv_field_list +from calibre.gui2.preferences import LazyConfigWidgetBase, ConfigWidgetBase +from calibre.gui2.preferences.look_feel_tabs import DisplayedFields, move_field_down, move_field_up +from calibre.gui2.preferences.look_feel_tabs.tb_quickview_ui import Ui_Form + +class QVDisplayedFields(DisplayedFields): # {{{ + + def __init__(self, db, parent=None): + DisplayedFields.__init__(self, db, parent) + + def initialize(self, use_defaults=False): + self.beginResetModel() + self.fields = [[x[0], x[1]] for x in + get_qv_field_list(self.db.field_metadata, use_defaults=use_defaults)] + self.endResetModel() + self.changed = True + + def commit(self): + if self.changed: + self.db.new_api.set_pref('qv_display_fields', self.fields) + +# }}} + + +class QuickviewTab(LazyConfigWidgetBase, Ui_Form): + + def genesis(self, gui): + self.gui = gui + r = self.register + + r('qv_respects_vls', gprefs) + r('qv_dclick_changes_column', gprefs) + r('qv_retkey_changes_column', gprefs) + r('qv_follows_column', gprefs) + + self.qv_display_model = QVDisplayedFields(self.gui.current_db, self.qv_display_order) + self.qv_display_model.dataChanged.connect(self.changed_signal) + self.qv_display_order.setModel(self.qv_display_model) + + mu = partial(move_field_up, self.qv_display_order, self.qv_display_model) + md = partial(move_field_down, self.qv_display_order, self.qv_display_model) + self.qv_display_order.set_movement_functions(mu, md) + self.qv_up_button.clicked.connect(mu) + self.qv_down_button.clicked.connect(md) + + def lazy_initialize(self): + self.qv_display_model.initialize() + + def restore_defaults(self): + ConfigWidgetBase.restore_defaults(self) + self.qv_display_model.restore_defaults() + + def refresh_gui(self, gui): + qv = get_quickview_action_plugin() + if qv: + qv.refill_quickview() + + def commit(self, *args): + rr = ConfigWidgetBase.commit(self, *args) + self.qv_display_model.commit() + return rr + + diff --git a/src/calibre/gui2/preferences/look_feel_tabs/tb_quickview.ui b/src/calibre/gui2/preferences/look_feel_tabs/tb_quickview.ui new file mode 100644 index 0000000000..cf4a3174ec --- /dev/null +++ b/src/calibre/gui2/preferences/look_feel_tabs/tb_quickview.ui @@ -0,0 +1,125 @@ + + + Form + + + + :/images/cover_flow.png:/images/cover_flow.png + + + + + + + + <p>Check this box to make Quickview show books only in the +current Virtual library. If unchecked, Quickview ignores Virtual libraries. If +unchecked then only row changes are taken into account.</p> + + + &Apply Virtual libraries + + + + + + + <p>Check this box to make Quickview change the column being examined +when the column in the book list is changed using the cursor arrow keys</p> + + + &Change Quickview item when book list column changes + + + + + + + <p>Pressing Enter in a cell changes both the book and the +column being examined (the left-hand panel)</p> + + + &Pressing Enter changes the examined column + + + + + + + <p>Double-clicking in a cell changes both the book and the +column being examined (the left-hand panel)</p> + + + &Double click changes examined column + + + + + + + + + Select columns to display + + + + + + Move up. Keyboard shortcut: Ctrl-Up arrow + + + + :/images/arrow-up.png:/images/arrow-up.png + + + + + + + Move down. Keyboard shortcut: Ctrl-Down arrow + + + + :/images/arrow-down.png:/images/arrow-down.png + + + + + + + true + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + ListViewWithMoveByKeyPress + QListView +
calibre/gui2/preferences.h
+
+ + ListWidgetWithMoveByKeyPress + QListWidget +
calibre/gui2/preferences.h
+
+
+ +
\ No newline at end of file