Ticket #4075: zoom_scaled_changed.py

File zoom_scaled_changed.py, 1.2 KB (added by humitos, 12 years ago)

Test case - works properly in XO-1.74 but XO-4

Line 
1#!/usr/bin/env python
2
3import math
4
5from gi.repository import Gtk
6from gi.repository import Gdk
7from gi.repository import SugarGestures
8
9
10class 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
42def 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
52if __name__ == "__main__":
53    main()