Merge branch 'lazy-operations-look_feel' of https://github.com/un-pogaz/calibre

This commit is contained in:
Kovid Goyal 2025-01-23 19:05:41 +05:30
commit d8168dd59c
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 29 additions and 7 deletions

View File

@ -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)
@ -854,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)
@ -863,9 +873,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

View File

@ -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: