From 64c423ba08c41c9073cdaf48932e10ad26cb3930 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 3 Apr 2010 15:21:53 +0530 Subject: [PATCH] Ensure Tag Browser recount is always called in the GUI thread. --- src/calibre/gui2/__init__.py | 5 +++++ src/calibre/gui2/tag_view.py | 5 ++++- src/calibre/gui2/ui.py | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/calibre/gui2/__init__.py b/src/calibre/gui2/__init__.py index 870414bc66..f467d5cc80 100644 --- a/src/calibre/gui2/__init__.py +++ b/src/calibre/gui2/__init__.py @@ -592,6 +592,11 @@ def is_ok_to_use_qt(): gui_thread = QThread.currentThread() return gui_thread is QThread.currentThread() +def is_gui_thread(): + global gui_thread + return gui_thread is QThread.currentThread() + + def find_forms(srcdir): base = os.path.join(srcdir, 'calibre', 'gui2') forms = [] diff --git a/src/calibre/gui2/tag_view.py b/src/calibre/gui2/tag_view.py index d174b41212..f4b94324fd 100644 --- a/src/calibre/gui2/tag_view.py +++ b/src/calibre/gui2/tag_view.py @@ -12,7 +12,7 @@ from itertools import izip from PyQt4.Qt import Qt, QTreeView, QApplication, \ QFont, SIGNAL, QSize, QIcon, QPoint, \ QAbstractItemModel, QVariant, QModelIndex -from calibre.gui2 import config, NONE +from calibre.gui2 import config, NONE, is_gui_thread, Dispatcher from calibre.utils.search_query_parser import saved_searches from calibre.library.database2 import Tag @@ -54,6 +54,9 @@ class TagsView(QTreeView): self.model().clear_state() def recount(self, *args): + if not is_gui_thread(): + # Re-call in GUI thread + return Dispatcher(self.recount)(*args) ci = self.currentIndex() if not ci.isValid(): ci = self.indexAt(QPoint(10, 10)) diff --git a/src/calibre/gui2/ui.py b/src/calibre/gui2/ui.py index 2ab91e585b..33ad97d827 100644 --- a/src/calibre/gui2/ui.py +++ b/src/calibre/gui2/ui.py @@ -536,7 +536,7 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI): self.connect(self.library_view.model(), SIGNAL('count_changed(int)'), self.location_view.count_changed) self.connect(self.library_view.model(), SIGNAL('count_changed(int)'), - self.tags_view.recount) + self.tags_view.recount, Qt.QueuedConnection) self.connect(self.search, SIGNAL('cleared()'), self.tags_view_clear) self.connect(self.saved_search, SIGNAL('changed()'), self.tags_view.recount, Qt.QueuedConnection) if not gprefs.get('quick_start_guide_added', False):