Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManuel Kaufmann <humitos@gmail.com>2012-10-18 13:02:26 (GMT)
committer Manuel Kaufmann <humitos@gmail.com>2012-10-18 13:02:26 (GMT)
commit6904b1fa4a99700f47cb2bce388c837c00aa195c (patch)
tree40ea083d22fa066bbea462d9e5731cde2d0db466
parent80c898e98dda3df4e6c2bcc6a674e403aa8b162c (diff)
New test for XO-4
https://dev.laptop.org/ticket/12212
-rw-r--r--tests/touch_test2.py65
1 files changed, 65 insertions, 0 deletions
diff --git a/tests/touch_test2.py b/tests/touch_test2.py
new file mode 100644
index 0000000..d5b43af
--- /dev/null
+++ b/tests/touch_test2.py
@@ -0,0 +1,65 @@
+#!/usr/bin/env python
+# Copyright (C) 2011, One Laptop Per Child
+# Author, Gonzalo Odiard <gonzalo@laptop.org>
+# Translated from c demo provided by Carlos Garnacho <carlos@lanedo.com>
+
+from gi.repository import Gtk
+from gi.repository import Gdk
+import math
+import logging
+
+
+class TestTouch(Gtk.DrawingArea):
+
+ def __init__(self):
+ self.touches = {}
+ super(TestTouch, self).__init__()
+ self.set_events(Gdk.EventMask.TOUCH_MASK)
+ self.add_events(Gdk.EventMask.BUTTON_PRESS_MASK)
+ self.add_events(Gdk.EventMask.BUTTON_RELEASE_MASK)
+ self.add_events(Gdk.EventMask.BUTTON_MOTION_MASK)
+ self.connect('draw', self.__draw_cb)
+ self.connect('event', self.__event_cb)
+
+ def __event_cb(self, widget, event):
+ if event.type in (Gdk.EventType.TOUCH_BEGIN,
+ Gdk.EventType.TOUCH_CANCEL, Gdk.EventType.TOUCH_END,
+ Gdk.EventType.TOUCH_UPDATE, Gdk.EventType.BUTTON_PRESS,
+ Gdk.EventType.BUTTON_RELEASE, Gdk.EventType.MOTION_NOTIFY):
+ x = event.get_coords()[1]
+ y = event.get_coords()[2]
+ seq = str(event.touch.sequence)
+ if seq == 'None':
+ return
+ logging.error('event type %s x %s y %s seq %s', event.type, x, y, seq)
+ if event.type in (Gdk.EventType.TOUCH_BEGIN,
+ Gdk.EventType.TOUCH_UPDATE, Gdk.EventType.BUTTON_PRESS,
+ Gdk.EventType.MOTION_NOTIFY):
+ self.touches[seq] = (x, y)
+ elif event.type in (Gdk.EventType.TOUCH_END,
+ Gdk.EventType.BUTTON_RELEASE):
+ del self.touches[seq]
+ self.queue_draw()
+
+ def __draw_cb(self, widget, ctx):
+ ctx.set_source_rgba(0.3, 0.3, 0.3, 0.7)
+ for touch in self.touches.values():
+ x, y = touch
+ ctx.save()
+ ctx.arc(x, y, 60, 0., 2 * math.pi)
+ ctx.fill()
+ ctx.restore()
+
+
+def main():
+ window = Gtk.Window()
+ test_touch = TestTouch()
+
+ window.add(test_touch)
+ window.connect("destroy", Gtk.main_quit)
+ window.show_all()
+ window.maximize()
+ Gtk.main()
+
+if __name__ == "__main__":
+ main()