mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Misc cleanups
This commit is contained in:
parent
fb13f2e7f4
commit
149f979409
@ -49,7 +49,7 @@ class TagCategories(QDialog, Ui_TagCategories):
|
||||
cc_map = self.db.custom_column_label_map
|
||||
for cc in cc_map:
|
||||
if cc_map[cc]['datatype'] == 'text':
|
||||
self.category_labels.append(cc)
|
||||
self.category_labels.append(db.tag_browser_categories.get_search_label(cc))
|
||||
category_icons.append(cc_icon)
|
||||
category_values.append(lambda col=cc: self.db.all_custom(label=col))
|
||||
category_names.append(cc_map[cc]['name'])
|
||||
|
@ -632,6 +632,8 @@ class BooksModel(QAbstractTableModel): # {{{
|
||||
return None
|
||||
if role == Qt.ToolTipRole:
|
||||
ht = self.column_map[section]
|
||||
if self.is_custom_column(self.column_map[section]):
|
||||
ht = self.db.tag_browser_categories.custom_field_prefix + ht
|
||||
if ht == 'timestamp': # change help text because users know this field as 'date'
|
||||
ht = 'date'
|
||||
return QVariant(_('The lookup/search name is "{0}"').format(ht))
|
||||
|
@ -224,10 +224,14 @@ class TagsModel(QAbstractItemModel): # {{{
|
||||
data = self.get_node_tree(config['sort_by_popularity'])
|
||||
self.root_item = TagTreeItem()
|
||||
for i, r in enumerate(self.row_map):
|
||||
if self.db.get_tag_browser_categories()[r]['kind'] != 'user':
|
||||
tt = _('The lookup/search name is "{0}"').format(r)
|
||||
else:
|
||||
tt = ''
|
||||
c = TagTreeItem(parent=self.root_item,
|
||||
data=self.categories[i],
|
||||
category_icon=self.category_icon_map[r],
|
||||
tooltip=_('The lookup/search name is "{0}"').format(r))
|
||||
tooltip=tt)
|
||||
for tag in data[r]:
|
||||
TagTreeItem(parent=c, data=tag, icon_map=self.icon_state_map)
|
||||
|
||||
|
@ -386,7 +386,7 @@ class ResultCache(SearchQueryParser):
|
||||
for x in self.tag_browser_categories:
|
||||
if (len(self.tag_browser_categories[x]['search_labels']) and \
|
||||
self.tag_browser_categories[x]['kind'] in ['standard', 'not_cat']):
|
||||
MAP[x] = self.FIELD_MAP[self.tag_browser_categories.get_label(x)]
|
||||
MAP[x] = self.FIELD_MAP[self.tag_browser_categories.get_field_label(x)]
|
||||
|
||||
# add custom columns to MAP. Put the column's type into IS_CUSTOM
|
||||
IS_CUSTOM = []
|
||||
|
@ -670,7 +670,7 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
||||
# icon_map is not None if get_categories is to store an icon and
|
||||
# possibly a tooltip in the tag structure.
|
||||
icon, tooltip = None, ''
|
||||
label = tb_cats.get_label(category)
|
||||
label = tb_cats.get_field_label(category)
|
||||
if icon_map:
|
||||
if cat['kind'] == 'standard':
|
||||
if category in icon_map:
|
||||
@ -769,7 +769,7 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
||||
for srch in saved_searches.names():
|
||||
items.append(Tag(srch, tooltip=saved_searches.lookup(srch), icon=icon))
|
||||
if len(items):
|
||||
tb_cats.add_user_category(field_name='search', name=_('Searches'))
|
||||
tb_cats.add_search_category(field_name='search', name=_('Searches'))
|
||||
if icon_map is not None:
|
||||
icon_map['search'] = icon_map['search']
|
||||
categories['search'] = items
|
||||
|
@ -88,73 +88,77 @@ class TagsMetadata(dict, DictMixin):
|
||||
]
|
||||
|
||||
def __init__(self):
|
||||
self.tb_cats_ = OrderedDict()
|
||||
self._tb_cats = OrderedDict()
|
||||
for k,v in self.category_items_:
|
||||
self.tb_cats_[k] = v
|
||||
|
||||
def __getattr__(self, name):
|
||||
if name in self.tb_cats_:
|
||||
return self.tb_cats_[name]
|
||||
return None
|
||||
|
||||
# def __setattr__(self, name, val):
|
||||
# dict.__setattr__(self, name, val)
|
||||
self._tb_cats[k] = v
|
||||
self._custom_fields = []
|
||||
self.custom_field_prefix = '#'
|
||||
|
||||
def __getitem__(self, key):
|
||||
return self.tb_cats_[key]
|
||||
return self._tb_cats[key]
|
||||
|
||||
# def __setitem__(self, key, val):
|
||||
# print 'setitem', key, val
|
||||
# self.tb_cats_[key] = val
|
||||
def __setitem__(self, key, val):
|
||||
raise AttributeError('Assigning to this object is forbidden')
|
||||
|
||||
def __delitem__(self, key):
|
||||
del self.tb_cats_[key]
|
||||
del self._tb_cats[key]
|
||||
|
||||
def __iter__(self):
|
||||
for key in self.tb_cats_:
|
||||
for key in self._tb_cats:
|
||||
yield key
|
||||
|
||||
def keys(self):
|
||||
return self.tb_cats_.keys()
|
||||
return self._tb_cats.keys()
|
||||
|
||||
def iterkeys(self):
|
||||
for key in self.tb_cats_:
|
||||
for key in self._tb_cats:
|
||||
yield key
|
||||
|
||||
def iteritems(self):
|
||||
for key in self.tb_cats_:
|
||||
yield (key, self.tb_cats_[key])
|
||||
for key in self._tb_cats:
|
||||
yield (key, self._tb_cats[key])
|
||||
|
||||
def get_label(self, key):
|
||||
if 'label' not in self.tb_cats_[key]:
|
||||
def is_custom_field(self, label):
|
||||
return label.startswith(self.custom_field_prefix) or label in self._custom_fields
|
||||
|
||||
def get_field_label(self, key):
|
||||
if 'label' not in self._tb_cats[key]:
|
||||
return key
|
||||
return self.tb_cats_[key]['label']
|
||||
return self._tb_cats[key]['label']
|
||||
|
||||
def get_search_label(self, key):
|
||||
if 'label' in self._tb_cats:
|
||||
return key
|
||||
if self.is_custom_field(key):
|
||||
return self.custom_field_prefix+key
|
||||
raise ValueError('Unknown key [%s]'%(key))
|
||||
|
||||
def get_custom_fields(self):
|
||||
return [l for l in self.tb_cats_ if self.tb_cats_[l]['kind'] == 'custom']
|
||||
return [l for l in self._tb_cats if self._tb_cats[l]['kind'] == 'custom']
|
||||
|
||||
def add_custom_field(self, field_name, table, column, datatype, is_multiple, number, name):
|
||||
fn = '#' + field_name
|
||||
if fn in self.tb_cats_:
|
||||
fn = self.custom_field_prefix + field_name
|
||||
if fn in self._tb_cats:
|
||||
raise ValueError('Duplicate custom field [%s]'%(field_name))
|
||||
self.tb_cats_[fn] = {'table':table, 'column':column,
|
||||
self._custom_fields.append(field_name)
|
||||
self._tb_cats[fn] = {'table':table, 'column':column,
|
||||
'datatype':datatype, 'is_multiple':is_multiple,
|
||||
'kind':'custom', 'name':name,
|
||||
'search_labels':[fn],'label':field_name,
|
||||
'colnum':number}
|
||||
|
||||
def add_user_category(self, field_name, name):
|
||||
if field_name in self.tb_cats_:
|
||||
if field_name in self._tb_cats:
|
||||
raise ValueError('Duplicate user field [%s]'%(field_name))
|
||||
self.tb_cats_[field_name] = {'table':None, 'column':None,
|
||||
self._tb_cats[field_name] = {'table':None, 'column':None,
|
||||
'datatype':None, 'is_multiple':False,
|
||||
'kind':'user', 'name':name,
|
||||
'search_labels':[]}
|
||||
|
||||
def add_search_category(self, field_name, name):
|
||||
if field_name in self.tb_cats_:
|
||||
if field_name in self._tb_cats:
|
||||
raise ValueError('Duplicate user field [%s]'%(field_name))
|
||||
self.tb_cats_[field_name] = {'table':None, 'column':None,
|
||||
self._tb_cats[field_name] = {'table':None, 'column':None,
|
||||
'datatype':None, 'is_multiple':False,
|
||||
'kind':'search', 'name':name,
|
||||
'search_labels':[]}
|
||||
@ -184,7 +188,7 @@ class TagsMetadata(dict, DictMixin):
|
||||
|
||||
def get_search_labels(self):
|
||||
s_labels = []
|
||||
for v in self.tb_cats_.itervalues():
|
||||
for v in self._tb_cats.itervalues():
|
||||
map((lambda x:s_labels.append(x)), v['search_labels'])
|
||||
for v in self.search_items:
|
||||
s_labels.append(v)
|
||||
|
Loading…
x
Reference in New Issue
Block a user