mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Delay load category defs
This commit is contained in:
parent
d5b879cee6
commit
c9a7b68532
@ -7,7 +7,7 @@ import posixpath
|
|||||||
import sys
|
import sys
|
||||||
import textwrap
|
import textwrap
|
||||||
from collections import Counter, OrderedDict, defaultdict
|
from collections import Counter, OrderedDict, defaultdict
|
||||||
from functools import partial
|
from functools import partial, lru_cache
|
||||||
from gettext import pgettext
|
from gettext import pgettext
|
||||||
from qt.core import (
|
from qt.core import (
|
||||||
QAbstractItemView, QApplication, QCheckBox, QDialog, QDialogButtonBox, QFont,
|
QAbstractItemView, QApplication, QCheckBox, QDialog, QDialogButtonBox, QFont,
|
||||||
@ -50,7 +50,10 @@ LINEAR_ROLE = CATEGORY_ROLE + 1
|
|||||||
MIME_ROLE = LINEAR_ROLE + 1
|
MIME_ROLE = LINEAR_ROLE + 1
|
||||||
NBSP = '\xa0'
|
NBSP = '\xa0'
|
||||||
|
|
||||||
CATEGORIES = (
|
|
||||||
|
@lru_cache(maxsize=2)
|
||||||
|
def category_defs():
|
||||||
|
return (
|
||||||
('text', _('Text'), _('Chapter-')),
|
('text', _('Text'), _('Chapter-')),
|
||||||
('styles', _('Styles'), _('Style-')),
|
('styles', _('Styles'), _('Style-')),
|
||||||
('images', _('Images'), _('Image-')),
|
('images', _('Images'), _('Image-')),
|
||||||
@ -83,7 +86,7 @@ def get_bulk_rename_settings(parent, number, msg=None, sanitize=sanitize_file_na
|
|||||||
d.l = l = QFormLayout(d)
|
d.l = l = QFormLayout(d)
|
||||||
d.setLayout(l)
|
d.setLayout(l)
|
||||||
d.prefix = p = QLineEdit(d)
|
d.prefix = p = QLineEdit(d)
|
||||||
default_prefix = {k:v for k, __, v in CATEGORIES}.get(category, _('Chapter-'))
|
default_prefix = {k:v for k, __, v in category_defs()}.get(category, _('Chapter-'))
|
||||||
previous = tprefs.get('file-list-bulk-rename-prefix', {})
|
previous = tprefs.get('file-list-bulk-rename-prefix', {})
|
||||||
prefix = prefix or previous.get(category, default_prefix)
|
prefix = prefix or previous.get(category, default_prefix)
|
||||||
p.setText(prefix)
|
p.setText(prefix)
|
||||||
@ -430,7 +433,7 @@ class FileList(QTreeWidget, OpenWithHandler):
|
|||||||
self.root = self.invisibleRootItem()
|
self.root = self.invisibleRootItem()
|
||||||
self.root.setFlags(Qt.ItemFlag.ItemIsDragEnabled)
|
self.root.setFlags(Qt.ItemFlag.ItemIsDragEnabled)
|
||||||
self.categories = {}
|
self.categories = {}
|
||||||
for category, text, __ in CATEGORIES:
|
for category, text, __ in category_defs():
|
||||||
self.categories[category] = i = QTreeWidgetItem(self.root, 0)
|
self.categories[category] = i = QTreeWidgetItem(self.root, 0)
|
||||||
i.setText(0, text)
|
i.setText(0, text)
|
||||||
i.setData(0, Qt.ItemDataRole.DecorationRole, self.top_level_pixmap_cache[category])
|
i.setData(0, Qt.ItemDataRole.DecorationRole, self.top_level_pixmap_cache[category])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user