diff options
author | Manuel QuiƱones <manuq@laptop.org> | 2013-05-16 11:36:56 (GMT) |
---|---|---|
committer | Agustin Zubiaga <aguz@localhost.localdomain> | 2013-06-03 19:07:01 (GMT) |
commit | 8db37d787d4938d0f982c2676bfb4e52224afddd (patch) | |
tree | cd0e1e91c22ad1e49369c367feb7e6c0cb0a079b /ImageViewerActivity.py | |
parent | 7baddea12761f3c97095f4025f5999e07c366e14 (diff) |
Add drag by touch
Diffstat (limited to 'ImageViewerActivity.py')
-rw-r--r-- | ImageViewerActivity.py | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/ImageViewerActivity.py b/ImageViewerActivity.py index 78e5679..a72642e 100644 --- a/ImageViewerActivity.py +++ b/ImageViewerActivity.py @@ -28,6 +28,7 @@ import time import os import math from gi.repository import Gtk +from gi.repository import Gdk from gi.repository import GObject from sugar3.graphics.alert import NotifyAlert @@ -117,14 +118,21 @@ class ImageViewerActivity(activity.Activity): Gtk.PolicyType.ALWAYS) # Don't use the default kinetic scrolling, let the view do the - # pinch to zoom logic. + # drag-by-touch and pinch-to-zoom logic. self.scrolled_window.set_kinetic_scrolling(False) self.view = ImageView.ImageViewer() + + # Connect to the touch signal for performing drag-by-touch. + self.view.add_events(Gdk.EventMask.TOUCH_MASK) + self._touch_hid = self.view.connect('touch-event', + self.__touch_event_cb) self.scrolled_window.add_with_viewport(self.view) self.view.show() if GESTURES_AVAILABLE: + # Connect to the zoom signals for performing + # pinch-to-zoom. zoom_controller = SugarGestures.ZoomController() zoom_controller.attach(self, SugarGestures.EventControllerFlags.NONE) @@ -203,14 +211,28 @@ class ImageViewerActivity(activity.Activity): # Wait for a successful join before trying to get the document self.connect("joined", self._joined_cb) + def __touch_event_cb(self, widget, event): + coords = event.get_coords() + if event.type == Gdk.EventType.TOUCH_BEGIN: + self.view.start_dragtouch(coords) + elif event.type == Gdk.EventType.TOUCH_UPDATE: + self.view.update_dragtouch(coords) + elif event.type == Gdk.EventType.TOUCH_END: + self.view.finish_dragtouch(coords) + def __zoomtouch_began_cb(self, controller): self.view.start_zoomtouch(controller.get_center()) + # Don't listen to touch signals until pinch-to-zoom ends. + self.view.disconnect(self._touch_hid) + def __zoomtouch_changed_cb(self, controller, scale): self.view.update_zoomtouch(controller.get_center(), scale) def __zoomtouch_ended_cb(self, controller): self.view.finish_zoomtouch() + self._touch_hid = self.view.connect('touch-event', + self.__touch_event_cb) def _add_toolbar_buttons(self, toolbar_box): activity_button = ActivityToolbarButton(self) |