Merge lp:~thomir-deactivatedaccount/window-mocker/add-mouse-test into lp:window-mocker

Proposed by Thomi Richards
Status: Merged
Approved by: Allan LeSage
Approved revision: 21
Merged at revision: 21
Proposed branch: lp:~thomir-deactivatedaccount/window-mocker/add-mouse-test
Merge into: lp:window-mocker
Diff against target: 80 lines (+69/-0)
1 file modified
windowmocker/plugins/qt.py (+69/-0)
To merge this branch: bzr merge lp:~thomir-deactivatedaccount/window-mocker/add-mouse-test
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Allan LeSage (community) Approve
Review via email: mp+161746@code.launchpad.net

Commit message

Add MouseTest content option.

Description of the change

This branch adds the MouseTest content id, which we use to test mouse and touch events in autopilot.

To post a comment you must log in.
Revision history for this message
Allan LeSage (allanlesage) wrote :

LGTM.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'windowmocker/plugins/qt.py'
2--- windowmocker/plugins/qt.py 2013-04-22 23:31:05 +0000
3+++ windowmocker/plugins/qt.py 2013-05-01 00:04:25 +0000
4@@ -72,7 +72,76 @@
5 def _create_controls(self, control_spec):
6 if control_spec == 'TextEdit':
7 return QtGui.QTextEdit()
8+ elif control_spec == 'MouseTest':
9+ return MouseTestWidget()
10+
11
12
13 def run(self):
14 self.app.exec_()
15+
16+
17+class MouseTestWidget(QtGui.QWidget):
18+
19+ def __init__(self):
20+ super(MouseTestWidget, self).__init__()
21+ self.setAttribute(QtCore.Qt.WA_AcceptTouchEvents)
22+ self.button_control = QtGui.QLabel(self)
23+ self.button_control.setAttribute(QtCore.Qt.WA_AcceptTouchEvents)
24+ self.button_control.setObjectName("button_status")
25+ self.position_control = QtGui.QLabel(self)
26+ self.position_control.setAttribute(QtCore.Qt.WA_AcceptTouchEvents)
27+ self.position_control.setObjectName("position_status")
28+ layout = QtGui.QVBoxLayout(self)
29+ layout.addWidget(self.button_control)
30+ layout.addWidget(self.position_control)
31+
32+ self.setMouseTracking(True)
33+ self.button_control.setMouseTracking(True)
34+ self.position_control.setMouseTracking(True)
35+
36+ def event(self, event):
37+ if event.type() == QtCore.QEvent.TouchBegin:
38+ self.touchBegin(event)
39+ elif event.type() == QtCore.QEvent.TouchUpdate:
40+ self.touchUpdate(event)
41+ elif event.type() == QtCore.QEvent.TouchEnd:
42+ self.touchEnd(event)
43+ else:
44+ return super(MouseTestWidget, self).event(event)
45+ return True
46+
47+ def touchBegin(self, event):
48+ self.button_control.setText("Touch Press")
49+
50+ def touchUpdate(self, event):
51+ pass
52+
53+ def touchEnd(self, event):
54+ self.button_control.setText("Touch Release")
55+
56+ def mousePressEvent(self, mouseEvent):
57+ btn_name = self._get_button_string(mouseEvent.button())
58+ self.button_control.setText("Press " + btn_name)
59+
60+ def mouseReleaseEvent(self, mouseEvent):
61+ btn_name = self._get_button_string(mouseEvent.button())
62+ self.button_control.setText("Release " + btn_name)
63+
64+ def mouseMoveEvent(self, mouseEvent):
65+ pos = mouseEvent.globalPos()
66+ self.position_control.setText("Position: ({}, {})".format(pos.x(), pos.y()))
67+
68+ def wheelEvent(self, wheelEvent):
69+ direction = "down" if wheelEvent.delta() < 0 else "up"
70+ self.button_control.setText("Wheel {}".format(direction))
71+
72+ def _get_button_string(self, btn):
73+ if btn == QtCore.Qt.LeftButton:
74+ return "Left"
75+ elif btn == QtCore.Qt.RightButton:
76+ return "Right"
77+ elif btn == QtCore.Qt.MiddleButton:
78+ return "Middle"
79+ else:
80+ return "Other"

Subscribers

People subscribed via source and target branches

to all changes: