diff options
author | Carlos Garnacho <carlosg@gnome.org> | 2012-11-21 15:10:42 (GMT) |
---|---|---|
committer | Gonzalo Odiard <godiard@gmail.com> | 2012-11-27 19:15:29 (GMT) |
commit | 5dd0d42eab0b8d7973ec9c714101c08fe8e099ad (patch) | |
tree | d31f84004b3c6e15b9c10f70c141de8c92ec313e | |
parent | e681d00ed1e3b3bda36b286fb19503f4ef0725b6 (diff) |
Implement OSK resizing on the AbiWidget
A new class deriving from Abi.Widget has been added, this class
handles document view resizing, and ensures the cursor stays
visible after the resize.
Signed-off-by: Carlos Garnacho <carlosg@gnome.org>
-rw-r--r-- | AbiWordActivity.py | 3 | ||||
-rw-r--r-- | widgets.py | 60 |
2 files changed, 62 insertions, 1 deletions
diff --git a/AbiWordActivity.py b/AbiWordActivity.py index ccfec0e..8c75cd2 100644 --- a/AbiWordActivity.py +++ b/AbiWordActivity.py @@ -48,6 +48,7 @@ from toolbar import ListToolbar from toolbar import InsertToolbar from toolbar import ParagraphToolbar from widgets import ExportButtonFactory +from widgets import DocumentView from port import chooser import speech @@ -65,7 +66,7 @@ class AbiWordActivity(activity.Activity): os.chdir(os.path.expanduser('~')) # create our main abiword canvas - self.abiword_canvas = Abi.Widget() + self.abiword_canvas = DocumentView() self._shared_activity = None self._new_instance = True toolbar_box = ToolbarBox() @@ -18,6 +18,9 @@ import time from gettext import gettext as _ import logging +from gi.repository import Abi +from gi.repository import GLib + from sugar3.graphics.radiotoolbutton import RadioToolButton from sugar3.graphics.combobox import ComboBox from sugar3.graphics.palette import Palette @@ -247,3 +250,60 @@ class ExportButtonFactory(): datastore.write(fileObject, transfer_ownership=True) fileObject.destroy() del fileObject + + +class DocumentView(Abi.Widget): + + def __init__(self): + Abi.Widget.__init__(self) + self.connect('size-allocate', self.__size_allocate_cb) + self.connect('request-clear-area', self.__request_clear_area_cb) + self.connect('unset-clear-area', self.__unset_clear_area_cb) + self.osk_changed = False + self.dy = 0 + + def __shallow_move_cb(self): + self.moveto_right() + return False + + def __size_allocate_cb(self, widget, allocation): + self.set_allocation(allocation) + + if self.get_child() is not None: + child_allocation = allocation + child_allocation.y = 0 + child_allocation.x = 0 + child_allocation.height -= self.dy + self.get_child().size_allocate(allocation) + + if self.osk_changed is True: + self.moveto_left() + GLib.timeout_add(100, self.__shallow_move_cb) + self.osk_changed = False + + def __request_clear_area_cb(self, widget, clear, cursor): + allocation = widget.get_allocation() + allocation.x = 0 + allocation.y = 0 + allocation.x, allocation.y = \ + widget.get_window().get_root_coords(allocation.x, allocation.y) + + if clear.y > allocation.y + allocation.height or \ + clear.y + clear.height < allocation.y: + return False + + self.dy = allocation.y + allocation.height - clear.y + + # Ensure there's at least some room for the view + if self.dy > allocation.height - 80: + self.dy = 0 + return False + + self.osk_changed = True + self.queue_resize() + return True + + def __unset_clear_area_cb(self, widget, snap_back): + self.dy = 0 + self.queue_resize() + return True |