diff --git a/pyqttester.py b/pyqttester.py index 4c51e0a..8e01aa9 100755 --- a/pyqttester.py +++ b/pyqttester.py @@ -105,7 +105,9 @@ def parse_args(): parser_record.add_argument( '--events-include', metavar='REGEX', - default=r'MouseEvent,KeyEvent,CloseEvent', # TODO: add Drag, Focus, Hover ? + default=r'MouseEvent,KeyEvent,CloseEvent,FocusEvent,DragLeaveEvent,DragEnterEvent,HoverEvent,HideEvent,' + 'ShowEvent,StatusTipEvent,ResizeEvent,SocketNotifier,StatusTipEvent', # TODO: add Drag, Focus, Hover ? + #ChildEvent do not work' help='When recording, record only events that match the filter.') parser_record.add_argument( '--events-exclude', metavar='REGEX', @@ -408,7 +410,15 @@ def _serialize_value(cls, value, attr): value.y(), value.width(), value.height()) - # Perhaps it's an enum value from Qt namespace + if isinstance(value, (QtCore.QSize, QtCore.QSizeF)): + return 'QtCore.{}({}, {})'.format(type(value).__name__, + value.width(), + value.height()) + #if isinstance(value, (QtGui.QActionEvent)): + # return 'QtGui.{}({}, {}, {})'.format(type(value).__name__,value.parent(), value.type(), value.action(), value.before()) + + #if isinstance(value, (QtCore.QString)): + # return '{}()'.format(type(value).__name__) assert isinstance(Qt.LeftButton, int) if isinstance(value, int): s = cls._qenum_key(Qt, value) @@ -431,6 +441,19 @@ def _serialize_value(cls, value, attr): 'QKeyEvent': 'type key modifiers text isAutoRepeat count'.split(), 'QMoveEvent': 'pos oldPos'.split(), 'QCloseEvent': [], + 'QChildEvent' : 'type child'.split(), + 'QFocusEvent' : 'type reason'.split(), + 'QDragLeaveEvent' : [], + 'QDragEnterEvent' : 'point actions data buttons modifiers'.split(), + 'QHoverEvent' : 'type pos oldPos'.split(), #for qt4 + 'QPaintEvent' : 'paintRegion'.split(), + 'QHideEvent' : [], + 'QShowEvent' : [], + 'QStatusTipEvent' : 'tip'.split(), + 'QResizeEvent' : 'size oldSize'.split(), + 'QSocketNotifier' : 'socket type parent'.split(), #problem with QObject* parent + 'QActionEvent' : 'type action before'.split(), + 'QStatusTipEvent' : 'tip'.split(), } @classmethod @@ -646,6 +669,7 @@ class EventRecorder(_EventFilter): def __init__(self, file, events_include, events_exclude): super().__init__() self.file = file + self.spuscen = [] # Prepare the recorded events stack; # the first entry is the protocol version @@ -670,8 +694,10 @@ def eventFilter(self, obj, event): # Only process out-of-application, system (e.g. X11) events # if not event.spontaneous(): # return False + is_skipped = (not self.event_matches(type(event).__name__) or not isinstance(obj, QWidget)) # FIXME: This condition is too strict (QGraphicsItems are QOjects) + log_ = log.debug if is_skipped else log.info log_('Caught %s%s %s event (%s) on object %s', 'skipped' if is_skipped else 'recorded', @@ -692,6 +718,9 @@ def eventFilter(self, obj, event): serialized = self.resolver.getstate(obj, event) if serialized: self.events.append(serialized) + if is_skipped: + self.spuscen.append(EVENT_TYPE.get(event.type(), + 'Unknown(type=' + str(event.type()) + ')')) return False def close(self): @@ -702,6 +731,8 @@ def close(self): len(self.events) - SCENARIO_FORMAT_VERSION - 1, self.file.name) log.debug(self.events) + for i in set(self.spuscen): + log.info(i) class EventReplayer(_EventFilter): def __init__(self, file): diff --git a/setup.py b/setup.py old mode 100644 new mode 100755