mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
After testing, for submission
This commit is contained in:
parent
e3c9ebf283
commit
feaebe3524
@ -75,7 +75,7 @@ class CreateCustomColumn(QDialog, Ui_QCreateCustomColumn):
|
|||||||
if col in self.standard_colnames:
|
if col in self.standard_colnames:
|
||||||
bad_col = True
|
bad_col = True
|
||||||
if bad_col:
|
if bad_col:
|
||||||
self.parent.messagebox(_('The lookup name is already used'))
|
self.parent.messagebox(_('The lookup name %s is already used')%col)
|
||||||
return
|
return
|
||||||
bad_head = False
|
bad_head = False
|
||||||
for t in self.parent.custcols:
|
for t in self.parent.custcols:
|
||||||
|
@ -146,15 +146,14 @@ class TagCategories(QDialog, Ui_TagCategories):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def del_category(self):
|
def del_category(self):
|
||||||
if not confirm('<p>'+_('The current tag category will be '
|
|
||||||
'<b>permanently deleted</b>. Are you sure?')
|
|
||||||
+'</p>', 'tag_category_delete', self):
|
|
||||||
return
|
|
||||||
if self.current_cat_name is not None:
|
if self.current_cat_name is not None:
|
||||||
if self.current_cat_name == unicode(self.category_box.currentText()):
|
if not confirm('<p>'+_('The current tag category will be '
|
||||||
del self.categories[self.current_cat_name]
|
'<b>permanently deleted</b>. Are you sure?')
|
||||||
self.current_category = None
|
+'</p>', 'tag_category_delete', self):
|
||||||
self.category_box.removeItem(self.category_box.currentIndex())
|
return
|
||||||
|
del self.categories[self.current_cat_name]
|
||||||
|
self.current_cat_name = None
|
||||||
|
self.category_box.removeItem(self.category_box.currentIndex())
|
||||||
|
|
||||||
def select_category(self, idx):
|
def select_category(self, idx):
|
||||||
self.save_category()
|
self.save_category()
|
||||||
@ -164,7 +163,9 @@ class TagCategories(QDialog, Ui_TagCategories):
|
|||||||
else:
|
else:
|
||||||
self.current_cat_name = None
|
self.current_cat_name = None
|
||||||
if self.current_cat_name:
|
if self.current_cat_name:
|
||||||
self.applied_items = [tup[2] for tup in self.categories.get(self.current_cat_name, [])]
|
self.applied_items = [cat[2] for cat in self.categories.get(self.current_cat_name, [])]
|
||||||
|
else:
|
||||||
|
self.applied_items = []
|
||||||
self.display_filtered_categories(None)
|
self.display_filtered_categories(None)
|
||||||
|
|
||||||
def accept(self):
|
def accept(self):
|
||||||
|
@ -300,13 +300,13 @@ class BooksModel(QAbstractTableModel):
|
|||||||
self.headers[i] = self.orig_headers[i]
|
self.headers[i] = self.orig_headers[i]
|
||||||
elif i in self.custom_columns:
|
elif i in self.custom_columns:
|
||||||
self.headers[i] = self.custom_columns[i]['name']
|
self.headers[i] = self.custom_columns[i]['name']
|
||||||
|
self.build_data_convertors()
|
||||||
self.reset()
|
self.reset()
|
||||||
self.emit(SIGNAL('columns_sorted()'))
|
self.emit(SIGNAL('columns_sorted()'))
|
||||||
|
|
||||||
def set_database(self, db):
|
def set_database(self, db):
|
||||||
self.db = db
|
self.db = db
|
||||||
self.custom_columns = self.db.custom_column_label_map
|
self.custom_columns = self.db.custom_column_label_map
|
||||||
self.build_data_convertors()
|
|
||||||
self.read_config()
|
self.read_config()
|
||||||
|
|
||||||
def refresh_ids(self, ids, current_row=-1):
|
def refresh_ids(self, ids, current_row=-1):
|
||||||
@ -703,9 +703,9 @@ class BooksModel(QAbstractTableModel):
|
|||||||
def bool_type(r, idx=-1):
|
def bool_type(r, idx=-1):
|
||||||
return None # displayed using a decorator
|
return None # displayed using a decorator
|
||||||
|
|
||||||
def bool_type_decorator(r, idx=-1):
|
def bool_type_decorator(r, idx=-1, bool_cols_are_tristate=True):
|
||||||
val = self.db.data[r][idx]
|
val = self.db.data[r][idx]
|
||||||
if tweaks['bool_custom_columns_are_tristate'] == 'no':
|
if not bool_cols_are_tristate:
|
||||||
if val is None or not val:
|
if val is None or not val:
|
||||||
return self.bool_no_icon
|
return self.bool_no_icon
|
||||||
if val:
|
if val:
|
||||||
@ -748,21 +748,32 @@ class BooksModel(QAbstractTableModel):
|
|||||||
self.dc[col] = functools.partial(datetime_type, idx=idx)
|
self.dc[col] = functools.partial(datetime_type, idx=idx)
|
||||||
elif datatype == 'bool':
|
elif datatype == 'bool':
|
||||||
self.dc[col] = functools.partial(bool_type, idx=idx)
|
self.dc[col] = functools.partial(bool_type, idx=idx)
|
||||||
self.dc_decorator[col] = functools.partial(bool_type_decorator, idx=idx)
|
self.dc_decorator[col] = functools.partial(
|
||||||
|
bool_type_decorator, idx=idx,
|
||||||
|
bool_cols_are_tristate=tweaks['bool_custom_columns_are_tristate'] == 'yes')
|
||||||
elif datatype == 'rating':
|
elif datatype == 'rating':
|
||||||
self.dc[col] = functools.partial(rating_type, idx=idx)
|
self.dc[col] = functools.partial(rating_type, idx=idx)
|
||||||
else:
|
else:
|
||||||
print 'What type is this?', col, datatype
|
print 'What type is this?', col, datatype
|
||||||
|
# build a index column to data converter map, to remove the string lookup in the data loop
|
||||||
|
self.column_to_dc_map = []
|
||||||
|
self.column_to_dc_decorator_map = []
|
||||||
|
for col in self.column_map:
|
||||||
|
self.column_to_dc_map.append(self.dc[col])
|
||||||
|
self.column_to_dc_decorator_map.append(self.dc_decorator.get(col, None))
|
||||||
|
|
||||||
def data(self, index, role):
|
def data(self, index, role):
|
||||||
if role in (Qt.DisplayRole, Qt.EditRole):
|
col = index.column()
|
||||||
return self.dc[self.column_map[index.column()]](index.row())
|
# in obscure cases where custom columns are both edited and added, for a time
|
||||||
elif role == Qt.DecorationRole:
|
# the column map does not accurately represent the screen. In these cases,
|
||||||
if self.column_map[index.column()] in self.dc_decorator:
|
# we will get asked to display columns we don't know about. Must test for this.
|
||||||
return self.dc_decorator[self.column_map[index.column()]](index.row())
|
if col >= len(self.column_to_dc_map):
|
||||||
return None
|
return None
|
||||||
#elif role == Qt.SizeHintRole:
|
if role in (Qt.DisplayRole, Qt.EditRole):
|
||||||
# return QVariant(Qt.SizeHint(1, 23))
|
return self.column_to_dc_map[col](index.row())
|
||||||
|
elif role == Qt.DecorationRole:
|
||||||
|
if self.column_to_dc_decorator_map[col] is not None:
|
||||||
|
return self.column_to_dc_decorator_map[index.column()](index.row())
|
||||||
#elif role == Qt.TextAlignmentRole and self.column_map[index.column()] in ('size', 'timestamp'):
|
#elif role == Qt.TextAlignmentRole and self.column_map[index.column()] in ('size', 'timestamp'):
|
||||||
# return QVariant(Qt.AlignVCenter | Qt.AlignCenter)
|
# return QVariant(Qt.AlignVCenter | Qt.AlignCenter)
|
||||||
#elif role == Qt.ToolTipRole and index.isValid():
|
#elif role == Qt.ToolTipRole and index.isValid():
|
||||||
@ -771,14 +782,18 @@ class BooksModel(QAbstractTableModel):
|
|||||||
return NONE
|
return NONE
|
||||||
|
|
||||||
def headerData(self, section, orientation, role):
|
def headerData(self, section, orientation, role):
|
||||||
if role == Qt.ToolTipRole:
|
|
||||||
return QVariant(_('The lookup/search name is "{0}"').format(self.column_map[section]))
|
|
||||||
if role != Qt.DisplayRole:
|
|
||||||
return NONE
|
|
||||||
if orientation == Qt.Horizontal:
|
if orientation == Qt.Horizontal:
|
||||||
return QVariant(self.headers[self.column_map[section]])
|
if section >= len(self.column_map): # same problem as in data, the column_map can be wrong
|
||||||
else:
|
return None
|
||||||
|
if role == Qt.ToolTipRole:
|
||||||
|
return QVariant(_('The lookup/search name is "{0}"').format(self.column_map[section]))
|
||||||
|
if role == Qt.DisplayRole:
|
||||||
|
return QVariant(self.headers[self.column_map[section]])
|
||||||
|
return NONE
|
||||||
|
if role == Qt.DisplayRole: # orientation is vertical
|
||||||
return QVariant(section+1)
|
return QVariant(section+1)
|
||||||
|
return NONE
|
||||||
|
|
||||||
|
|
||||||
def flags(self, index):
|
def flags(self, index):
|
||||||
flags = QAbstractTableModel.flags(self, index)
|
flags = QAbstractTableModel.flags(self, index)
|
||||||
|
@ -229,7 +229,8 @@ class TagsModel(QAbstractItemModel):
|
|||||||
def get_node_tree(self, sort):
|
def get_node_tree(self, sort):
|
||||||
self.row_map = []
|
self.row_map = []
|
||||||
self.categories = []
|
self.categories = []
|
||||||
self.cat_icon_map = self.cat_icon_map_orig[:-1] # strip the tags icon. We will put it back later
|
# strip the icons after the 'standard' categories. We will put them back later
|
||||||
|
self.cat_icon_map = self.cat_icon_map_orig[:self.tags_categories_start-len(self.row_map_orig)]
|
||||||
self.user_categories = dict.copy(config['user_categories'])
|
self.user_categories = dict.copy(config['user_categories'])
|
||||||
column_map = config['column_map']
|
column_map = config['column_map']
|
||||||
|
|
||||||
@ -261,7 +262,10 @@ class TagsModel(QAbstractItemModel):
|
|||||||
if name in taglist[label]: # use same node as the complete category
|
if name in taglist[label]: # use same node as the complete category
|
||||||
l.append(taglist[label][name])
|
l.append(taglist[label][name])
|
||||||
# else: do nothing, to eliminate nodes that have zero counts
|
# else: do nothing, to eliminate nodes that have zero counts
|
||||||
data[c+'*'] = sorted(l, cmp=(lambda x, y: cmp(x.name.lower(), y.name.lower())))
|
if config['sort_by_popularity']:
|
||||||
|
data[c+'*'] = sorted(l, cmp=(lambda x, y: cmp(x.count, y.count)))
|
||||||
|
else:
|
||||||
|
data[c+'*'] = sorted(l, cmp=(lambda x, y: cmp(x.name.lower(), y.name.lower())))
|
||||||
self.row_map.append(c+'*')
|
self.row_map.append(c+'*')
|
||||||
self.categories.append(c)
|
self.categories.append(c)
|
||||||
self.cat_icon_map.append(self.usercat_icon)
|
self.cat_icon_map.append(self.usercat_icon)
|
||||||
@ -418,14 +422,14 @@ class TagsModel(QAbstractItemModel):
|
|||||||
ans = []
|
ans = []
|
||||||
tags_seen = []
|
tags_seen = []
|
||||||
for i, key in enumerate(self.row_map):
|
for i, key in enumerate(self.row_map):
|
||||||
|
if key.endswith('*'): # User category, so skip it. The tag will be marked in its real category
|
||||||
|
continue
|
||||||
category_item = self.root_item.children[i]
|
category_item = self.root_item.children[i]
|
||||||
for tag_item in category_item.children:
|
for tag_item in category_item.children:
|
||||||
tag = tag_item.tag
|
tag = tag_item.tag
|
||||||
if tag.state > 0:
|
if tag.state > 0:
|
||||||
prefix = ' not ' if tag.state == 2 else ''
|
prefix = ' not ' if tag.state == 2 else ''
|
||||||
category = key if not key.endswith('*') and \
|
category = key if key != 'news' else 'tag'
|
||||||
key not in ['news', 'specialtags', 'normaltags'] \
|
|
||||||
else 'tag'
|
|
||||||
if category == 'tag':
|
if category == 'tag':
|
||||||
if tag.name in tags_seen:
|
if tag.name in tags_seen:
|
||||||
continue
|
continue
|
||||||
|
@ -650,7 +650,6 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
|
|||||||
v.resizeRowToContents(0)
|
v.resizeRowToContents(0)
|
||||||
height = v.rowHeight(0)
|
height = v.rowHeight(0)
|
||||||
self.library_view.verticalHeader().setDefaultSectionSize(height)
|
self.library_view.verticalHeader().setDefaultSectionSize(height)
|
||||||
print datetime.now()
|
|
||||||
|
|
||||||
def do_edit_categories(self):
|
def do_edit_categories(self):
|
||||||
d = TagCategories(self, self.library_view.model().db)
|
d = TagCategories(self, self.library_view.model().db)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user