diff options
author | Gonzalo Odiard <godiard@gmail.com> | 2012-09-12 13:17:53 (GMT) |
---|---|---|
committer | Gonzalo Odiard <godiard@gmail.com> | 2012-09-12 13:17:53 (GMT) |
commit | 9fdd4fa2f168b1bd9d792f67d1466b682228f8a5 (patch) | |
tree | 45229c8f43bc2095daa5aa671189f7a8227808b8 /epubview | |
parent | 55d755ae8dfa6b2a27adeca6aaa62167cd894b58 (diff) |
Implement kindle like change page in epub backend
Signed-off-by: Gonzalo Odiard <gonzalo@laptop.org>
Diffstat (limited to 'epubview')
-rw-r--r-- | epubview/epubview.py | 14 | ||||
-rw-r--r-- | epubview/widgets.py | 22 |
2 files changed, 35 insertions, 1 deletions
diff --git a/epubview/epubview.py b/epubview/epubview.py index c7f7862..8b49881 100644 --- a/epubview/epubview.py +++ b/epubview/epubview.py @@ -91,6 +91,7 @@ class _View(Gtk.HBox): self._view_selection_changed_cb) self._view.connect_after('populate-popup', self._view_populate_popup_cb) + self._view.connect('touch-change-page', self.__touch_page_changed_cb) self._sw.add(self._view) self._v_vscrollbar = self._sw.get_vscrollbar() @@ -116,6 +117,12 @@ class _View(Gtk.HBox): self._view.set_can_default(True) self._view.set_can_focus(True) + def map_cp(widget): + widget.setup_touch() + widget.disconnect(self._setup_handle) + + self._setup_handle = self._view.connect('map', map_cp) + def set_document(self, epubdocumentinstance): ''' Sets document (should be a Epub instance) @@ -205,7 +212,6 @@ class _View(Gtk.HBox): """ self._v_vscrollbar.get_adjustment().set_value(position) - def can_zoom_in(self): ''' Returns True if it is possible to zoom in further @@ -317,6 +323,12 @@ class _View(Gtk.HBox): else: print ('Got unsupported scrolltype %s' % str(scrolltype)) + def __touch_page_changed_cb(self, widget, forward): + if forward: + self.scroll(Gtk.ScrollType.PAGE_FORWARD, False) + else: + self.scroll(Gtk.ScrollType.PAGE_BACKWARD, False) + def copy(self): ''' Copies the current selection to clipboard. diff --git a/epubview/widgets.py b/epubview/widgets.py index 4dc5846..54f7326 100644 --- a/epubview/widgets.py +++ b/epubview/widgets.py @@ -1,11 +1,33 @@ from gi.repository import WebKit +from gi.repository import Gdk +from gi.repository import GObject class _WebView(WebKit.WebView): + + __gsignals__ = { + 'touch-change-page': (GObject.SignalFlags.RUN_FIRST, GObject.TYPE_NONE, + ([bool])), + } + def __init__(self, only_to_measure=False): WebKit.WebView.__init__(self) self._only_to_measure = only_to_measure + def setup_touch(self): + self.get_window().set_events(self.get_window().get_events() | + Gdk.EventMask.TOUCH_MASK) + self.connect('event', self.__event_cb) + + def __event_cb(self, widget, event): + if event.type == Gdk.EventType.TOUCH_BEGIN: + x = event.touch.x + view_width = widget.get_allocation().width + if x > view_width * 3 / 4: + self.emit('touch-change-page', True) + elif x < view_width * 1 / 4: + self.emit('touch-change-page', False) + def get_page_height(self): ''' Gets height (in pixels) of loaded (X)HTML page. |