mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Change icon stuff to use the context menu
This commit is contained in:
parent
7dd6fbd80e
commit
a3e9634e38
@ -106,6 +106,7 @@ gprefs.defaults['tag_browser_old_look'] = False
|
|||||||
gprefs.defaults['book_list_tooltips'] = True
|
gprefs.defaults['book_list_tooltips'] = True
|
||||||
gprefs.defaults['bd_show_cover'] = True
|
gprefs.defaults['bd_show_cover'] = True
|
||||||
gprefs.defaults['bd_overlay_cover_size'] = False
|
gprefs.defaults['bd_overlay_cover_size'] = False
|
||||||
|
gprefs.defaults['tags_browser_category_icons'] = {}
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
NONE = QVariant() #: Null value to return from the data function of item models
|
NONE = QVariant() #: Null value to return from the data function of item models
|
||||||
|
@ -214,6 +214,10 @@ class TagsModel(QAbstractItemModel): # {{{
|
|||||||
iconmap[key] = QIcon(I(category_icon_map[key]))
|
iconmap[key] = QIcon(I(category_icon_map[key]))
|
||||||
self.category_icon_map = TagsIcons(iconmap)
|
self.category_icon_map = TagsIcons(iconmap)
|
||||||
self.category_custom_icons = dict()
|
self.category_custom_icons = dict()
|
||||||
|
for k,v in gprefs['tags_browser_category_icons'].items():
|
||||||
|
icon = QIcon(v)
|
||||||
|
if len(icon.availableSizes()) > 0:
|
||||||
|
self.category_custom_icons[k] = icon
|
||||||
self.categories_with_ratings = ['authors', 'series', 'publisher', 'tags']
|
self.categories_with_ratings = ['authors', 'series', 'publisher', 'tags']
|
||||||
self.icon_state_map = [None, QIcon(I('plus.png')), QIcon(I('plusplus.png')),
|
self.icon_state_map = [None, QIcon(I('plus.png')), QIcon(I('plusplus.png')),
|
||||||
QIcon(I('minus.png')), QIcon(I('minusminus.png'))]
|
QIcon(I('minus.png')), QIcon(I('minusminus.png'))]
|
||||||
@ -232,6 +236,16 @@ class TagsModel(QAbstractItemModel): # {{{
|
|||||||
def gui_parent(self):
|
def gui_parent(self):
|
||||||
return QObject.parent(self)
|
return QObject.parent(self)
|
||||||
|
|
||||||
|
def set_custom_category_icon(self, key, path):
|
||||||
|
d = gprefs['tags_browser_category_icons']
|
||||||
|
if path:
|
||||||
|
d[key] = path
|
||||||
|
self.category_custom_icons[key] = QIcon(path)
|
||||||
|
else:
|
||||||
|
del d[key]
|
||||||
|
del self.category_custom_icons[key]
|
||||||
|
gprefs['tags_browser_category_icons'] = d
|
||||||
|
|
||||||
def reread_collapse_model(self, state_map, rebuild=True):
|
def reread_collapse_model(self, state_map, rebuild=True):
|
||||||
if gprefs['tags_browser_collapse_at'] == 0:
|
if gprefs['tags_browser_collapse_at'] == 0:
|
||||||
self.collapse_model = 'disable'
|
self.collapse_model = 'disable'
|
||||||
@ -312,16 +326,9 @@ class TagsModel(QAbstractItemModel): # {{{
|
|||||||
else:
|
else:
|
||||||
tt = _(u'The lookup/search name is "{0}"').format(key)
|
tt = _(u'The lookup/search name is "{0}"').format(key)
|
||||||
|
|
||||||
# Get any customized icons. Done here to account for columns
|
|
||||||
# coming and going. Should be done only once per model instantiation
|
|
||||||
if self.category_custom_icons.get(key, None) is None:
|
if self.category_custom_icons.get(key, None) is None:
|
||||||
icon = QIcon(I('tbci_' + key))
|
self.category_custom_icons[key] = \
|
||||||
if len(icon.availableSizes()) > 0:
|
self.category_icon_map['gst'] if is_gst else self.category_icon_map[key]
|
||||||
self.category_custom_icons[key] = icon
|
|
||||||
else:
|
|
||||||
self.category_custom_icons[key] = \
|
|
||||||
self.category_icon_map['gst'] if is_gst else \
|
|
||||||
self.category_icon_map[key]
|
|
||||||
|
|
||||||
if key.startswith('@'):
|
if key.startswith('@'):
|
||||||
path_parts = [p for p in key.split('.')]
|
path_parts = [p for p in key.split('.')]
|
||||||
|
@ -13,11 +13,12 @@ from itertools import izip
|
|||||||
|
|
||||||
from PyQt4.Qt import (QStyledItemDelegate, Qt, QTreeView, pyqtSignal, QSize,
|
from PyQt4.Qt import (QStyledItemDelegate, Qt, QTreeView, pyqtSignal, QSize,
|
||||||
QIcon, QApplication, QMenu, QPoint, QModelIndex, QToolTip, QCursor,
|
QIcon, QApplication, QMenu, QPoint, QModelIndex, QToolTip, QCursor,
|
||||||
QDrag)
|
QDrag, QFileDialog)
|
||||||
|
|
||||||
from calibre.gui2.tag_browser.model import (TagTreeItem, TAG_SEARCH_STATES,
|
from calibre.gui2.tag_browser.model import (TagTreeItem, TAG_SEARCH_STATES,
|
||||||
TagsModel)
|
TagsModel)
|
||||||
from calibre.gui2 import config, gprefs
|
from calibre.gui2 import config, gprefs
|
||||||
|
from calibre.utils.resources import get_image_path
|
||||||
from calibre.utils.search_query_parser import saved_searches
|
from calibre.utils.search_query_parser import saved_searches
|
||||||
from calibre.utils.icu import sort_key
|
from calibre.utils.icu import sort_key
|
||||||
|
|
||||||
@ -296,6 +297,22 @@ class TagsView(QTreeView): # {{{
|
|||||||
if not action:
|
if not action:
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
|
if action == 'set_icon':
|
||||||
|
try:
|
||||||
|
path = QFileDialog.getOpenFileName(self, 'New Icon', get_image_path(None),
|
||||||
|
filter='*.png *.jpg')
|
||||||
|
if path:
|
||||||
|
self._model.set_custom_category_icon(key, unicode(path))
|
||||||
|
self.recount()
|
||||||
|
except:
|
||||||
|
import traceback
|
||||||
|
traceback.print_exc()
|
||||||
|
return
|
||||||
|
if action == 'clear_icon':
|
||||||
|
self._model.set_custom_category_icon(key, None)
|
||||||
|
self.recount()
|
||||||
|
return
|
||||||
|
|
||||||
if action == 'edit_item':
|
if action == 'edit_item':
|
||||||
self.edit(index)
|
self.edit(index)
|
||||||
return
|
return
|
||||||
@ -533,6 +550,12 @@ class TagsView(QTreeView): # {{{
|
|||||||
partial(self.context_menu_handler, action='manage_searches',
|
partial(self.context_menu_handler, action='manage_searches',
|
||||||
category=tag.name if tag else None))
|
category=tag.name if tag else None))
|
||||||
|
|
||||||
|
self.context_menu.addSeparator()
|
||||||
|
self.context_menu.addAction(_('Change category icon'),
|
||||||
|
partial(self.context_menu_handler, action='set_icon', key=key))
|
||||||
|
self.context_menu.addAction(_('Restore default icon'),
|
||||||
|
partial(self.context_menu_handler, action='clear_icon', key=key))
|
||||||
|
|
||||||
# Always show the user categories editor
|
# Always show the user categories editor
|
||||||
self.context_menu.addSeparator()
|
self.context_menu.addSeparator()
|
||||||
if key.startswith('@') and \
|
if key.startswith('@') and \
|
||||||
@ -551,6 +574,7 @@ class TagsView(QTreeView): # {{{
|
|||||||
self.context_menu.addAction(_('Show all categories'),
|
self.context_menu.addAction(_('Show all categories'),
|
||||||
partial(self.context_menu_handler, action='defaults'))
|
partial(self.context_menu_handler, action='defaults'))
|
||||||
|
|
||||||
|
|
||||||
m = self.context_menu.addMenu(_('Change sub-categorization scheme'))
|
m = self.context_menu.addMenu(_('Change sub-categorization scheme'))
|
||||||
da = m.addAction(_('Disable'),
|
da = m.addAction(_('Disable'),
|
||||||
partial(self.context_menu_handler, action='categorization', category='disable'))
|
partial(self.context_menu_handler, action='categorization', category='disable'))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user