[orca] Add support for Evolution's GUI



commit 243b46e064d1d6257efc7675fb733076ea275ec4
Author: Joanmarie Diggs <jdiggs igalia com>
Date:   Tue Jan 20 21:37:37 2015 -0500

    Add support for Evolution's GUI

 src/orca/script_utilities.py                       |   14 ++
 src/orca/scripts/apps/evolution/Makefile.am        |    7 +-
 .../scripts/apps/evolution/braille_generator.py    |   67 +++++++++++
 src/orca/scripts/apps/evolution/script.py          |   13 ++
 .../scripts/apps/evolution/script_utilities.py     |   49 ++++++++
 .../scripts/apps/evolution/speech_generator.py     |  125 ++++++++++++++++++++
 6 files changed, 273 insertions(+), 2 deletions(-)
---
diff --git a/src/orca/script_utilities.py b/src/orca/script_utilities.py
index 94bdb6c..db6ef92 100644
--- a/src/orca/script_utilities.py
+++ b/src/orca/script_utilities.py
@@ -2828,3 +2828,17 @@ class Utilities:
         index = self.cellIndex(obj)
         rowIndex = table.getRowAtIndex(index)
         return table.getRowHeader(rowIndex)
+
+    def coordinatesForCell(self, obj):
+        if not (obj and obj.getRole() == pyatspi.ROLE_TABLE_CELL):
+            return None
+
+        isTable = lambda x: x and 'Table' in pyatspi.listInterfaces(x)
+        parent = pyatspi.findAncestor(obj, isTable)
+        try:
+            table = parent.queryTable()
+        except:
+            return None
+
+        index = self.cellIndex(obj)
+        return table.getRowAtIndex(index), table.getColumnHeader(index)
diff --git a/src/orca/scripts/apps/evolution/Makefile.am b/src/orca/scripts/apps/evolution/Makefile.am
index 3bd7007..91ca74c 100644
--- a/src/orca/scripts/apps/evolution/Makefile.am
+++ b/src/orca/scripts/apps/evolution/Makefile.am
@@ -1,6 +1,9 @@
 orca_python_PYTHON = \
-    __init__.py \
-    script.py
+       __init__.py \
+       braille_generator.py \
+       script.py \
+       script_utilities.py \
+       speech_generator.py
 
 orca_pythondir=$(pkgpythondir)/scripts/apps/evolution
 
diff --git a/src/orca/scripts/apps/evolution/braille_generator.py 
b/src/orca/scripts/apps/evolution/braille_generator.py
new file mode 100644
index 0000000..56f7b1d
--- /dev/null
+++ b/src/orca/scripts/apps/evolution/braille_generator.py
@@ -0,0 +1,67 @@
+# Orca
+#
+# Copyright (C) 2015 Igalia, S.L.
+#
+# Author: Joanmarie Diggs <jdiggs igalia com>
+#
+# This library 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 Free Software Foundation; either
+# version 2.1 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser 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.
+
+__id__        = "$Id$"
+__version__   = "$Revision$"
+__date__      = "$Date$"
+__copyright__ = "Copyright (c) 2015 Igalia, S.L."
+__license__   = "LGPL"
+
+import orca.braille as braille
+import orca.scripts.toolkits.WebKitGtk as WebKitGtk
+
+class BrailleGenerator(WebKitGtk.BrailleGenerator):
+
+    def __init__(self, script):
+        super().__init__(script)
+        self._cache = {}
+
+    def _isMessageListToggleCell(self, obj):
+        cached = self._cache.get(hash(obj), {})
+        rv = cached.get("isMessageListToggleCell")
+        if rv == None:
+            rv = self._script.utilities.isMessageListToggleCell(obj)
+            cached["isMessageListToggleCell"] = rv
+            self._cache[hash(obj)] = cached
+
+        return rv
+
+    def _generateRealActiveDescendantDisplayedText(self, obj, **args):
+        if self._isMessageListToggleCell(obj):
+            return []
+
+        return super()._generateRealActiveDescendantDisplayedText(obj, **args)
+
+    def generateBraille(self, obj, **args):
+        self._cache = {}
+        result, focusedRegion = super().generateBraille(obj, **args)
+        self._cache = {}
+
+        if focusedRegion != result[0]:
+            return [result, focusedRegion]
+
+        hasObj = lambda x: isinstance(x, (braille.Component, braille.Text))
+        isObj = lambda x: self._script.utilities.isSameObject(obj, x.accessible)
+        matches = [r for r in result if hasObj(r) and isObj(r)]
+        if matches:
+            focusedRegion = matches[0]
+
+        return [result, focusedRegion]
diff --git a/src/orca/scripts/apps/evolution/script.py b/src/orca/scripts/apps/evolution/script.py
index 2b554a4..55e9f4f 100644
--- a/src/orca/scripts/apps/evolution/script.py
+++ b/src/orca/scripts/apps/evolution/script.py
@@ -33,6 +33,10 @@ import orca.scripts.toolkits.gtk as gtk
 import orca.scripts.toolkits.WebKitGtk as WebKitGtk
 import orca.settings as settings
 
+from .braille_generator import BrailleGenerator
+from .speech_generator import SpeechGenerator
+from .script_utilities import Utilities
+
 ########################################################################
 #                                                                      #
 # The Evolution script class.                                          #
@@ -51,6 +55,15 @@ class Script(WebKitGtk.Script):
         WebKitGtk.Script.__init__(self, app, False)
         self.presentIfInactive = False
 
+    def getBrailleGenerator(self):
+        return BrailleGenerator(self)
+
+    def getSpeechGenerator(self):
+        return SpeechGenerator(self)
+
+    def getUtilities(self):
+        return Utilities(self)
+
     def isActivatableEvent(self, event):
         """Returns True if the given event is one that should cause this
         script to become the active script.  This is only a hint to
diff --git a/src/orca/scripts/apps/evolution/script_utilities.py 
b/src/orca/scripts/apps/evolution/script_utilities.py
new file mode 100644
index 0000000..73e7bae
--- /dev/null
+++ b/src/orca/scripts/apps/evolution/script_utilities.py
@@ -0,0 +1,49 @@
+# Orca
+#
+# Copyright (C) 2015 Igalia, S.L.
+#
+# Author: Joanmarie Diggs <jdiggs igalia com>
+#
+# This library 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 Free Software Foundation; either
+# version 2.1 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser 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.
+
+__id__        = "$Id$"
+__version__   = "$Revision$"
+__date__      = "$Date$"
+__copyright__ = "Copyright (c) 2015 Igalia, S.L."
+__license__   = "LGPL"
+
+import pyatspi
+
+import orca.scripts.toolkits.gtk as gtk
+import orca.scripts.toolkits.WebKitGtk as WebKitGtk
+
+class Utilities(WebKitGtk.Utilities):
+
+    def __init__(self, script):
+        super().__init__(script)
+
+    def isMessageListToggleCell(self, obj):
+        if self.isWebKitGtk(obj):
+            return False
+
+        if not gtk.Utilities.hasMeaningfulToggleAction(self, obj):
+            return False
+
+        if not obj.name:
+            return False
+
+        header = self.columnHeaderForCell(obj)
+        return header and header.name == obj.name
diff --git a/src/orca/scripts/apps/evolution/speech_generator.py 
b/src/orca/scripts/apps/evolution/speech_generator.py
new file mode 100644
index 0000000..6250802
--- /dev/null
+++ b/src/orca/scripts/apps/evolution/speech_generator.py
@@ -0,0 +1,125 @@
+# Orca
+#
+# Copyright (C) 2015 Igalia, S.L.
+#
+# Author: Joanmarie Diggs <jdiggs igalia com>
+#
+# This library 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 Free Software Foundation; either
+# version 2.1 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser 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.
+
+__id__        = "$Id$"
+__version__   = "$Revision$"
+__date__      = "$Date$"
+__copyright__ = "Copyright (c) 2015 Igalia, S.L."
+__license__   = "LGPL"
+
+import pyatspi
+
+import orca.scripts.toolkits.WebKitGtk as WebKitGtk
+
+class SpeechGenerator(WebKitGtk.SpeechGenerator):
+
+    def __init__(self, script):
+        super().__init__(script)
+        self._cache = {}
+
+    def _isMessageListToggleCell(self, obj):
+        cached = self._cache.get(hash(obj), {})
+        rv = cached.get("isMessageListToggleCell")
+        if rv == None:
+            rv = self._script.utilities.isMessageListToggleCell(obj)
+            cached["isMessageListToggleCell"] = rv
+            self._cache[hash(obj)] = cached
+
+        return rv
+
+    def _isFocused(self, obj):
+        cached = self._cache.get(hash(obj), {})
+        rv = cached.get("isFocused")
+        if rv == None:
+            rv = obj.getState().contains(pyatspi.STATE_FOCUSED)
+            cached["isFocused"] = rv
+            self._cache[hash(obj)] = cached
+
+        return rv
+
+    def _isChecked(self, obj):
+        cached = self._cache.get(hash(obj), {})
+        rv = cached.get("isChecked")
+        if rv == None:
+            rv = obj.getState().contains(pyatspi.STATE_CHECKED)
+            cached["isChecked"] = rv
+            self._cache[hash(obj)] = cached
+
+        return rv
+
+    def _isInNewRow(self, obj):
+        cached = self._cache.get(hash(obj), {})
+        rv = cached.get("isInNewRow")
+        if rv == None:
+            row, column = self._script.utilities.coordinatesForCell(obj)
+            lastRow = self._script.pointOfReference.get("lastRow")
+            rv = row != lastRow
+            cached["isInNewRow"] = rv
+            self._cache[hash(obj)] = cached
+
+        return rv
+
+    def _generateCellCheckedState(self, obj, **args):
+        if self._isMessageListToggleCell(obj):
+            if self._isInNewRow(obj) or not self._isFocused(obj):
+                return []
+
+        return super()._generateCellCheckedState(obj, **args)
+
+    def _generateLabel(self, obj, **args):
+        if self._isMessageListToggleCell(obj):
+            return []
+
+        return super()._generateLabel(obj, **args)
+
+    def _generateName(self, obj, **args):
+        if self._isMessageListToggleCell(obj):
+            return []
+
+        return super()._generateName(obj, **args)
+
+    def _generateLabelOrName(self, obj, **args):
+        if self._isMessageListToggleCell(obj):
+            return []
+
+        return super()._generateLabelOrName(obj, **args)
+
+    def _generateRealActiveDescendantDisplayedText(self, obj, **args):
+        if self._isMessageListToggleCell(obj):
+            if not self._isChecked(obj):
+                return []
+            if self._isFocused(obj) and not self._isInNewRow(obj):
+                return []
+
+        return super()._generateRealActiveDescendantDisplayedText(obj, **args)
+
+    def _generateRoleName(self, obj, **args):
+        if self._isMessageListToggleCell(obj) and not self._isFocused(obj):
+            return []
+
+        return super()._generateRoleName(obj, **args)
+
+    def generateSpeech(self, obj, **args):
+        self._cache = {}
+        results = super().generateSpeech(obj, **args)
+        self._cache = {}
+
+        return results


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]