This commit is contained in:
Kovid Goyal 2025-01-16 20:50:19 +05:30
commit 85f70dc95c
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 39 additions and 3 deletions

View File

@ -725,6 +725,36 @@ You can easily find any item in the Tag browser by clicking the search button at
You can control how items are sorted in the Tag browser via the :guilabel:`Configure` button at the lower-left of the Tag browser. You can choose to sort by name, average rating or popularity (popularity is the number of books with an item in your library; for example, the popularity of Isaac Asimov is the number of books in your library by Isaac Asimov).
You can use your own icons for categories and values in categories. To change the icon for a category,
right-click on the category (the outer-level item) and choose `Change (category name) category icon`. A dialog will open where you can pick an image to be used as the icon. To restore the icon to its default choose `Restore (category name) default icon`.
To choose icons for values in categories, right-click on a value then choose `Manage value icons`. You will see a list of choices:
* `Choose an icon for this value but not its children`. A dialog will open where you choose an icon for the value. Children of that value will not inherit that icon.
* `Choose an icon for this value and its children`. A dialog will open where you choose an icon for the value. Any children that don't have their own specified icon will inherit this icon.
* `Choose an existing icon for this value but not its children`. This option is offered if the value already has an icon that is inherited by the value's children. Selecting it will make the icon apply to the value but not its children.
* `Choose and existing icon for this value and its children`. This option is offered if the value already has an icon that is not inherited by the value's children. Selecting it will make the icon apply to the value and its children.
* `Use the default icon for this value`. This option is offered if the item has an icon. It removes the icon from the value and any children inheriting the icon. The default icon is what is specified below.
* `Use/edit a template to choose the default value icon`. This option permits you to provide a calibre template that returns the name of an icon file to be uses as a default icon. The template can use two variables:
* ``category``: the lookup name of the category, for example ``authors``, ``series``, ``#mycolumn``.
* ``value``: the value of the item within the category.
Book metadata such as title is not available.
For example, this template specifies that any value in the clicked-on category beginning with `History` will have an icon named ``flower.png``::
program:
if substr($value, 0, 7) == 'History' then 'flower.png' fi
If the template returns the empty string (``''``) then the category icon will be used. If the template
returns a file name that doesn't exist then no icon is displayed.
* `Use the category icon as the default`. This option specifies that the icon used for the category should be used for any value that doesn't otherwise have an icon. Selecting this option removes any template icon specification.
Icons for item values are stored in the ``tb_icons`` subfolder in the calibre configuration folder. Icons used by templates are in the ``template_icons`` subfolder of ``tb_icons``.
.. raw:: html epub
<div style="clear:both"></div>

View File

@ -143,10 +143,12 @@ class TagTreeItem: # {{{
break
if val_icon is None and TEMPLATE_ICON_INDICATOR in self.value_icons[category]:
t = self.eval_formatter.safe_format(self.value_icons[category][TEMPLATE_ICON_INDICATOR][0],
{'category': category, 'value': node.tag.original_name},
{'category': category, 'value': self.tag.original_name},
'VALUE_ICON_TEMPLATE_ERROR', None)
if t:
val_icon = (os.path.join('template_icons', t), False)
else:
val_icon = None
if val_icon is not None:
cc = self.value_icon_cache.get(val_icon[0])
if cc is None:

View File

@ -1285,13 +1285,15 @@ class TagsView(QTreeView): # {{{
im.addAction(_('Use the default icon for {}').format(for_name),
partial(self.context_menu_handler, action='clear_icon',
key=key, index=index, category=category))
ma.setEnabled(icon_name is not None)
im.addSection(_('Defaults'))
im.addAction(_('Use a template to choose the default value icon'),
im.addAction(_('Use/edit a template to choose the default value icon'),
partial(self.context_menu_handler, action='set_icon',
key=key, index=index, category=None, extra=(None, None)))
im.addAction(_('Use the category icon for the default value icon'),
ma = im.addAction(_('Use the category icon for the default value icon'),
partial(self.context_menu_handler, action='clear_icon',
key=key, index=None, category=category))
ma.setEnabled(self._model.value_icons.get(key, {}).get(TEMPLATE_ICON_INDICATOR) is not None)
im.addSeparator()
# Always show the User categories editor
self.context_menu.addSeparator()

View File

@ -197,6 +197,8 @@ def get_icon_for_node(node, parent, node_to_tag_map, tag_map, eval_formatter):
if t:
# Use POSIX path separator
val_icon = 'template_icons/' + t
else:
val_icon = None
if val_icon:
node['value_icon'] = val_icon