From feaebe3524aa36083fed224fcd198e69125df528 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Tue, 20 Apr 2010 14:26:21 +0100 Subject: [PATCH] After testing, for submission --- .../dialogs/config/create_custom_column.py | 2 +- src/calibre/gui2/dialogs/tag_categories.py | 19 +++---- src/calibre/gui2/library.py | 49 ++++++++++++------- src/calibre/gui2/tag_view.py | 14 ++++-- src/calibre/gui2/ui.py | 1 - 5 files changed, 52 insertions(+), 33 deletions(-) diff --git a/src/calibre/gui2/dialogs/config/create_custom_column.py b/src/calibre/gui2/dialogs/config/create_custom_column.py index 0b6d15a2b5..b0f0fbcaac 100644 --- a/src/calibre/gui2/dialogs/config/create_custom_column.py +++ b/src/calibre/gui2/dialogs/config/create_custom_column.py @@ -75,7 +75,7 @@ class CreateCustomColumn(QDialog, Ui_QCreateCustomColumn): if col in self.standard_colnames: bad_col = True if bad_col: - self.parent.messagebox(_('The lookup name is already used')) + self.parent.messagebox(_('The lookup name %s is already used')%col) return bad_head = False for t in self.parent.custcols: diff --git a/src/calibre/gui2/dialogs/tag_categories.py b/src/calibre/gui2/dialogs/tag_categories.py index 74afc67242..dbba827cbe 100644 --- a/src/calibre/gui2/dialogs/tag_categories.py +++ b/src/calibre/gui2/dialogs/tag_categories.py @@ -146,15 +146,14 @@ class TagCategories(QDialog, Ui_TagCategories): return True def del_category(self): - if not confirm('

'+_('The current tag category will be ' - 'permanently deleted. Are you sure?') - +'

', 'tag_category_delete', self): - return if self.current_cat_name is not None: - if self.current_cat_name == unicode(self.category_box.currentText()): - del self.categories[self.current_cat_name] - self.current_category = None - self.category_box.removeItem(self.category_box.currentIndex()) + if not confirm('

'+_('The current tag category will be ' + 'permanently deleted. Are you sure?') + +'

', 'tag_category_delete', self): + 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): self.save_category() @@ -164,7 +163,9 @@ class TagCategories(QDialog, Ui_TagCategories): else: self.current_cat_name = None 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) def accept(self): diff --git a/src/calibre/gui2/library.py b/src/calibre/gui2/library.py index 2261e29479..58a9ac5ea9 100644 --- a/src/calibre/gui2/library.py +++ b/src/calibre/gui2/library.py @@ -300,13 +300,13 @@ class BooksModel(QAbstractTableModel): self.headers[i] = self.orig_headers[i] elif i in self.custom_columns: self.headers[i] = self.custom_columns[i]['name'] + self.build_data_convertors() self.reset() self.emit(SIGNAL('columns_sorted()')) def set_database(self, db): self.db = db self.custom_columns = self.db.custom_column_label_map - self.build_data_convertors() self.read_config() def refresh_ids(self, ids, current_row=-1): @@ -703,9 +703,9 @@ class BooksModel(QAbstractTableModel): def bool_type(r, idx=-1): 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] - if tweaks['bool_custom_columns_are_tristate'] == 'no': + if not bool_cols_are_tristate: if val is None or not val: return self.bool_no_icon if val: @@ -748,21 +748,32 @@ class BooksModel(QAbstractTableModel): self.dc[col] = functools.partial(datetime_type, idx=idx) elif datatype == 'bool': 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': self.dc[col] = functools.partial(rating_type, idx=idx) else: 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): - if role in (Qt.DisplayRole, Qt.EditRole): - return self.dc[self.column_map[index.column()]](index.row()) - elif role == Qt.DecorationRole: - if self.column_map[index.column()] in self.dc_decorator: - return self.dc_decorator[self.column_map[index.column()]](index.row()) + col = index.column() + # in obscure cases where custom columns are both edited and added, for a time + # the column map does not accurately represent the screen. In these cases, + # we will get asked to display columns we don't know about. Must test for this. + if col >= len(self.column_to_dc_map): return None - #elif role == Qt.SizeHintRole: - # return QVariant(Qt.SizeHint(1, 23)) + if role in (Qt.DisplayRole, Qt.EditRole): + 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'): # return QVariant(Qt.AlignVCenter | Qt.AlignCenter) #elif role == Qt.ToolTipRole and index.isValid(): @@ -771,14 +782,18 @@ class BooksModel(QAbstractTableModel): return NONE 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: - return QVariant(self.headers[self.column_map[section]]) - else: + if section >= len(self.column_map): # same problem as in data, the column_map can be wrong + 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 NONE + def flags(self, index): flags = QAbstractTableModel.flags(self, index) diff --git a/src/calibre/gui2/tag_view.py b/src/calibre/gui2/tag_view.py index f0764abb86..7d79fedb72 100644 --- a/src/calibre/gui2/tag_view.py +++ b/src/calibre/gui2/tag_view.py @@ -229,7 +229,8 @@ class TagsModel(QAbstractItemModel): def get_node_tree(self, sort): self.row_map = [] 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']) column_map = config['column_map'] @@ -261,7 +262,10 @@ class TagsModel(QAbstractItemModel): if name in taglist[label]: # use same node as the complete category l.append(taglist[label][name]) # 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.categories.append(c) self.cat_icon_map.append(self.usercat_icon) @@ -418,14 +422,14 @@ class TagsModel(QAbstractItemModel): ans = [] tags_seen = [] 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] for tag_item in category_item.children: tag = tag_item.tag if tag.state > 0: prefix = ' not ' if tag.state == 2 else '' - category = key if not key.endswith('*') and \ - key not in ['news', 'specialtags', 'normaltags'] \ - else 'tag' + category = key if key != 'news' else 'tag' if category == 'tag': if tag.name in tags_seen: continue diff --git a/src/calibre/gui2/ui.py b/src/calibre/gui2/ui.py index c1ff3ececd..d0ffad610c 100644 --- a/src/calibre/gui2/ui.py +++ b/src/calibre/gui2/ui.py @@ -650,7 +650,6 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI): v.resizeRowToContents(0) height = v.rowHeight(0) self.library_view.verticalHeader().setDefaultSectionSize(height) - print datetime.now() def do_edit_categories(self): d = TagCategories(self, self.library_view.model().db)