diff --git a/src/calibre/gui2/__init__.py b/src/calibre/gui2/__init__.py index 771234691a..6527ad3f55 100644 --- a/src/calibre/gui2/__init__.py +++ b/src/calibre/gui2/__init__.py @@ -13,7 +13,7 @@ from PyQt4.Qt import (QVariant, QFileInfo, QObject, SIGNAL, QBuffer, Qt, ORG_NAME = 'KovidsBrain' APP_UID = 'libprs500' from calibre.constants import (islinux, iswindows, isbsd, isfrozen, isosx, - config_dir, filesystem_encoding) + plugins, config_dir, filesystem_encoding, DEBUG) from calibre.utils.config import Config, ConfigProxy, dynamic, JSONConfig from calibre.ebooks.metadata import MetaInformation from calibre.utils.date import UNDEFINED_DATE @@ -764,6 +764,7 @@ class Application(QApplication): if override_program_name: args = [override_program_name] + args[1:] qargs = [i.encode('utf-8') if isinstance(i, unicode) else i for i in args] + self.pi = plugins['progress_indicator'][0] QApplication.__init__(self, qargs) global gui_thread, qt_app gui_thread = QThread.currentThread() @@ -773,16 +774,26 @@ class Application(QApplication): self._file_open_paths = [] self._file_open_lock = RLock() self.setup_styles(force_calibre_style) + if DEBUG: + self.redirect_notify = True + + if DEBUG: + def notify(self, receiver, event): + if self.redirect_notify: + self.redirect_notify = False + return self.pi.do_notify(receiver, event) + else: + ret = QApplication.notify(self, receiver, event) + self.redirect_notify = True + return ret def load_calibre_style(self): # On OS X QtCurve resets the palette, so we preserve it explicitly orig_pal = QPalette(self.palette()) - from calibre.constants import plugins - pi = plugins['progress_indicator'][0] path = os.path.join(sys.extensions_location, 'calibre_style.'+( 'pyd' if iswindows else 'so')) - pi.load_style(path, 'Calibre') + self.pi.load_style(path, 'Calibre') # On OSX, on some machines, colors can be invalid. See https://bugs.launchpad.net/bugs/1014900 for role in (orig_pal.Button, orig_pal.Window): c = orig_pal.brush(role).color() diff --git a/src/calibre/gui2/progress_indicator/QProgressIndicator.cpp b/src/calibre/gui2/progress_indicator/QProgressIndicator.cpp index 64fd346674..bcd352d6be 100644 --- a/src/calibre/gui2/progress_indicator/QProgressIndicator.cpp +++ b/src/calibre/gui2/progress_indicator/QProgressIndicator.cpp @@ -5,6 +5,7 @@ #include #include #include +#include QProgressIndicator::QProgressIndicator(QWidget* parent, int size) : QWidget(parent), @@ -145,3 +146,16 @@ int load_style(QString &path, QString &name) { } return ret; } + +bool do_notify(QObject *receiver, QEvent *event) { + try { + return QApplication::instance()->notify(receiver, event); + } catch (std::exception& e) { + qCritical() << "C++ exception thrown in slot: " << e.what(); + } catch (...) { + qCritical() << "Unknown C++ exception thrown in slot"; + } + qCritical() << "Receiver name:" << receiver->objectName() << "Receiver class:" << receiver->metaObject()->className() << "Event type: " << event->type(); + return false; +} + diff --git a/src/calibre/gui2/progress_indicator/QProgressIndicator.h b/src/calibre/gui2/progress_indicator/QProgressIndicator.h index 0fd82a99f5..e228964dab 100644 --- a/src/calibre/gui2/progress_indicator/QProgressIndicator.h +++ b/src/calibre/gui2/progress_indicator/QProgressIndicator.h @@ -100,3 +100,5 @@ private: */ int load_style(QString &path, QString &name); +bool do_notify(QObject *receiver, QEvent *event); + diff --git a/src/calibre/gui2/progress_indicator/QProgressIndicator.sip b/src/calibre/gui2/progress_indicator/QProgressIndicator.sip index 03c6dacdd6..7789f52eac 100644 --- a/src/calibre/gui2/progress_indicator/QProgressIndicator.sip +++ b/src/calibre/gui2/progress_indicator/QProgressIndicator.sip @@ -8,6 +8,7 @@ %ModuleHeaderCode int load_style(QString &path, QString &name); +bool do_notify(QObject *receiver, QEvent *event); %End class QProgressIndicator : QWidget { @@ -57,3 +58,5 @@ protected: int load_style(QString &path, QString &name); +bool do_notify(QObject *receiver, QEvent *event); +