From eb599d569fbd23d6438fb725533667d0d11903de Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Sun, 6 Jun 2010 09:59:15 +0100 Subject: [PATCH] Fix restriction count display on main UI. --- src/calibre/gui2/library/models.py | 5 +++-- src/calibre/gui2/search_box.py | 3 +++ src/calibre/gui2/tag_view.py | 2 -- src/calibre/gui2/ui.py | 26 +++++++++++++++++++++----- 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/calibre/gui2/library/models.py b/src/calibre/gui2/library/models.py index 48ce5bbc45..3ef3237369 100644 --- a/src/calibre/gui2/library/models.py +++ b/src/calibre/gui2/library/models.py @@ -214,19 +214,20 @@ class BooksModel(QAbstractTableModel): # {{{ self.count_changed() def search(self, text, refinement, reset=True): + initial_rowcount = self.rowCount(None) try: self.db.search(text) except ParseException: self.searched.emit(False) return self.last_search = text + final_rowcount = self.rowCount(None) if reset: self.clear_caches() self.reset() - if self.last_search: + if self.last_search or initial_rowcount != final_rowcount: self.searched.emit(True) - def sort(self, col, order, reset=True): if not self.db: return diff --git a/src/calibre/gui2/search_box.py b/src/calibre/gui2/search_box.py index d3059992bc..4c5d5d6817 100644 --- a/src/calibre/gui2/search_box.py +++ b/src/calibre/gui2/search_box.py @@ -99,6 +99,9 @@ class SearchBox2(QComboBox): def clear_to_help(self): self._in_a_search = False self.setEditText(self.help_text) + if self.timer is not None: # Turn off any timers that got started in setEditText + self.killTimer(self.timer) + self.timer = None self.line_edit.home(False) self.help_state = True self.line_edit.setStyleSheet( diff --git a/src/calibre/gui2/tag_view.py b/src/calibre/gui2/tag_view.py index 80f6bfa264..04c03ef877 100644 --- a/src/calibre/gui2/tag_view.py +++ b/src/calibre/gui2/tag_view.py @@ -76,8 +76,6 @@ class TagsView(QTreeView): # {{{ self.search_restriction = 'search:"%s"' % unicode(s).strip() self.model().set_search_restriction(self.search_restriction) self.restriction_set.emit(self.search_restriction) - self.recount() # Must happen after the emission of the restriction_set signal - self.tags_marked.emit(self._model.tokens(), self.match_all) def mouseReleaseEvent(self, event): # Swallow everything except leftButton so context menus work correctly diff --git a/src/calibre/gui2/ui.py b/src/calibre/gui2/ui.py index 7546e461d6..ad5234fca1 100644 --- a/src/calibre/gui2/ui.py +++ b/src/calibre/gui2/ui.py @@ -547,8 +547,7 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI): self.connect(self.edit_categories, SIGNAL('clicked()'), self.do_user_categories_edit) self.tags_view.set_database(db, self.tag_match, self.popularity, self.search_restriction) self.tags_view.tags_marked.connect(self.search.search_from_tags) - for x in (self.saved_search.clear_to_help, self.mark_restriction_set): - self.tags_view.restriction_set.connect(x) + self.tags_view.restriction_set.connect(self.mark_restriction_set) self.tags_view.tags_marked.connect(self.saved_search.clear_to_help) self.tags_view.tag_list_edit.connect(self.do_tags_list_edit) self.tags_view.user_category_edit.connect(self.do_user_categories_edit) @@ -866,15 +865,29 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI): def mark_restriction_set(self, r): self.restriction_in_effect = False if r is None or not r else True + # Set the count of books to -1 so that the next search knows to capture + # the count + self.restriction_count_of_books_in_view = -1 + self.saved_search.clear_to_help() + # Force a null search so that the restriction change is taken into + # account. As a side effect, this will clear the search box to empty + self.search.set_search_string('') def set_number_of_books_shown(self, compute_count): if self.current_view() == self.library_view and self.restriction_in_effect: if compute_count: self.restriction_count_of_books_in_view = self.current_view().row_count() + # tell the tag browser that counts might have changed + self.tags_view.recount() t = _("({0} of {1})").format(self.current_view().row_count(), self.restriction_count_of_books_in_view) self.search_count.setStyleSheet('QLabel { border-radius: 8px; background-color: yellow; }') else: # No restriction or not library view + if self.current_view() == self.library_view and compute_count: + # set the count to turn off future recounts + self.restriction_count_of_books_in_view = self.current_view().row_count() + # tell the tag browser that counts might have changed + self.tags_view.recount() if not self.search.in_a_search(): t = _("(all books)") else: @@ -884,18 +897,21 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI): self.search_count.setText(t) def search_box_cleared(self): - self.set_number_of_books_shown(compute_count=True) + self.set_number_of_books_shown(compute_count=False) self.tags_view.clear() self.saved_search.clear_to_help() def search_clear(self): - self.set_number_of_books_shown(compute_count=True) + self.set_number_of_books_shown(compute_count=False) self.search.clear() def search_done(self, view, ok): if view is self.current_view(): self.search.search_done(ok) - self.set_number_of_books_shown(compute_count=False) + if self.restriction_count_of_books_in_view < 0: + self.set_number_of_books_shown(compute_count=True) + else: + self.set_number_of_books_shown(compute_count=False) def sync_cf_to_listview(self, current, previous): if self.cover_flow_sync_flag and self.cover_flow.isVisible() and \