Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGonzalo Odiard <godiard@gmail.com>2012-06-28 03:30:30 (GMT)
committer Gonzalo Odiard <godiard@gmail.com>2012-06-28 03:30:30 (GMT)
commitae8b13ce4f570543a032adaad18b12b5112bc749 (patch)
treecb4477d813b4d5848873e97a793637ae9b698880
parentb7540688a5867e36402b0350b8a70bbe8e52eb5b (diff)
Test multi touch
Signed-off-by: Gonzalo Odiard <gonzalo@laptop.org>
-rw-r--r--touch_test.py55
1 files changed, 55 insertions, 0 deletions
diff --git a/touch_test.py b/touch_test.py
new file mode 100644
index 0000000..badf05f
--- /dev/null
+++ b/touch_test.py
@@ -0,0 +1,55 @@
+#!/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
+
+
+class TestTouch(Gtk.DrawingArea):
+
+ def __init__(self):
+ self.touches = {}
+ super(TestTouch, self).__init__()
+ self.set_events(Gdk.EventMask.TOUCH_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):
+ x = event.touch.x
+ y = event.touch.y
+ seq = str(event.touch.sequence)
+
+ if event.type in (Gdk.EventType.TOUCH_BEGIN,
+ Gdk.EventType.TOUCH_UPDATE):
+ self.touches[seq] = (x, y)
+ elif event.type == Gdk.EventType.TOUCH_END:
+ 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()
+ Gtk.main()
+
+if __name__ == "__main__":
+ main()