diff options
Diffstat (limited to 'tests/zoom_center.py')
-rw-r--r-- | tests/zoom_center.py | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/tests/zoom_center.py b/tests/zoom_center.py new file mode 100644 index 0000000..db96b04 --- /dev/null +++ b/tests/zoom_center.py @@ -0,0 +1,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() |