[caribou] Improve text detection code
- From: Benjamin Konrath <bkonrath src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [caribou] Improve text detection code
- Date: Mon, 14 Dec 2009 23:06:39 +0000 (UTC)
commit 346f4c2e849eecd4c637883d20d00225b9ca797a
Author: Willie Walker <william walker sun com>
Date: Mon Dec 14 18:00:45 2009 -0500
Improve text detection code
Add listening for focus events and add check if role is ROLE_PARAGRAPH or ROLE_TERMINAL. This allow Caribou to work with the terminal, OpenOffice and newly envoked windows/applications.
src/caribou.py | 26 +++++++++++++++++++-------
1 files changed, 19 insertions(+), 7 deletions(-)
---
diff --git a/src/caribou.py b/src/caribou.py
index e4f6e3f..55ffbe3 100644
--- a/src/caribou.py
+++ b/src/caribou.py
@@ -4,6 +4,8 @@
# Copyright (C) 2009 Adaptive Technology Resource Centre
# * Contributor: Ben Konrath <ben bagu org>
# Copyright (C) 2009 Eitan Isaacson <eitan monotonous org>
+# Copyright (C) 2009 Sun Microsystems, Inc.
+# * Contributor: Willie Walker <william walker sun com>
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by the
@@ -69,11 +71,13 @@ class Caribou:
caribouwindow.show_all()
- def on_state_changed_focused(self, event):
+ def on_focus(self, event):
acc = event.source
- if pyatspi.STATE_EDITABLE in acc.getState().getStates():
- if event.source_role == pyatspi.ROLE_TEXT:
- if event.detail1 == 1:
+ if pyatspi.STATE_EDITABLE in acc.getState().getStates() or event.source_role == pyatspi.ROLE_TERMINAL:
+ if event.source_role in (pyatspi.ROLE_TEXT,
+ pyatspi.ROLE_PARAGRAPH,
+ pyatspi.ROLE_TERMINAL):
+ if event.type.startswith("focus") or event.detail1 == 1:
self.__set_text_location(acc)
self.__current_acc = event.source
self.__set_location = self.__set_text_location
@@ -87,7 +91,7 @@ class Caribou:
print "leave text widget in", event.host_application.name
elif event.source_role == pyatspi.ROLE_ENTRY:
- if event.detail1 == 1:
+ if event.type.startswith("focus") or event.detail1 == 1:
self.__set_entry_location(acc)
self.__current_acc = event.source
self.__set_location = self.__set_entry_location
@@ -124,13 +128,20 @@ class Caribou:
print "OK"
else:
print "FAIL"
- result = pyatspi.Registry.deregisterEventListener(self.on_state_changed_focused, "object:state-changed:focused")
+ result = pyatspi.Registry.deregisterEventListener(self.on_focus, "object:state-changed:focused")
if debug == True:
print "deregisterEventListener - object:state-changed:focused ...",
if result == False:
print "OK"
else:
print "FAIL"
+ result = pyatspi.Registry.deregisterEventListener(self.on_focus, "focus")
+ if debug == True:
+ print "deregisterEventListener - focus ...",
+ if result == False:
+ print "OK"
+ else:
+ print "FAIL"
result = pyatspi.Registry.deregisterKeystrokeListener(self.on_key_down, mask=None, kind=(pyatspi.KEY_PRESSED_EVENT,))
if debug == True:
print "deregisterKeystrokeListener"
@@ -170,7 +181,8 @@ if __name__ == "__main__":
sys.exit(0)
caribou = Caribou()
- pyatspi.Registry.registerEventListener(caribou.on_state_changed_focused, "object:state-changed:focused")
+ pyatspi.Registry.registerEventListener(caribou.on_focus, "object:state-changed:focused")
+ pyatspi.Registry.registerEventListener(caribou.on_focus, "focus")
pyatspi.Registry.registerEventListener(caribou.on_text_caret_moved, "object:text-caret-moved")
pyatspi.Registry.registerKeystrokeListener(caribou.on_key_down, mask=None, kind=(pyatspi.KEY_PRESSED_EVENT,))
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]