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
=== modified file 'windowmocker/plugins/qt.py'
--- windowmocker/plugins/qt.py 2013-04-22 23:31:05 +0000
+++ windowmocker/plugins/qt.py 2013-05-01 00:04:25 +0000
@@ -72,7 +72,76 @@
72 def _create_controls(self, control_spec):72 def _create_controls(self, control_spec):
73 if control_spec == 'TextEdit':73 if control_spec == 'TextEdit':
74 return QtGui.QTextEdit()74 return QtGui.QTextEdit()
75 elif control_spec == 'MouseTest':
76 return MouseTestWidget()
77
7578
7679
77 def run(self):80 def run(self):
78 self.app.exec_()81 self.app.exec_()
82
83
84class MouseTestWidget(QtGui.QWidget):
85
86 def __init__(self):
87 super(MouseTestWidget, self).__init__()
88 self.setAttribute(QtCore.Qt.WA_AcceptTouchEvents)
89 self.button_control = QtGui.QLabel(self)
90 self.button_control.setAttribute(QtCore.Qt.WA_AcceptTouchEvents)
91 self.button_control.setObjectName("button_status")
92 self.position_control = QtGui.QLabel(self)
93 self.position_control.setAttribute(QtCore.Qt.WA_AcceptTouchEvents)
94 self.position_control.setObjectName("position_status")
95 layout = QtGui.QVBoxLayout(self)
96 layout.addWidget(self.button_control)
97 layout.addWidget(self.position_control)
98
99 self.setMouseTracking(True)
100 self.button_control.setMouseTracking(True)
101 self.position_control.setMouseTracking(True)
102
103 def event(self, event):
104 if event.type() == QtCore.QEvent.TouchBegin:
105 self.touchBegin(event)
106 elif event.type() == QtCore.QEvent.TouchUpdate:
107 self.touchUpdate(event)
108 elif event.type() == QtCore.QEvent.TouchEnd:
109 self.touchEnd(event)
110 else:
111 return super(MouseTestWidget, self).event(event)
112 return True
113
114 def touchBegin(self, event):
115 self.button_control.setText("Touch Press")
116
117 def touchUpdate(self, event):
118 pass
119
120 def touchEnd(self, event):
121 self.button_control.setText("Touch Release")
122
123 def mousePressEvent(self, mouseEvent):
124 btn_name = self._get_button_string(mouseEvent.button())
125 self.button_control.setText("Press " + btn_name)
126
127 def mouseReleaseEvent(self, mouseEvent):
128 btn_name = self._get_button_string(mouseEvent.button())
129 self.button_control.setText("Release " + btn_name)
130
131 def mouseMoveEvent(self, mouseEvent):
132 pos = mouseEvent.globalPos()
133 self.position_control.setText("Position: ({}, {})".format(pos.x(), pos.y()))
134
135 def wheelEvent(self, wheelEvent):
136 direction = "down" if wheelEvent.delta() < 0 else "up"
137 self.button_control.setText("Wheel {}".format(direction))
138
139 def _get_button_string(self, btn):
140 if btn == QtCore.Qt.LeftButton:
141 return "Left"
142 elif btn == QtCore.Qt.RightButton:
143 return "Right"
144 elif btn == QtCore.Qt.MiddleButton:
145 return "Middle"
146 else:
147 return "Other"

Subscribers

People subscribed via source and target branches

to all changes: