mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
Get tag browser value icons working in content server
This commit is contained in:
parent
a0a7ef06c0
commit
39e17d55e3
@ -14,7 +14,7 @@ DATA_DIR_NAME = 'data'
|
|||||||
DATA_FILE_PATTERN = f'{DATA_DIR_NAME}/**/*'
|
DATA_FILE_PATTERN = f'{DATA_DIR_NAME}/**/*'
|
||||||
BOOK_ID_PATH_TEMPLATE = ' ({})'
|
BOOK_ID_PATH_TEMPLATE = ' ({})'
|
||||||
RESOURCE_URL_SCHEME = 'calres'
|
RESOURCE_URL_SCHEME = 'calres'
|
||||||
|
TEMPLATE_ICON_INDICATOR = ' template ' # Item values cannot start or end with space
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class TrashEntry:
|
class TrashEntry:
|
||||||
|
@ -14,6 +14,7 @@ from qt.core import QAbstractItemModel, QFont, QIcon, QMimeData, QModelIndex, QO
|
|||||||
|
|
||||||
from calibre.constants import config_dir
|
from calibre.constants import config_dir
|
||||||
from calibre.db.categories import Tag, category_display_order
|
from calibre.db.categories import Tag, category_display_order
|
||||||
|
from calibre.db.constants import TEMPLATE_ICON_INDICATOR
|
||||||
from calibre.ebooks.metadata import rating_to_stars
|
from calibre.ebooks.metadata import rating_to_stars
|
||||||
from calibre.gui2 import config, error_dialog, file_icon_provider, gprefs, question_dialog
|
from calibre.gui2 import config, error_dialog, file_icon_provider, gprefs, question_dialog
|
||||||
from calibre.gui2.dialogs.confirm_delete import confirm
|
from calibre.gui2.dialogs.confirm_delete import confirm
|
||||||
@ -30,7 +31,6 @@ TAG_SEARCH_STATES = {'clear': 0, 'mark_plus': 1, 'mark_plusplus': 2,
|
|||||||
'mark_minus': 3, 'mark_minusminus': 4}
|
'mark_minus': 3, 'mark_minusminus': 4}
|
||||||
DRAG_IMAGE_ROLE = Qt.ItemDataRole.UserRole + 1000
|
DRAG_IMAGE_ROLE = Qt.ItemDataRole.UserRole + 1000
|
||||||
COUNT_ROLE = DRAG_IMAGE_ROLE + 1
|
COUNT_ROLE = DRAG_IMAGE_ROLE + 1
|
||||||
TEMPLATE_ICON_INDICATOR = ' template ' # Item values cannot start or end with space
|
|
||||||
|
|
||||||
_bf = None
|
_bf = None
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ from threading import Lock
|
|||||||
|
|
||||||
from calibre.constants import config_dir
|
from calibre.constants import config_dir
|
||||||
from calibre.db.categories import Tag, category_display_order
|
from calibre.db.categories import Tag, category_display_order
|
||||||
from calibre.db.constants import DATA_FILE_PATTERN
|
from calibre.db.constants import DATA_FILE_PATTERN, TEMPLATE_ICON_INDICATOR
|
||||||
from calibre.ebooks.metadata.sources.identify import urls_from_identifiers
|
from calibre.ebooks.metadata.sources.identify import urls_from_identifiers
|
||||||
from calibre.library.comments import comments_to_html, markdown
|
from calibre.library.comments import comments_to_html, markdown
|
||||||
from calibre.library.field_metadata import category_icon_map
|
from calibre.library.field_metadata import category_icon_map
|
||||||
@ -157,48 +157,48 @@ def category_item_as_json(x, clear_rating=False):
|
|||||||
return ans
|
return ans
|
||||||
|
|
||||||
|
|
||||||
# don't want to import from the GUI so use the value of TEMPLATE_ICON_INDICATOR
|
|
||||||
TEMPLATE_ICON_INDICATOR = ' template '
|
def get_gpref(name: str, defval = None):
|
||||||
|
gprefs = getattr(get_gpref, 'gprefs', None)
|
||||||
|
if gprefs is None:
|
||||||
|
from calibre.utils.config import JSONConfig
|
||||||
|
gprefs = get_gpref.gprefs = JSONConfig('gui')
|
||||||
|
return gprefs.get(name, defval)
|
||||||
|
|
||||||
|
|
||||||
def get_icon_for_node(node, parent, node_to_tag_map, tag_map, eval_formatter):
|
def get_icon_for_node(node, parent, node_to_tag_map, tag_map, eval_formatter):
|
||||||
try:
|
category = node['category']
|
||||||
category = node['category']
|
if category in ('search', 'formats') or category.startswith('@'):
|
||||||
if category in ('search', 'formats') or category.startswith('@'):
|
return
|
||||||
node['value_icon'] = None
|
|
||||||
return
|
|
||||||
|
|
||||||
def name_for_icon(node):
|
def name_for_icon(node):
|
||||||
return node.get('original_name', node.get('name'))
|
return node.get('original_name', node.get('name'))
|
||||||
|
|
||||||
from calibre.gui2 import gprefs
|
value_icons = get_gpref('tags_browser_value_icons')
|
||||||
value_icons = gprefs['tags_browser_value_icons']
|
val_icon, for_children = value_icons.get(category, {}).get(name_for_icon(node), (None, False))
|
||||||
val_icon,for_children = value_icons.get(category, {}).get(name_for_icon(node), (None, False))
|
if val_icon is None:
|
||||||
if val_icon is None:
|
# No specific icon. Walk up the hierarchy checking parents.
|
||||||
# No specific icon. Walk up the hierarchy checking parents.
|
par = parent
|
||||||
par = parent
|
while True:
|
||||||
while True:
|
pid = str(par['id'])
|
||||||
pid = str(par['id'])
|
if not pid.startswith('n'):
|
||||||
if not pid.startswith('n'):
|
# 'Real' nodes (tag nodes) start with 'n'
|
||||||
# 'Real' nodes (tag nodes) start with 'n'
|
break
|
||||||
break
|
pt = node_to_tag_map[pid]
|
||||||
pt = node_to_tag_map[pid]
|
pd = tag_map[id(pt)][1]
|
||||||
pd = tag_map[id(pt)][1]
|
val_icon,for_children = value_icons.get(pd['category'], {}).get(name_for_icon(pd), (None, False))
|
||||||
val_icon,for_children = value_icons.get(pd['category'], {}).get(name_for_icon(pd), (None, False))
|
if val_icon is not None and for_children:
|
||||||
if val_icon is not None and for_children:
|
break
|
||||||
break
|
par = pd
|
||||||
par = pd
|
if val_icon is None and TEMPLATE_ICON_INDICATOR in value_icons.get(category, {}):
|
||||||
if val_icon is None and TEMPLATE_ICON_INDICATOR in value_icons.get(category, {}):
|
t = eval_formatter.safe_format(
|
||||||
t = eval_formatter.safe_format(value_icons[category][TEMPLATE_ICON_INDICATOR][0],
|
value_icons[category][TEMPLATE_ICON_INDICATOR][0], {'category': category, 'value': name_for_icon(node)},
|
||||||
{'category': category, 'value': name_for_icon(node)},
|
'VALUE_ICON_TEMPLATE_ERROR', None)
|
||||||
'VALUE_ICON_TEMPLATE_ERROR', None)
|
if t:
|
||||||
if t:
|
# Use POSIX path separator
|
||||||
# Use linux path separator
|
val_icon = 'template_icons/' + t
|
||||||
val_icon = 'template_icons/' + t
|
if val_icon:
|
||||||
node['value_icon'] = val_icon
|
node['value_icon'] = val_icon
|
||||||
except:
|
|
||||||
import traceback
|
|
||||||
traceback.print_exc()
|
|
||||||
|
|
||||||
|
|
||||||
CategoriesSettings = namedtuple(
|
CategoriesSettings = namedtuple(
|
||||||
@ -466,7 +466,11 @@ def process_category_node(
|
|||||||
node_id, node_data = node_data
|
node_id, node_data = node_data
|
||||||
node = {'id':node_id, 'children':[]}
|
node = {'id':node_id, 'children':[]}
|
||||||
parent['children'].append(node)
|
parent['children'].append(node)
|
||||||
get_icon_for_node(node_data, parent, node_to_tag_map, tag_map, eval_formatter)
|
try:
|
||||||
|
get_icon_for_node(node_data, parent, node_to_tag_map, tag_map, eval_formatter)
|
||||||
|
except Exception:
|
||||||
|
import traceback
|
||||||
|
traceback.print_exc()
|
||||||
return node, node_data
|
return node, node_data
|
||||||
|
|
||||||
for idx, tag in enumerate(category_items):
|
for idx, tag in enumerate(category_items):
|
||||||
|
@ -68,6 +68,9 @@ def icon_for_node(node):
|
|||||||
fallback = interface_data.icon_map[node.data.category]
|
fallback = interface_data.icon_map[node.data.category]
|
||||||
else:
|
else:
|
||||||
ans = interface_data.icon_map[node.data.category] or 'column.png'
|
ans = interface_data.icon_map[node.data.category] or 'column.png'
|
||||||
|
if node.data.value_icon:
|
||||||
|
fallback = ans
|
||||||
|
ans = '_' + node.data.value_icon
|
||||||
if fallback:
|
if fallback:
|
||||||
fallback = absolute_path(interface_data.icon_path + '/' + fallback)
|
fallback = absolute_path(interface_data.icon_path + '/' + fallback)
|
||||||
return absolute_path(interface_data.icon_path + '/' + ans), fallback
|
return absolute_path(interface_data.icon_path + '/' + ans), fallback
|
||||||
|
Loading…
x
Reference in New Issue
Block a user