From 2c68207773691ff0dd8f442fa4c4471d4adb5598 Mon Sep 17 00:00:00 2001 From: un-pogaz <46523284+un-pogaz@users.noreply.github.com> Date: Wed, 29 Jan 2025 22:24:15 +0100 Subject: [PATCH 1/4] add a note in the ui about the icon value rules --- src/calibre/gui2/preferences/look_feel_tabs/tb_icon_rules.ui | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/calibre/gui2/preferences/look_feel_tabs/tb_icon_rules.ui b/src/calibre/gui2/preferences/look_feel_tabs/tb_icon_rules.ui index 7b1426cf2d..edee294faf 100644 --- a/src/calibre/gui2/preferences/look_feel_tabs/tb_icon_rules.ui +++ b/src/calibre/gui2/preferences/look_feel_tabs/tb_icon_rules.ui @@ -43,7 +43,8 @@ <p>View all the defined value icon rules, including template rules. Rules are defined and edited in the Tag browser context menus. Rules can be deleted in -this dialog using the button, the delete key, or the context menu.</p> +this dialog using the button, the delete key, or the context menu. The icon value rules +are defined per-user, not per-library.</p> true From 01610583cf837525402cdb1c1744d3eb5405d4c0 Mon Sep 17 00:00:00 2001 From: un-pogaz <46523284+un-pogaz@users.noreply.github.com> Date: Wed, 29 Jan 2025 22:55:50 +0100 Subject: [PATCH 2/4] add option to show only category in current library --- .../look_feel_tabs/tb_icon_rules.py | 27 ++++++++++++++----- .../look_feel_tabs/tb_icon_rules.ui | 11 ++++++-- 2 files changed, 29 insertions(+), 9 deletions(-) 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 2ca8a27263..ce4b69ad2d 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 @@ -288,6 +288,8 @@ class TbIconRulesTab(LazyConfigWidgetBase, Ui_Form): r('tag_browser_show_category_icons', gprefs) r('tag_browser_show_value_icons', gprefs) + self.show_only_current_library.setChecked(gprefs.get('tag_browser_rules_show_only_current_library', False)) + self.rules_table.setSelectionBehavior(QAbstractItemView.SelectionBehavior.SelectItems) self.rules_table.setColumnCount(HEADER_SECTION_COUNT) self.rules_table.setHorizontalHeaderLabels(('', _('Category'), _('Value'), '', @@ -330,6 +332,7 @@ class TbIconRulesTab(LazyConfigWidgetBase, Ui_Form): self.delete_button.clicked.connect(self.delete_rule) self.edit_button.clicked.connect(self.edit_column) self.undo_button.clicked.connect(self.undo_changes) + self.show_only_current_library.stateChanged.connect(self.change_filter_library) self.tb_icon_rules_groupbox.setContentsMargins(0, 0, 0, 0) self.tb_icon_rules_gridlayout.setContentsMargins(2, 2, 2, 2) @@ -340,19 +343,28 @@ class TbIconRulesTab(LazyConfigWidgetBase, Ui_Form): pass def lazy_initialize(self): + self.rules_table.setItemDelegateForColumn(ICON_COLUMN, IconColumnDelegate(self, self.rules_table, self.changed_signal)) + self.rules_table.setItemDelegateForColumn(FOR_CHILDREN_COLUMN, + ChildrenColumnDelegate(self, self.rules_table, self.changed_signal)) + self.populate_content() + self.section_order = [0, 1, 1, 0, 0, 0, 0] + self.do_sort(VALUE_COLUMN) + self.do_sort(CATEGORY_COLUMN) + + def populate_content(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'] row = 0 t = self.rules_table - t.setItemDelegateForColumn(ICON_COLUMN, IconColumnDelegate(self, self.rules_table, self.changed_signal)) - t.setItemDelegateForColumn(FOR_CHILDREN_COLUMN, - ChildrenColumnDelegate(self, self.rules_table, self.changed_signal)) + t.clearContents() for category,vdict in v.items(): if category in field_metadata: display_name = field_metadata[category]['name'] + elif self.show_only_current_library.isChecked(): + continue else: display_name = category.removeprefix('#') for item_value in vdict: @@ -369,10 +381,6 @@ class TbIconRulesTab(LazyConfigWidgetBase, Ui_Form): t.setItem(row, FOR_CHILDREN_COLUMN, item) row += 1 - self.section_order = [0, 1, 1, 0, 0, 0, 0] - self.do_sort(VALUE_COLUMN) - self.do_sort(CATEGORY_COLUMN) - def show_context_menu(self, point): item = self.rules_table.itemAt(point) if item is None: @@ -416,6 +424,10 @@ class TbIconRulesTab(LazyConfigWidgetBase, Ui_Form): return return super().keyPressEvent(ev) + def change_filter_library(self, state): + gprefs['tag_browser_rules_show_only_current_library'] = self.show_only_current_library.isChecked() + self.populate_content() + def undo_changes(self): idx = self.rules_table.currentIndex() if idx.isValid(): @@ -484,6 +496,7 @@ class TbIconRulesTab(LazyConfigWidgetBase, Ui_Form): else: self.rules_table.setColumnWidth(c, w) self.table_column_widths.append(self.rules_table.columnWidth(c)) + gprefs['tag_browser_rules_dialog_table_widths'] = self.table_column_widths def do_sort(self, section): diff --git a/src/calibre/gui2/preferences/look_feel_tabs/tb_icon_rules.ui b/src/calibre/gui2/preferences/look_feel_tabs/tb_icon_rules.ui index edee294faf..5b90a59e08 100644 --- a/src/calibre/gui2/preferences/look_feel_tabs/tb_icon_rules.ui +++ b/src/calibre/gui2/preferences/look_feel_tabs/tb_icon_rules.ui @@ -51,10 +51,17 @@ are defined per-user, not per-library.</p> - + + + + Show only category available in the current library + + + + - + From 9a20755d70202dc25162531a6a77aaea8885c1de Mon Sep 17 00:00:00 2001 From: un-pogaz <46523284+un-pogaz@users.noreply.github.com> Date: Wed, 29 Jan 2025 23:42:34 +0100 Subject: [PATCH 3/4] extend to filter also the values --- .../gui2/preferences/look_feel_tabs/tb_icon_rules.py | 7 ++++++- .../gui2/preferences/look_feel_tabs/tb_icon_rules.ui | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) 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 ce4b69ad2d..72631a4335 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 @@ -354,6 +354,7 @@ class TbIconRulesTab(LazyConfigWidgetBase, Ui_Form): def populate_content(self): field_metadata = self.gui.current_db.field_metadata category_icons = self.gui.tags_view.model().category_custom_icons + only_current_library = self.show_only_current_library.isChecked() v = gprefs['tags_browser_value_icons'] row = 0 @@ -363,11 +364,15 @@ class TbIconRulesTab(LazyConfigWidgetBase, Ui_Form): for category,vdict in v.items(): if category in field_metadata: display_name = field_metadata[category]['name'] - elif self.show_only_current_library.isChecked(): + all_values = self.gui.current_db.new_api.all_field_names(category) + elif only_current_library: continue else: display_name = category.removeprefix('#') + all_values = () for item_value in vdict: + if only_current_library and item_value != TEMPLATE_ICON_INDICATOR and item_value not in all_values: + continue t.setRowCount(row + 1) d = v[category][item_value] t.setItem(row, DELETED_COLUMN, StateTableWidgetItem('')) diff --git a/src/calibre/gui2/preferences/look_feel_tabs/tb_icon_rules.ui b/src/calibre/gui2/preferences/look_feel_tabs/tb_icon_rules.ui index 5b90a59e08..b247b37205 100644 --- a/src/calibre/gui2/preferences/look_feel_tabs/tb_icon_rules.ui +++ b/src/calibre/gui2/preferences/look_feel_tabs/tb_icon_rules.ui @@ -54,7 +54,7 @@ are defined per-user, not per-library.</p> - Show only category available in the current library + Show only categories and values available in the current library From 80afeac3218b37a25efbecc99fc0b07bb5e1b3e6 Mon Sep 17 00:00:00 2001 From: un-pogaz <46523284+un-pogaz@users.noreply.github.com> Date: Wed, 29 Jan 2025 23:52:51 +0100 Subject: [PATCH 4/4] reapply sort after filter library change --- src/calibre/gui2/preferences/look_feel_tabs/tb_icon_rules.py | 3 +++ 1 file changed, 3 insertions(+) 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 72631a4335..4e16173e1d 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 @@ -348,6 +348,7 @@ class TbIconRulesTab(LazyConfigWidgetBase, Ui_Form): ChildrenColumnDelegate(self, self.rules_table, self.changed_signal)) self.populate_content() self.section_order = [0, 1, 1, 0, 0, 0, 0] + self.last_section_sorted = 0 self.do_sort(VALUE_COLUMN) self.do_sort(CATEGORY_COLUMN) @@ -432,6 +433,7 @@ class TbIconRulesTab(LazyConfigWidgetBase, Ui_Form): def change_filter_library(self, state): gprefs['tag_browser_rules_show_only_current_library'] = self.show_only_current_library.isChecked() self.populate_content() + self.rules_table.sortByColumn(self.last_section_sorted, Qt.SortOrder(self.section_order[self.last_section_sorted])) def undo_changes(self): idx = self.rules_table.currentIndex() @@ -507,6 +509,7 @@ class TbIconRulesTab(LazyConfigWidgetBase, Ui_Form): def do_sort(self, section): order = 1 - self.section_order[section] self.section_order[section] = order + self.last_section_sorted = section self.rules_table.sortByColumn(section, Qt.SortOrder(order)) def commit(self):