From 715ebb3fd91d7fa1aef96b79170bf812692ce716 Mon Sep 17 00:00:00 2001 From: Eitan Isaacson Date: Fri, 27 Nov 2009 11:19:41 -0800 Subject: Put keyboard above text when at screen bottom. --- src/caribou.py | 6 +++--- src/keyboard.py | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/caribou.py b/src/caribou.py index 1e1abac..e03018f 100644 --- a/src/caribou.py +++ b/src/caribou.py @@ -41,7 +41,7 @@ class Test: def __set_text_location(self, acc): text = acc.queryText() [x, y, width, height] = text.getCharacterExtents(text.caretOffset, pyatspi.DESKTOP_COORDS) - cp.set_cursor_location(x, y + height) + cp.set_cursor_location(x, y, width, height) cp.show_all() def __set_entry_location(self, acc): @@ -50,9 +50,9 @@ class Test: if x == 0 and y == 0 and width == 0 and height == 0: component = acc.queryComponent() bb = component.getExtents(pyatspi.DESKTOP_COORDS) - cp.set_cursor_location(bb.x, bb.y + bb.height) + cp.set_cursor_location(bb.x, bb.y, bb.width, bb.height) else: - cp.set_cursor_location(x, y + height) + cp.set_cursor_location(x, y, width, height) cp.show_all() def on_state_changed_focused(self, event): diff --git a/src/keyboard.py b/src/keyboard.py index b67f88f..c9455ee 100644 --- a/src/keyboard.py +++ b/src/keyboard.py @@ -113,9 +113,9 @@ class CaribouWindow(gtk.VBox): self.__cursor_location = (0, 0) self.pack_start(CaribouKeyboard(qwerty)) - def set_cursor_location(self, x, y): #print "----> SET CURSOR LOCATION" - self.__cursor_location = (x, y) + def set_cursor_location(self, x, y, width, height): + self.__cursor_location = (x, y, width, height) self.__check_position() def do_size_request(self, requisition): @@ -137,9 +137,9 @@ class CaribouWindow(gtk.VBox): x = self.__cursor_location[0] if by > sy: - y = sy - self.__toplevel.allocation.height + y = self.__cursor_location[1] - self.__toplevel.allocation.height else: - y = self.__cursor_location[1] + y = self.__cursor_location[1] + self.__cursor_location[3] self.move(x, y) -- cgit v1.2.1 From 0d88cdf8b3c0ce0d2f711cd0a11255dc16eb7ef4 Mon Sep 17 00:00:00 2001 From: Eitan Isaacson Date: Mon, 30 Nov 2009 16:37:36 -0800 Subject: some bigger changes --- src/caribou.py | 8 +++--- src/keyboard.py | 77 +++++++++++++++++++++++++++++++++------------------------ 2 files changed, 49 insertions(+), 36 deletions(-) diff --git a/src/caribou.py b/src/caribou.py index e03018f..6ee1944 100644 --- a/src/caribou.py +++ b/src/caribou.py @@ -41,7 +41,7 @@ class Test: def __set_text_location(self, acc): text = acc.queryText() [x, y, width, height] = text.getCharacterExtents(text.caretOffset, pyatspi.DESKTOP_COORDS) - cp.set_cursor_location(x, y, width, height) + cp.cursor_location = gtk.gdk.Rectangle(x, y, width, height) cp.show_all() def __set_entry_location(self, acc): @@ -50,9 +50,9 @@ class Test: if x == 0 and y == 0 and width == 0 and height == 0: component = acc.queryComponent() bb = component.getExtents(pyatspi.DESKTOP_COORDS) - cp.set_cursor_location(bb.x, bb.y, bb.width, bb.height) + cp.cursor_location = gtk.gdk.Rectangle(bb.x, bb.y, bb.width, bb.height) else: - cp.set_cursor_location(x, y, width, height) + cp.cursor_location = gtk.gdk.Rectangle(x, y, width, height) cp.show_all() def on_state_changed_focused(self, event): @@ -160,7 +160,7 @@ if __name__ == "__main__": pyatspi.Registry.registerKeystrokeListener(test.on_key_down, mask = None, kind = (pyatspi.KEY_PRESSED_EVENT,)) # TODO: move text entry detection to its own file - cp = keyboard.CaribouWindow() + cp = keyboard.CaribouHoverWindow() cp.hide_all() gtk.main() diff --git a/src/keyboard.py b/src/keyboard.py index c9455ee..d7d290f 100644 --- a/src/keyboard.py +++ b/src/keyboard.py @@ -1,4 +1,4 @@ -# -*- coding: UTF-8 -*- +# -*- coding: utf-8 -*- # # Carbou - On-screen Keyboard and UI navigation application # @@ -100,62 +100,75 @@ class CaribouKeyboard(gtk.Frame): gobject.type_register(CaribouKeyboard) -class CaribouWindow(gtk.VBox): +class CaribouWindow(gtk.Window): __gtype_name__ = "CaribouWindow" def __init__(self): - super(CaribouWindow, self).__init__() + super(CaribouWindow, self).__init__(gtk.WINDOW_POPUP) self.set_name("CaribouWindow") - self.__toplevel = gtk.Window(gtk.WINDOW_POPUP) - self.__toplevel.add(self) - self.__toplevel.connect("size-allocate", lambda w, a: self.__check_position()) - self.__cursor_location = (0, 0) - self.pack_start(CaribouKeyboard(qwerty)) + self._vbox = gtk.VBox() + self.add(self._vbox) - #print "----> SET CURSOR LOCATION" - def set_cursor_location(self, x, y, width, height): - self.__cursor_location = (x, y, width, height) - self.__check_position() + self.connect("size-allocate", lambda w, a: self._update_position()) - def do_size_request(self, requisition): - #print "---->> DO SIZE REQUEST" - gtk.VBox.do_size_request(self, requisition) - self.__toplevel.resize(1, 1) + self._vbox.pack_start(CaribouKeyboard(qwerty)) - def __check_position(self): +class CaribouHoverWindow(CaribouWindow): + __gtype_name__ = "CaribouHoverWindow" + def __init__(self): + super(CaribouHoverWindow, self).__init__() + self._cursor_location = gtk.gdk.Rectangle() + + def _set_cursor_location(self, val): + self._cursor_location = val + self._update_position() + + def _get_cursor_location(self): + return self._cursor_location + + cursor_location = gobject.property(type=object, + setter=_set_cursor_location, + getter=_get_cursor_location) + + def _update_position(self): #print "---->>> CHECK POSITION" - bx = self.__cursor_location[0] + self.__toplevel.allocation.width - by = self.__cursor_location[1] + self.__toplevel.allocation.height + bx = self.cursor_location.x + self.allocation.width + by = self.cursor_location.y + self.allocation.height root_window = gdk.get_default_root_window() sx, sy = root_window.get_size() if bx > sx: - x = sx - self.__toplevel.allocation.width + x = sx - self.allocation.width else: - x = self.__cursor_location[0] + x = self.cursor_location.x if by > sy: - y = self.__cursor_location[1] - self.__toplevel.allocation.height + y = self.cursor_location.y - self.allocation.height else: - y = self.__cursor_location[1] + self.__cursor_location[3] + y = self.cursor_location.y + self.cursor_location.height self.move(x, y) - def show_all(self): - gtk.VBox.show_all(self) - self.__toplevel.show_all() +class CaribouKeyboardPlacement: + LEFT = 0 + RIGHT = 1 + TOP = 0 + BOTTOM = 1 + CENTER = 2 + + SCREEN = 0 + ENTRY = 1 + CURSOR = 2 - def hide_all(self): - gtk.VBox.hide_all(self) - self.__toplevel.hide_all() + INSIDE = 0 + OUTSIDE = 1 - def move(self, x, y): - self.__toplevel.move(x, y) + if __name__ == "__main__": - ckbd = CaribouWindow() + ckbd = CaribouHoverWindow() ckbd.show_all() gtk.main() -- cgit v1.2.1 From 6f172cc65a1c625a1204584f69e06034fccbaba2 Mon Sep 17 00:00:00 2001 From: Eitan Isaacson Date: Mon, 30 Nov 2009 17:45:54 -0800 Subject: The start of some placement code --- src/caribou.py | 6 ++-- src/keyboard.py | 110 +++++++++++++++++++++++++++++++++++--------------------- 2 files changed, 73 insertions(+), 43 deletions(-) diff --git a/src/caribou.py b/src/caribou.py index 6ee1944..e6a5bd5 100644 --- a/src/caribou.py +++ b/src/caribou.py @@ -41,7 +41,7 @@ class Test: def __set_text_location(self, acc): text = acc.queryText() [x, y, width, height] = text.getCharacterExtents(text.caretOffset, pyatspi.DESKTOP_COORDS) - cp.cursor_location = gtk.gdk.Rectangle(x, y, width, height) + cp.set_cursor_location(gtk.gdk.Rectangle(x, y, width, height)) cp.show_all() def __set_entry_location(self, acc): @@ -50,9 +50,9 @@ class Test: if x == 0 and y == 0 and width == 0 and height == 0: component = acc.queryComponent() bb = component.getExtents(pyatspi.DESKTOP_COORDS) - cp.cursor_location = gtk.gdk.Rectangle(bb.x, bb.y, bb.width, bb.height) + cp.set_cursor_location(gtk.gdk.Rectangle(bb.x, bb.y, bb.width, bb.height)) else: - cp.cursor_location = gtk.gdk.Rectangle(x, y, width, height) + cp.set_cursor_location(gtk.gdk.Rectangle(x, y, width, height)) cp.show_all() def on_state_changed_focused(self, event): diff --git a/src/keyboard.py b/src/keyboard.py index d7d290f..741d07f 100644 --- a/src/keyboard.py +++ b/src/keyboard.py @@ -110,62 +110,92 @@ class CaribouWindow(gtk.Window): self._vbox = gtk.VBox() self.add(self._vbox) - self.connect("size-allocate", lambda w, a: self._update_position()) - self._vbox.pack_start(CaribouKeyboard(qwerty)) class CaribouHoverWindow(CaribouWindow): __gtype_name__ = "CaribouHoverWindow" - def __init__(self): + + def __init__(self, default_placement=None): super(CaribouHoverWindow, self).__init__() + + self.connect("size-allocate", lambda w, a: self._update_position()) + self._cursor_location = gtk.gdk.Rectangle() + self._entry_location = gtk.gdk.Rectangle() + self._default_placement = default_placement or \ + CaribouKeyboardPlacement() + - def _set_cursor_location(self, val): - self._cursor_location = val + def set_cursor_location(self, cursor_location): + self._cursor_location = cursor_location self._update_position() - def _get_cursor_location(self): - return self._cursor_location - - cursor_location = gobject.property(type=object, - setter=_set_cursor_location, - getter=_get_cursor_location) + def set_entry_location(self, entry_location): + self._entry_location = entry_location + self._update_position() - def _update_position(self): - #print "---->>> CHECK POSITION" - bx = self.cursor_location.x + self.allocation.width - by = self.cursor_location.y + self.allocation.height + def set_default_placement(self, default_placement): + self._default_placement = default_placement + self._update_position() + def _get_root_bbox(self): root_window = gdk.get_default_root_window() - sx, sy = root_window.get_size() - - if bx > sx: - x = sx - self.allocation.width - else: - x = self.cursor_location.x - - if by > sy: - y = self.cursor_location.y - self.allocation.height - else: - y = self.cursor_location.y + self.cursor_location.height + args = root_window.get_position() + root_window.get_size() + return gdk.Rectangle(*args) + + def _update_position(self, placement=None): + placement = placement or self._default_placement + root_bbox = self._get_root_bbox() + bbox = root_bbox + + if placement.stickto == placement.CURSOR: + bbox = self._cursor_location + elif placement.stickto == placement.ENTRY: + bbox = self._entry_location + + x = bbox.x + y = bbox.y + + if placement.halign == placement.LEFT: + x += bbox.width + elif placement.halign == placement.CENTER: + x += bbox.width/2 + + if placement.valign == placement.BOTTOM: + y += bbox.height + elif placement.halign == placement.CENTER: + y += bbox.height/2 self.move(x, y) -class CaribouKeyboardPlacement: - LEFT = 0 - RIGHT = 1 - TOP = 0 - BOTTOM = 1 - CENTER = 2 - - SCREEN = 0 - ENTRY = 1 - CURSOR = 2 - - INSIDE = 0 - OUTSIDE = 1 - +class CaribouKeyboardPlacement(object): + LEFT = 'left' + RIGHT = 'right' + TOP = 'top' + BOTTOM = 'bottom' + CENTER = 'center' + + SCREEN = 'screen' + ENTRY = 'entry' + CURSOR = 'cursor' + + INSIDE = 'inside' + OUTSIDE = 'outside' + def __init__(self, halign=None, valign=None, stickto=None, + hgravitate=None, vgravitate=None): + self.halign = halign or self.LEFT + self.valign = valign or self.BOTTOM + self.stickto = stickto or self.CURSOR + self.hgravitate = hgravitate or self.OUTSIDE + self.vgravitate = vgravitate or self.OUTSIDE + + def copy(self, halign=None, valign=None, stickto=None, gravitate=None): + return self.__class__(halign or self.halign, + valign or self.valign, + stickto or self.stickto, + hgravitate or self.hgravitate, + vgravitate or self.vgravitate) if __name__ == "__main__": ckbd = CaribouHoverWindow() -- cgit v1.2.1 From 4649c851dbb1654429fd441daa5232e5866079a3 Mon Sep 17 00:00:00 2001 From: Eitan Isaacson Date: Mon, 30 Nov 2009 18:16:33 -0800 Subject: made an abstract axis as not to duplicate x and y code --- src/keyboard.py | 71 +++++++++++++++++++++++++++++++-------------------------- 1 file changed, 39 insertions(+), 32 deletions(-) diff --git a/src/keyboard.py b/src/keyboard.py index 741d07f..0c8dc2b 100644 --- a/src/keyboard.py +++ b/src/keyboard.py @@ -145,34 +145,33 @@ class CaribouHoverWindow(CaribouWindow): def _update_position(self, placement=None): placement = placement or self._default_placement + + x = self._calculate_axis(placement.x) + y = self._calculate_axis(placement.y) + + self.move(x, y) + + def _calculate_axis(self, axis_placement): root_bbox = self._get_root_bbox() bbox = root_bbox - if placement.stickto == placement.CURSOR: + if axis_placement.stickto == CaribouKeyboardPlacement.CURSOR: bbox = self._cursor_location - elif placement.stickto == placement.ENTRY: + elif axis_placement.stickto == CaribouKeyboardPlacement.ENTRY: bbox = self._entry_location - x = bbox.x - y = bbox.y - - if placement.halign == placement.LEFT: - x += bbox.width - elif placement.halign == placement.CENTER: - x += bbox.width/2 + offset = axis_placement.get_offset(bbox) - if placement.valign == placement.BOTTOM: - y += bbox.height - elif placement.halign == placement.CENTER: - y += bbox.height/2 + if axis_placement.align == CaribouKeyboardPlacement.END: + offset += axis_placement.get_length(bbox) + elif axis_placement.halign == CaribouKeyboardPlacement.CENTER: + offset += axis_placement.get_length(bbox)/2 - self.move(x, y) + return offset class CaribouKeyboardPlacement(object): - LEFT = 'left' - RIGHT = 'right' - TOP = 'top' - BOTTOM = 'bottom' + START = 'start' + END = 'end' CENTER = 'center' SCREEN = 'screen' @@ -182,20 +181,28 @@ class CaribouKeyboardPlacement(object): INSIDE = 'inside' OUTSIDE = 'outside' - def __init__(self, halign=None, valign=None, stickto=None, - hgravitate=None, vgravitate=None): - self.halign = halign or self.LEFT - self.valign = valign or self.BOTTOM - self.stickto = stickto or self.CURSOR - self.hgravitate = hgravitate or self.OUTSIDE - self.vgravitate = vgravitate or self.OUTSIDE - - def copy(self, halign=None, valign=None, stickto=None, gravitate=None): - return self.__class__(halign or self.halign, - valign or self.valign, - stickto or self.stickto, - hgravitate or self.hgravitate, - vgravitate or self.vgravitate) + class _AxisPlacement(object): + def __init__(self, axis, align=None, stickto=None, gravitate=None): + self.axis = axis + self.align = align or CaribouKeyboardPlacement.END + self.stickto = stickto or CaribouKeyboardPlacement.CURSOR + self.gravitate = gravitate or CaribouKeyboardPlacement.OUTSIDE + + def copy(self, align=None, stickto=None, gravitate=None): + return self.__class__(self.axis, + align or self.align, + stickto or self.stickto, + gravitate or self.gravitate) + + def get_offset(self, bbox): + return bbox.x if self.axis == 'x' else bbox.y + + def get_length(self, bbox): + return bbox.width if self.axis == 'x' else bbox.height + + def __init__(self, x=None, y=None): + self.x = x or self._AxisPlacement('x') + self.y = y or self._AxisPlacement('y') if __name__ == "__main__": ckbd = CaribouHoverWindow() -- cgit v1.2.1 From 7b04e086f744aa88939d8ab7b3c5f7573c7484fb Mon Sep 17 00:00:00 2001 From: Eitan Isaacson Date: Tue, 1 Dec 2009 14:16:48 -0800 Subject: Fixed more positioning things. --- src/caribou.py | 32 +++++++++++++++++++++++-------- src/keyboard.py | 58 +++++++++++++++++++++++++++++++++++++++++++++------------ 2 files changed, 70 insertions(+), 20 deletions(-) diff --git a/src/caribou.py b/src/caribou.py index e6a5bd5..f52f8d1 100644 --- a/src/caribou.py +++ b/src/caribou.py @@ -42,17 +42,27 @@ class Test: text = acc.queryText() [x, y, width, height] = text.getCharacterExtents(text.caretOffset, pyatspi.DESKTOP_COORDS) cp.set_cursor_location(gtk.gdk.Rectangle(x, y, width, height)) + + component = acc.queryComponent() + entry_bb = component.getExtents(pyatspi.DESKTOP_COORDS) + cp.set_entry_location(entry_bb) cp.show_all() def __set_entry_location(self, acc): text = acc.queryText() - [x, y, width, height] = text.getCharacterExtents(text.caretOffset, pyatspi.DESKTOP_COORDS) - if x == 0 and y == 0 and width == 0 and height == 0: - component = acc.queryComponent() - bb = component.getExtents(pyatspi.DESKTOP_COORDS) - cp.set_cursor_location(gtk.gdk.Rectangle(bb.x, bb.y, bb.width, bb.height)) - else: - cp.set_cursor_location(gtk.gdk.Rectangle(x, y, width, height)) + cursor_bb = gdk.Rectangle( + *text.getCharacterExtents(text.caretOffset, + pyatspi.DESKTOP_COORDS)) + + component = acc.queryComponent() + entry_bb = component.getExtents(pyatspi.DESKTOP_COORDS) + + if cursor_bb == gdk.Rectangle(0, 0, 0, 0): + cursor_bb = entry_bb + + cp.set_cursor_location(cursor_bb) + cp.set_entry_location(entry_bb) + cp.show_all() def on_state_changed_focused(self, event): @@ -160,7 +170,13 @@ if __name__ == "__main__": pyatspi.Registry.registerKeystrokeListener(test.on_key_down, mask = None, kind = (pyatspi.KEY_PRESSED_EVENT,)) # TODO: move text entry detection to its own file - cp = keyboard.CaribouHoverWindow() + placement = keyboard.CaribouKeyboardPlacement( + xalign=keyboard.CaribouKeyboardPlacement.START, + xstickto=keyboard.CaribouKeyboardPlacement.ENTRY, + ystickto=keyboard.CaribouKeyboardPlacement.ENTRY, + xgravitate=keyboard.CaribouKeyboardPlacement.INSIDE, + ygravitate=keyboard.CaribouKeyboardPlacement.INSIDE) + cp = keyboard.CaribouHoverWindow(placement) cp.hide_all() gtk.main() diff --git a/src/keyboard.py b/src/keyboard.py index 0c8dc2b..c132421 100644 --- a/src/keyboard.py +++ b/src/keyboard.py @@ -144,15 +144,21 @@ class CaribouHoverWindow(CaribouWindow): return gdk.Rectangle(*args) def _update_position(self, placement=None): + root_bbox = self._get_root_bbox() placement = placement or self._default_placement - x = self._calculate_axis(placement.x) - y = self._calculate_axis(placement.y) + x = self._calculate_axis(placement.x, root_bbox) + y = self._calculate_axis(placement.y, root_bbox) + + proposed_position = \ + gdk.Rectangle(x, y, self.allocation.width, self.allocation.height) + + x += placement.x.adjust_to_bounds(root_bbox, proposed_position) + y += placement.y.adjust_to_bounds(root_bbox, proposed_position) self.move(x, y) - def _calculate_axis(self, axis_placement): - root_bbox = self._get_root_bbox() + def _calculate_axis(self, axis_placement, root_bbox): bbox = root_bbox if axis_placement.stickto == CaribouKeyboardPlacement.CURSOR: @@ -164,7 +170,12 @@ class CaribouHoverWindow(CaribouWindow): if axis_placement.align == CaribouKeyboardPlacement.END: offset += axis_placement.get_length(bbox) - elif axis_placement.halign == CaribouKeyboardPlacement.CENTER: + if axis_placement.gravitate == CaribouKeyboardPlacement.INSIDE: + offset -= axis_placement.get_length(self.allocation) + elif axis_placement.align == CaribouKeyboardPlacement.START: + if axis_placement.gravitate == CaribouKeyboardPlacement.OUTSIDE: + offset -= axis_placement.get_length(self.allocation) + elif axis_placement.align == CaribouKeyboardPlacement.CENTER: offset += axis_placement.get_length(bbox)/2 return offset @@ -182,11 +193,11 @@ class CaribouKeyboardPlacement(object): OUTSIDE = 'outside' class _AxisPlacement(object): - def __init__(self, axis, align=None, stickto=None, gravitate=None): + def __init__(self, axis, align, stickto, gravitate): self.axis = axis - self.align = align or CaribouKeyboardPlacement.END - self.stickto = stickto or CaribouKeyboardPlacement.CURSOR - self.gravitate = gravitate or CaribouKeyboardPlacement.OUTSIDE + self.align = align + self.stickto = stickto + self.gravitate = gravitate def copy(self, align=None, stickto=None, gravitate=None): return self.__class__(self.axis, @@ -200,9 +211,32 @@ class CaribouKeyboardPlacement(object): def get_length(self, bbox): return bbox.width if self.axis == 'x' else bbox.height - def __init__(self, x=None, y=None): - self.x = x or self._AxisPlacement('x') - self.y = y or self._AxisPlacement('y') + def adjust_to_bounds(self, root_bbox, child_bbox): + child_vector_start = self.get_offset(child_bbox) + child_vector_end = self.get_length(child_bbox) + child_vector_start + root_vector_start = self.get_offset(root_bbox) + root_vector_end = self.get_length(root_bbox) + root_vector_start + + if root_vector_end < child_vector_end: + return root_vector_end - child_vector_end + + if root_vector_start > child_vector_start: + return root_vector_start - child_vector_start + + return 0 + + + def __init__(self, + xalign=None, xstickto=None, xgravitate=None, + yalign=None, ystickto=None, ygravitate=None): + self.x = self._AxisPlacement('x', + xalign or self.END, + xstickto or self.CURSOR, + xgravitate or self.OUTSIDE) + self.y = self._AxisPlacement('y', + yalign or self.END, + ystickto or self.CURSOR, + ygravitate or self.OUTSIDE) if __name__ == "__main__": ckbd = CaribouHoverWindow() -- cgit v1.2.1 From f543b33e104cc63892f056f44a32172b545a9509 Mon Sep 17 00:00:00 2001 From: Eitan Isaacson Date: Tue, 1 Dec 2009 16:07:15 -0800 Subject: seperate calculating position and moving --- src/keyboard.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/keyboard.py b/src/keyboard.py index c132421..0511c5f 100644 --- a/src/keyboard.py +++ b/src/keyboard.py @@ -143,7 +143,7 @@ class CaribouHoverWindow(CaribouWindow): args = root_window.get_position() + root_window.get_size() return gdk.Rectangle(*args) - def _update_position(self, placement=None): + def _calculate_position(self, placement=None): root_bbox = self._get_root_bbox() placement = placement or self._default_placement @@ -156,7 +156,10 @@ class CaribouHoverWindow(CaribouWindow): x += placement.x.adjust_to_bounds(root_bbox, proposed_position) y += placement.y.adjust_to_bounds(root_bbox, proposed_position) - self.move(x, y) + return x, y + + def _update_position(self): + self.move(*self._calculate_position()) def _calculate_axis(self, axis_placement, root_bbox): bbox = root_bbox -- cgit v1.2.1 From 774c558b98f11288d2ddfd18bb4e0127da62877e Mon Sep 17 00:00:00 2001 From: Eitan Isaacson Date: Wed, 2 Dec 2009 13:48:11 -0800 Subject: Made special CaribouWindowEntry class to demonstrate more sophisticated placement policies --- src/caribou.py | 9 ++------- src/keyboard.py | 52 +++++++++++++++++++++++++++++++++++----------------- 2 files changed, 37 insertions(+), 24 deletions(-) diff --git a/src/caribou.py b/src/caribou.py index 6c8c93b..bc5eb64 100644 --- a/src/caribou.py +++ b/src/caribou.py @@ -175,13 +175,8 @@ if __name__ == "__main__": pyatspi.Registry.registerKeystrokeListener(test.on_key_down, mask = None, kind = (pyatspi.KEY_PRESSED_EVENT,)) # TODO: move text entry detection to its own file - placement = keyboard.CaribouKeyboardPlacement( - xalign=keyboard.CaribouKeyboardPlacement.START, - xstickto=keyboard.CaribouKeyboardPlacement.ENTRY, - ystickto=keyboard.CaribouKeyboardPlacement.ENTRY, - xgravitate=keyboard.CaribouKeyboardPlacement.INSIDE, - ygravitate=keyboard.CaribouKeyboardPlacement.INSIDE) - cp = keyboard.CaribouHoverWindow(placement) + + cp = keyboard.CaribouWindowEntry() cp.hide_all() gtk.main() diff --git a/src/keyboard.py b/src/keyboard.py index b4943f3..ae0244c 100644 --- a/src/keyboard.py +++ b/src/keyboard.py @@ -130,20 +130,14 @@ gobject.type_register(CaribouKeyboard) class CaribouWindow(gtk.Window): __gtype_name__ = "CaribouWindow" - def __init__(self): + def __init__(self, default_placement=None): super(CaribouWindow, self).__init__(gtk.WINDOW_POPUP) self.set_name("CaribouWindow") self._vbox = gtk.VBox() self.add(self._vbox) - self._vbox.pack_start(CaribouKeyboard(qwerty)) - -class CaribouHoverWindow(CaribouWindow): - __gtype_name__ = "CaribouHoverWindow" - - def __init__(self, default_placement=None): - super(CaribouHoverWindow, self).__init__() + self._vbox.pack_start(CaribouKeyboard(qwerty)) self.connect("size-allocate", lambda w, a: self._update_position()) @@ -151,7 +145,6 @@ class CaribouHoverWindow(CaribouWindow): self._entry_location = gtk.gdk.Rectangle() self._default_placement = default_placement or \ CaribouKeyboardPlacement() - def set_cursor_location(self, cursor_location): self._cursor_location = cursor_location @@ -177,16 +170,18 @@ class CaribouHoverWindow(CaribouWindow): x = self._calculate_axis(placement.x, root_bbox) y = self._calculate_axis(placement.y, root_bbox) - proposed_position = \ - gdk.Rectangle(x, y, self.allocation.width, self.allocation.height) - - x += placement.x.adjust_to_bounds(root_bbox, proposed_position) - y += placement.y.adjust_to_bounds(root_bbox, proposed_position) - + return x, y def _update_position(self): - self.move(*self._calculate_position()) + x, y = self._calculate_position() + root_bbox = self._get_root_bbox() + proposed_position = \ + gdk.Rectangle(x, y, self.allocation.width, self.allocation.height) + + x += self._default_placement.x.adjust_to_bounds(root_bbox, proposed_position) + y += self._default_placement.y.adjust_to_bounds(root_bbox, proposed_position) + self.move(x, y) def _calculate_axis(self, axis_placement, root_bbox): bbox = root_bbox @@ -210,6 +205,29 @@ class CaribouHoverWindow(CaribouWindow): return offset +class CaribouWindowEntry(CaribouWindow): + __gtype_name__ = "CaribouWindowEntry" + + def __init__(self): + placement = CaribouKeyboardPlacement( + xalign=CaribouKeyboardPlacement.START, + xstickto=CaribouKeyboardPlacement.ENTRY, + ystickto=CaribouKeyboardPlacement.ENTRY, + xgravitate=CaribouKeyboardPlacement.INSIDE, + ygravitate=CaribouKeyboardPlacement.OUTSIDE) + + CaribouWindow.__init__(self, placement) + + def _calculate_axis(self, axis_placement, root_bbox): + offset = CaribouWindow._calculate_axis(self, axis_placement, root_bbox) + + if axis_placement.axis == 'y': + if offset + self.allocation.height > root_bbox.height + root_bbox.y: + new_axis_placement = axis_placement.copy(align=CaribouKeyboardPlacement.START) + offset = CaribouWindow._calculate_axis(self, new_axis_placement, root_bbox) + + return offset + class CaribouKeyboardPlacement(object): START = 'start' END = 'end' @@ -269,7 +287,7 @@ class CaribouKeyboardPlacement(object): ygravitate or self.OUTSIDE) if __name__ == "__main__": - ckbd = CaribouHoverWindow() + ckbd = CaribouWindow() ckbd.show_all() gtk.main() -- cgit v1.2.1 From b6810c2e374e3ca603dae0538dea3c39ca53edf0 Mon Sep 17 00:00:00 2001 From: Eitan Isaacson Date: Thu, 3 Dec 2009 10:13:28 -0800 Subject: Add gtk prefix to gdk.Rectangle symbol --- src/caribou.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/caribou.py b/src/caribou.py index bc5eb64..82bfaa6 100644 --- a/src/caribou.py +++ b/src/caribou.py @@ -50,14 +50,14 @@ class Test: def __set_entry_location(self, acc): text = acc.queryText() - cursor_bb = gdk.Rectangle( + cursor_bb = gtk.gdk.Rectangle( *text.getCharacterExtents(text.caretOffset, pyatspi.DESKTOP_COORDS)) component = acc.queryComponent() entry_bb = component.getExtents(pyatspi.DESKTOP_COORDS) - if cursor_bb == gdk.Rectangle(0, 0, 0, 0): + if cursor_bb == gtk.gdk.Rectangle(0, 0, 0, 0): cursor_bb = entry_bb cp.set_cursor_location(cursor_bb) -- cgit v1.2.1