1 | #!/usr/bin/env python |
---|
2 | |
---|
3 | import math |
---|
4 | |
---|
5 | from gi.repository import Gtk |
---|
6 | from gi.repository import Gdk |
---|
7 | from gi.repository import SugarGestures |
---|
8 | |
---|
9 | |
---|
10 | class TestTouch(Gtk.DrawingArea): |
---|
11 | |
---|
12 | def __init__(self): |
---|
13 | super(TestTouch, self).__init__() |
---|
14 | |
---|
15 | self.set_events(Gdk.EventMask.TOUCH_MASK) |
---|
16 | self.connect('draw', self.__draw_cb) |
---|
17 | |
---|
18 | self.touch = None |
---|
19 | |
---|
20 | zoom = SugarGestures.ZoomController() |
---|
21 | zoom.connect('scale-changed', self.__scale_changed_cb) |
---|
22 | zoom.attach(self, SugarGestures.EventControllerFlags.NONE) |
---|
23 | |
---|
24 | def __scale_changed_cb(self, controller, scale): |
---|
25 | print 'Scale:', scale |
---|
26 | if scale == 1.0: |
---|
27 | self.touch = (500, 250) |
---|
28 | else: |
---|
29 | self.touch = None |
---|
30 | self.queue_draw() |
---|
31 | |
---|
32 | def __draw_cb(self, widget, ctx): |
---|
33 | ctx.set_source_rgba(1, 0, 0, 0.7) |
---|
34 | if self.touch is not None: |
---|
35 | x, y = self.touch |
---|
36 | ctx.save() |
---|
37 | ctx.arc(x, y, 60, 0., 2 * math.pi) |
---|
38 | ctx.fill() |
---|
39 | ctx.restore() |
---|
40 | |
---|
41 | |
---|
42 | def main(): |
---|
43 | window = Gtk.Window() |
---|
44 | test_touch = TestTouch() |
---|
45 | |
---|
46 | window.add(test_touch) |
---|
47 | window.connect("destroy", Gtk.main_quit) |
---|
48 | window.show_all() |
---|
49 | window.set_size_request(1000, 500) |
---|
50 | Gtk.main() |
---|
51 | |
---|
52 | if __name__ == "__main__": |
---|
53 | main() |
---|