diff --git a/src/calibre/gui2/dialogs/tag_categories.py b/src/calibre/gui2/dialogs/tag_categories.py index 869068a4f8..e7884bfe75 100644 --- a/src/calibre/gui2/dialogs/tag_categories.py +++ b/src/calibre/gui2/dialogs/tag_categories.py @@ -71,12 +71,16 @@ class TagCategories(QDialog, Ui_TagCategories): for item,l in enumerate(self.categories[cat]): key = ':'.join([l[1], l[0]]) t = self.all_items_dict.get(key, None) - if t is None: - t = Item(name=l[0], label=l[1], index=len(self.all_items), - icon=category_icons[self.category_labels.index(l[1])], exists=False) - self.all_items.append(t) - self.all_items_dict[key] = t - l[2] = t.index + if l[1] in self.category_labels: + if t is None: + t = Item(name=l[0], label=l[1], index=len(self.all_items), + icon=category_icons[self.category_labels.index(l[1])], exists=False) + self.all_items.append(t) + self.all_items_dict[key] = t + l[2] = t.index + else: + # remove any references to a category that no longer exists + del self.categories[cat][item] self.all_items_sorted = sorted(self.all_items, cmp=lambda x,y: cmp(x.name.lower(), y.name.lower())) self.display_filtered_categories(0) diff --git a/src/calibre/gui2/library.py b/src/calibre/gui2/library.py index fa283d9032..c1a8057844 100644 --- a/src/calibre/gui2/library.py +++ b/src/calibre/gui2/library.py @@ -1077,7 +1077,7 @@ class BooksView(TableView): def connect_to_restriction_set(self, tv): QObject.connect(tv, SIGNAL('restriction_set(PyQt_PyObject)'), - self._model.set_search_restriction) + self._model.set_search_restriction) # must be synchronous (not queued) def connect_to_book_display(self, bd): QObject.connect(self._model, SIGNAL('new_bookdisplay_data(PyQt_PyObject)'), diff --git a/src/calibre/gui2/tag_view.py b/src/calibre/gui2/tag_view.py index c3088ba468..5cce38bd4f 100644 --- a/src/calibre/gui2/tag_view.py +++ b/src/calibre/gui2/tag_view.py @@ -64,10 +64,10 @@ class TagsView(QTreeView): if len(s) == 0: self.search_restriction = '' else: - self.search_restriction = unicode(s) + self.search_restriction = 'search:"%s"' % unicode(s).strip() self.model().set_search_restriction(self.search_restriction) - self.recount() self.emit(SIGNAL('restriction_set(PyQt_PyObject)'), self.search_restriction) + self.recount() # Must happen after the emission of the restriction_set signal self.emit(SIGNAL('tags_marked(PyQt_PyObject, PyQt_PyObject)'), self._model.tokens(), self.match_all) @@ -264,7 +264,7 @@ class TagsModel(QAbstractItemModel): for c in self.user_categories: l = [] for (name,label,ign) in self.user_categories[c]: - if name in taglist[label]: # use same node as the complete category + if label in taglist and 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']: diff --git a/src/calibre/library/caches.py b/src/calibre/library/caches.py index 59c8085d4b..dfa39ad869 100644 --- a/src/calibre/library/caches.py +++ b/src/calibre/library/caches.py @@ -543,4 +543,4 @@ class ResultCache(SearchQueryParser): return [] def set_search_restriction(self, s): - self.search_restriction = '' if not s else 'search:"%s"' % (s.strip()) + self.search_restriction = s