From 6f84e54bd3ec7762ae210a29f5f885e8a848f5c1 Mon Sep 17 00:00:00 2001 From: un-pogaz <46523284+un-pogaz@users.noreply.github.com> Date: Thu, 23 Jan 2025 13:20:59 +0100 Subject: [PATCH 1/2] implement lazy operations for "Look & feel" --- src/calibre/gui2/preferences/look_feel.py | 20 +++++++++++++++++++ .../look_feel_tabs/tb_icon_rules.py | 15 +++++++------- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/calibre/gui2/preferences/look_feel.py b/src/calibre/gui2/preferences/look_feel.py index c7e327eaa5..d6624c2c24 100644 --- a/src/calibre/gui2/preferences/look_feel.py +++ b/src/calibre/gui2/preferences/look_feel.py @@ -36,6 +36,7 @@ from qt.core import ( Qt, QTableWidget, QTableWidgetItem, + QTabWidget, QVBoxLayout, QWidget, pyqtSignal, @@ -692,8 +693,16 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form): self.css_highlighter = get_highlighter('css')() self.css_highlighter.apply_theme(get_theme(None)) self.css_highlighter.set_document(self.opt_book_details_css.document()) + self.lazy_tabs = {} for i in range(self.tabWidget.count()): self.sections_view.addItem(QListWidgetItem(self.tabWidget.tabIcon(i), self.tabWidget.tabText(i).replace('&', ''))) + # retrieve tabs and subtabs of look & feel to load their content later when clicking of them + w = self.tabWidget.widget(i).widget() + self.lazy_tabs[(i, None)] = w + if isinstance(w, QTabWidget): + w.currentChanged.connect(partial(self.lazy_tab_operations, i)) + for ii in range(w.count()): + self.lazy_tabs[(i, ii)] = w.widget(ii) self.sections_view.setCurrentRow(self.tabWidget.currentIndex()) self.sections_view.currentRowChanged.connect(self.tabWidget.setCurrentIndex) self.sections_view.setMaximumWidth(self.sections_view.sizeHintForColumn(0) + 16) @@ -863,9 +872,20 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form): _('Current space used: %s') % human_readable(size)) def tab_changed(self, index): + self.lazy_tab_operations(index, None) if self.tabWidget.currentWidget() is self.cover_grid_tab: self.show_current_cache_usage() + def lazy_tab_operations(self, idx_section, idx_subtab): + ''' + Check if the tab has lazy operations. + Perfom the lazy operations only once, the first time the tab is selected. + ''' + tab = self.lazy_tabs.get((idx_section, idx_subtab), None) + if hasattr(tab, 'lazy_populate_content'): + tab.lazy_populate_content() + self.lazy_tabs.pop((idx_section, idx_subtab), None) + def show_current_cache_usage(self): t = Thread(target=self.calc_cache_size) t.daemon = True 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 431b13bfc7..23f57dffa8 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 @@ -141,8 +141,14 @@ class TbIconRulesTab(ConfigTabWidget, Ui_Form): self.tb_icon_rules_groupbox.setContentsMargins(0, 0, 0, 0) self.tb_icon_rules_gridlayout.setContentsMargins(2, 2, 2, 2) - field_metadata = gui.current_db.field_metadata - category_icons = gui.tags_view.model().category_custom_icons + try: + self.table_column_widths = gprefs.get('tag_browser_rules_dialog_table_widths', None) + except Exception: + pass + + def lazy_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 for category,vdict in v.items(): @@ -170,11 +176,6 @@ class TbIconRulesTab(ConfigTabWidget, Ui_Form): self.do_sort(VALUE_COLUMN) self.do_sort(CATEGORY_COLUMN) - try: - self.table_column_widths = gprefs.get('tag_browser_rules_dialog_table_widths', None) - except Exception: - pass - def show_context_menu(self, point): clicked_item = self.rules_table.itemAt(point) if clicked_item is None: From f3e5d970d3ea36023059b86c8417512d70f23d21 Mon Sep 17 00:00:00 2001 From: un-pogaz <46523284+un-pogaz@users.noreply.github.com> Date: Thu, 23 Jan 2025 14:22:06 +0100 Subject: [PATCH 2/2] perfom lazy operations for first selected section --- src/calibre/gui2/preferences/look_feel.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/calibre/gui2/preferences/look_feel.py b/src/calibre/gui2/preferences/look_feel.py index d6624c2c24..b524f8fc16 100644 --- a/src/calibre/gui2/preferences/look_feel.py +++ b/src/calibre/gui2/preferences/look_feel.py @@ -863,6 +863,7 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form): self.tb_focus_label.setVisible(self.opt_tag_browser_allow_keyboard_focus.isChecked()) self.update_color_palette_state() self.opt_gui_layout.setCurrentIndex(0 if self.gui.layout_container.is_wide else 1) + self.lazy_tab_operations(self.tabWidget.currentIndex(), None) def open_cg_cache(self): open_local_file(self.gui.grid_view.thumbnail_cache.location)