From 5dd0d42eab0b8d7973ec9c714101c08fe8e099ad Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Wed, 21 Nov 2012 15:10:42 +0000 Subject: 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 --- 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() diff --git a/widgets.py b/widgets.py index b4c68f8..38d062b 100644 --- a/widgets.py +++ b/widgets.py @@ -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 -- cgit v0.9.1