[orca/570658] Port Java script to the new speech generator
- From: William Walker <wwalker src gnome org>
- To: svn-commits-list gnome org
- Subject: [orca/570658] Port Java script to the new speech generator
- Date: Fri, 22 May 2009 16:50:28 -0400 (EDT)
commit 57662edd3057247b7b5e58a67b1d215f8d60ada1
Author: Willie Walker <william walker sun com>
Date: Fri May 22 16:49:40 2009 -0400
Port Java script to the new speech generator
---
.../toolkits/J2SE-access-bridge/Makefile.am | 1 +
.../toolkits/J2SE-access-bridge/formatting.py | 49 ++++++++
.../scripts/toolkits/J2SE-access-bridge/script.py | 9 +-
.../toolkits/J2SE-access-bridge/speechgenerator.py | 118 +++-----------------
src/orca/speechgenerator.py | 6 +-
5 files changed, 76 insertions(+), 107 deletions(-)
diff --git a/src/orca/scripts/toolkits/J2SE-access-bridge/Makefile.am b/src/orca/scripts/toolkits/J2SE-access-bridge/Makefile.am
index e9404a6..f39c230 100644
--- a/src/orca/scripts/toolkits/J2SE-access-bridge/Makefile.am
+++ b/src/orca/scripts/toolkits/J2SE-access-bridge/Makefile.am
@@ -3,6 +3,7 @@ orca_pathdir=$(pyexecdir)
orca_python_PYTHON = \
__init__.py \
braillegenerator.py \
+ formatting.py \
script.py \
speechgenerator.py \
where_am_I.py
diff --git a/src/orca/scripts/toolkits/J2SE-access-bridge/formatting.py b/src/orca/scripts/toolkits/J2SE-access-bridge/formatting.py
new file mode 100644
index 0000000..fe611ac
--- /dev/null
+++ b/src/orca/scripts/toolkits/J2SE-access-bridge/formatting.py
@@ -0,0 +1,49 @@
+# Orca
+#
+# Copyright 2006-2009 Sun Microsystems Inc.
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Library General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Library General Public License for more details.
+#
+# You should have received a copy of the GNU Library General Public
+# License along with this library; if not, write to the
+# Free Software Foundation, Inc., Franklin Street, Fifth Floor,
+# Boston MA 02110-1301 USA.
+
+"""Custom formatting for Java Swing."""
+
+__id__ = "$Id$"
+__version__ = "$Revision$"
+__date__ = "$Date$"
+__copyright__ = "Copyright (c) 2005-2009 Sun Microsystems Inc."
+__license__ = "LGPL"
+
+import pyatspi
+
+import orca.formatting
+
+# pylint: disable-msg=C0301
+
+formatting = {
+ 'speech': {
+ # In Java, tree objects are labels, so we need to look at their
+ # states in order to tell whether they are expanded or collapsed.
+ #
+ pyatspi.ROLE_LABEL: {
+ 'unfocused': '(displayedText or roleName) + expandableState',
+ 'focused': 'expandableState'
+ },
+ }
+}
+
+class Formatting(orca.formatting.Formatting):
+ def __init__(self, script):
+ orca.formatting.Formatting.__init__(self, script)
+ self.update(formatting)
diff --git a/src/orca/scripts/toolkits/J2SE-access-bridge/script.py b/src/orca/scripts/toolkits/J2SE-access-bridge/script.py
index 2aa815a..13a4c58 100644
--- a/src/orca/scripts/toolkits/J2SE-access-bridge/script.py
+++ b/src/orca/scripts/toolkits/J2SE-access-bridge/script.py
@@ -1,6 +1,6 @@
# Orca
#
-# Copyright 2006-2008 Sun Microsystems Inc.
+# Copyright 2006-2009 Sun Microsystems Inc.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
@@ -20,7 +20,7 @@
__id__ = "$Id$"
__version__ = "$Revision$"
__date__ = "$Date$"
-__copyright__ = "Copyright (c) 2005-2008 Sun Microsystems Inc."
+__copyright__ = "Copyright (c) 2005-2009 Sun Microsystems Inc."
__license__ = "LGPL"
import pyatspi
@@ -33,6 +33,7 @@ import orca.keybindings as keybindings
from braillegenerator import BrailleGenerator
from speechgenerator import SpeechGenerator
+from formatting import Formatting
from where_am_I import WhereAmI
########################################################################
@@ -66,6 +67,10 @@ class Script(default.Script):
"""
return SpeechGenerator(self)
+ def getFormatting(self):
+ """Returns the formatting strings for this script."""
+ return Formatting(self)
+
def consumesKeyboardEvent(self, keyboardEvent):
"""Called when a key is pressed on the keyboard.
diff --git a/src/orca/scripts/toolkits/J2SE-access-bridge/speechgenerator.py b/src/orca/scripts/toolkits/J2SE-access-bridge/speechgenerator.py
index 0152928..5261df3 100644
--- a/src/orca/scripts/toolkits/J2SE-access-bridge/speechgenerator.py
+++ b/src/orca/scripts/toolkits/J2SE-access-bridge/speechgenerator.py
@@ -1,6 +1,6 @@
# Orca
#
-# Copyright 2006-2008 Sun Microsystems Inc.
+# Copyright 2006-2009 Sun Microsystems Inc.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
@@ -20,16 +20,11 @@
__id__ = "$Id$"
__version__ = "$Revision$"
__date__ = "$Date$"
-__copyright__ = "Copyright (c) 2005-2008 Sun Microsystems Inc."
+__copyright__ = "Copyright (c) 2005-2009 Sun Microsystems Inc."
__license__ = "LGPL"
-import pyatspi
-
-import orca.rolenames as rolenames
import orca.speechgenerator as speechgenerator
-from orca.orca_i18n import _ # for gettext support
-
########################################################################
# #
# Speech Generator #
@@ -37,105 +32,20 @@ from orca.orca_i18n import _ # for gettext support
########################################################################
class SpeechGenerator(speechgenerator.SpeechGenerator):
- def __init__(self, script):
- speechgenerator.SpeechGenerator.__init__(self, script)
-
- def _getSpeechForLabel(self, obj, already_focused):
- """Get the speech for a label.
-
- Arguments:
- - obj: the label
- - already_focused: False if object just received focus
-
- Returns a list of utterances to be spoken for the object.
- """
-
- utterances = []
- if (not already_focused):
- text = self._script.getDisplayedText(obj)
- if not text:
- text = rolenames.getSpeechForRoleName(obj)
- if text:
- utterances.append(text)
-
- # In Java, tree objects are labels, so we need to look at their
- # states in order to tell whether they are expanded or collapsed.
- #
- state = obj.getState()
- if state.contains(pyatspi.STATE_EXPANDED):
- # Translators: this represents the state of a node in a tree.
- # 'expanded' means the children are showing.
- # 'collapsed' means the children are not showing.
- #
- utterances.append(_("expanded"))
- elif not state.contains(pyatspi.STATE_EXPANDED) and \
- state.contains(pyatspi.STATE_EXPANDABLE):
- # Translators: this represents the state of a node in a tree.
- # 'expanded' means the children are showing.
- # 'collapsed' means the children are not showing.
- #
- utterances.append(_("collapsed"))
-
- self._debugGenerator("J2SE-access-bridge:_getSpeechForLabel",
- obj,
- already_focused,
- utterances)
-
- return utterances
- def getSpeechContext(self, obj, stopAncestor=None):
- """This method is identical to speechgeneratior.getSpeechContext
- with one exception. The following test in
- speechgenerator.getSpeechContext:
+ # pylint: disable-msg=W0142
- if not text and 'Text' in pyatspi.listInterfaces(parent):
- text = self._script.getDisplayedText(parent)
-
- has be replaced by
-
- if not text:
- text = self._script.getDisplayedText(parent)
+ def __init__(self, script):
+ speechgenerator.SpeechGenerator.__init__(self, script)
- The Swing toolkit has labelled panels that do not implement the
- AccessibleText interface, but getDisplayedText returns
- a meaningful string that needs to be used if getDisplayedLabel
+ def _getAncestors(self, obj, **args):
+ """The Swing toolkit has labelled panels that do not implement the
+ AccessibleText interface, but getDisplayedText returns a
+ meaningful string that needs to be used if getDisplayedLabel
returns None.
"""
-
- utterances = []
-
- if not obj:
- return utterances
-
- if obj == stopAncestor:
- return utterances
-
- parent = obj.parent
- if parent \
- and (obj.getRole() == pyatspi.ROLE_TABLE_CELL) \
- and (parent.getRole() == pyatspi.ROLE_TABLE_CELL):
- parent = parent.parent
-
- while parent and (parent.parent != parent):
- if parent == stopAncestor:
- break
- if not self._script.isLayoutOnly(parent):
- text = self._script.getDisplayedLabel(parent)
- if not text and (parent.getRole() == pyatspi.ROLE_PANEL):
- text = self._script.getDisplayedText(parent)
- if text and len(text.strip()):
- # Push announcement of cell to the end
- #
- if parent.getRole() not in [pyatspi.ROLE_TABLE_CELL,
- pyatspi.ROLE_FILLER]:
- utterances.append(\
- rolenames.getSpeechForRoleName(parent))
- utterances.append(text)
- if parent.getRole() == pyatspi.ROLE_TABLE_CELL:
- utterances.append(\
- rolenames.getSpeechForRoleName(parent))
- parent = parent.parent
-
- utterances.reverse()
-
- return utterances
+ args['requireText'] = False
+ result = speechgenerator.SpeechGenerator._getAncestors(
+ self, obj, **args)
+ del args['requireText']
+ return result
diff --git a/src/orca/speechgenerator.py b/src/orca/speechgenerator.py
index 3ee983d..5427fe7 100644
--- a/src/orca/speechgenerator.py
+++ b/src/orca/speechgenerator.py
@@ -947,6 +947,7 @@ class SpeechGenerator:
def _getAncestors(self, obj, **args):
result = []
priorObj = args.get('priorObj', None)
+ requireText = args.get('requireText', True)
commonAncestor = self._script.findCommonAncestor(priorObj, obj)
if obj != commonAncestor:
parent = obj.parent
@@ -959,7 +960,10 @@ class SpeechGenerator:
break
if not self._script.isLayoutOnly(parent):
text = self._script.getDisplayedLabel(parent)
- if not text and 'Text' in pyatspi.listInterfaces(parent):
+ if not text \
+ and (not requireText \
+ or (requireText \
+ and 'Text' in pyatspi.listInterfaces(parent))):
text = self._script.getDisplayedText(parent)
if text and len(text.strip()):
# Push announcement of cell to the end
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]