After testing, for submission

This commit is contained in:
Charles Haley 2010-04-20 14:26:21 +01:00
parent e3c9ebf283
commit feaebe3524
5 changed files with 52 additions and 33 deletions

View File

@ -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:

View File

@ -146,14 +146,13 @@ class TagCategories(QDialog, Ui_TagCategories):
return True
def del_category(self):
if self.current_cat_name is not None:
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 == unicode(self.category_box.currentText()):
del self.categories[self.current_cat_name]
self.current_category = None
self.current_cat_name = None
self.category_box.removeItem(self.category_box.currentIndex())
def select_category(self, idx):
@ -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):

View File

@ -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 orientation == Qt.Horizontal:
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 NONE
if orientation == Qt.Horizontal:
if role == Qt.DisplayRole:
return QVariant(self.headers[self.column_map[section]])
else:
return NONE
if role == Qt.DisplayRole: # orientation is vertical
return QVariant(section+1)
return NONE
def flags(self, index):
flags = QAbstractTableModel.flags(self, index)

View File

@ -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,6 +262,9 @@ 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
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)
@ -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

View File

@ -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)