From 21af1ee92c6c503727d5192383fb1fc23c03e129 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 18 Oct 2014 11:33:32 +0530 Subject: [PATCH] Nicer event debugging --- src/calibre/gui2/__init__.py | 7 +++++++ src/calibre/gui2/complete2.py | 12 ++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/calibre/gui2/__init__.py b/src/calibre/gui2/__init__.py index 314ca4ecc5..6968100026 100644 --- a/src/calibre/gui2/__init__.py +++ b/src/calibre/gui2/__init__.py @@ -1260,6 +1260,13 @@ _df = os.environ.get('CALIBRE_DEVELOP_FROM', None) if _df and os.path.exists(_df): build_forms(_df, check_for_migration=True) +def event_type_name(ev_or_etype): + from PyQt5.QtCore import QEvent + etype = ev_or_etype.type() if isinstance(ev_or_etype, QEvent) else ev_or_etype + for name, num in vars(QEvent).iteritems(): + if num == etype: + return name + return 'UnknownEventType' if islinux or isbsd: def workaround_broken_under_mouse(ch): diff --git a/src/calibre/gui2/complete2.py b/src/calibre/gui2/complete2.py index c5720a6a29..d63f3ad55d 100644 --- a/src/calibre/gui2/complete2.py +++ b/src/calibre/gui2/complete2.py @@ -10,7 +10,7 @@ __docformat__ = 'restructuredtext en' import weakref import sip -from PyQt5.Qt import (QLineEdit, QAbstractListModel, Qt, pyqtSignal, QObject, +from PyQt5.Qt import (QLineEdit, QAbstractListModel, Qt, pyqtSignal, QObject, QKeySequence, QApplication, QListView, QPoint, QModelIndex, QFont, QFontInfo, QTimer) from calibre.constants import isosx, get_osx_version @@ -191,6 +191,12 @@ class Completer(QListView): # {{{ self.setFont(f) p.show() + def debug_event(self, ev): + from calibre.gui2 import event_type_name + print ('Event:', event_type_name(ev)) + if ev.type() in (ev.KeyPress, ev.ShortcutOverride, ev.KeyRelease): + print ('\tkey:', QKeySequence(ev.key()).toString()) + def eventFilter(self, obj, e): 'Redirect key presses from the popup to the widget' widget = self.completer_widget() @@ -200,6 +206,8 @@ class Completer(QListView): # {{{ if obj is not self: return QObject.eventFilter(self, obj, e) + # self.debug_event(e) + if etype == e.KeyPress: key = e.key() if key == Qt.Key_Escape: @@ -245,7 +253,7 @@ class Completer(QListView): # {{{ if e.isAccepted(): return True elif isosx and etype == e.InputMethodQuery and e.queries() == (Qt.ImHints | Qt.ImEnabled) and self.isVisible(): - # In Qt 5 the Esc key cause this event and the line edit does not + # In Qt 5 the Esc key causes this event and the line edit does not # handle it, which causes the parent dialog to be closed # See https://bugreports.qt-project.org/browse/QTBUG-41806 e.accept()