Nicer event debugging

This commit is contained in:
Kovid Goyal 2014-10-18 11:33:32 +05:30
parent 6aa3d39e3b
commit 21af1ee92c
2 changed files with 17 additions and 2 deletions

View File

@ -1260,6 +1260,13 @@ _df = os.environ.get('CALIBRE_DEVELOP_FROM', None)
if _df and os.path.exists(_df): if _df and os.path.exists(_df):
build_forms(_df, check_for_migration=True) 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: if islinux or isbsd:
def workaround_broken_under_mouse(ch): def workaround_broken_under_mouse(ch):

View File

@ -10,7 +10,7 @@ __docformat__ = 'restructuredtext en'
import weakref import weakref
import sip 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) QApplication, QListView, QPoint, QModelIndex, QFont, QFontInfo, QTimer)
from calibre.constants import isosx, get_osx_version from calibre.constants import isosx, get_osx_version
@ -191,6 +191,12 @@ class Completer(QListView): # {{{
self.setFont(f) self.setFont(f)
p.show() 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): def eventFilter(self, obj, e):
'Redirect key presses from the popup to the widget' 'Redirect key presses from the popup to the widget'
widget = self.completer_widget() widget = self.completer_widget()
@ -200,6 +206,8 @@ class Completer(QListView): # {{{
if obj is not self: if obj is not self:
return QObject.eventFilter(self, obj, e) return QObject.eventFilter(self, obj, e)
# self.debug_event(e)
if etype == e.KeyPress: if etype == e.KeyPress:
key = e.key() key = e.key()
if key == Qt.Key_Escape: if key == Qt.Key_Escape:
@ -245,7 +253,7 @@ class Completer(QListView): # {{{
if e.isAccepted(): if e.isAccepted():
return True return True
elif isosx and etype == e.InputMethodQuery and e.queries() == (Qt.ImHints | Qt.ImEnabled) and self.isVisible(): 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 # handle it, which causes the parent dialog to be closed
# See https://bugreports.qt-project.org/browse/QTBUG-41806 # See https://bugreports.qt-project.org/browse/QTBUG-41806
e.accept() e.accept()