1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
#!/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
import random
COLORS = (0.1, 0.2, 0.3, 0.4)
class TestTouch(Gtk.DrawingArea):
def __init__(self):
super(TestTouch, self).__init__()
self.touch = None
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 == Gdk.EventType.TOUCH_BEGIN:
self.touch = 200, 200
self.queue_draw()
else:
self.touch = None
def __draw_cb(self, widget, ctx):
if self.touch is None:
return
for x in range(1, 10):
color = random.choice(COLORS)
ctx.set_source_rgba(color, color, color, 0.7)
ctx.save()
ctx.arc(x, y, 60 * x, 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.set_requested_size(400, 400)
Gtk.main()
if __name__ == "__main__":
main()
|