[orca/570658] Start work on soffice braille generator



commit 8a6a1f26be9da779f3e8b4a473b7a058f781de09
Author: Willie Walker <william walker sun com>
Date:   Sat Jul 4 03:26:03 2009 -0400

    Start work on soffice braille generator

 src/orca/scripts/apps/soffice/braille_generator.py |   89 ++++++--------------
 src/orca/scripts/apps/soffice/formatting.py        |   18 ++++
 2 files changed, 44 insertions(+), 63 deletions(-)
---
diff --git a/src/orca/scripts/apps/soffice/braille_generator.py b/src/orca/scripts/apps/soffice/braille_generator.py
index 3fc5ec3..2da7e8b 100644
--- a/src/orca/scripts/apps/soffice/braille_generator.py
+++ b/src/orca/scripts/apps/soffice/braille_generator.py
@@ -40,49 +40,18 @@ class BrailleGenerator(braille_generator.BrailleGenerator):
     as the contents.
     """
 
+    # pylint: disable-msg=W0142
+
     def __init__(self, script):
         braille_generator.BrailleGenerator.__init__(self, script)
 
-    def _getTextForRole(self, obj, role=None):
-        if obj.getRole() == pyatspi.ROLE_DOCUMENT_FRAME \
-           or role == pyatspi.ROLE_DOCUMENT_FRAME:
-            return None
-
-        return braille_generator.BrailleGenerator.\
-            _getTextForRole(self, obj, role)
-
-    def _getBrailleRegionsForList(self, obj):
-        """Get the braille for a focused list.
-
-        Arguments:
-        - obj: the list
-
-        Returns a list where the first element is a list of Regions to
-        display and the second element is the Region which should get
-        focus.
-        """
-
-        self._debugGenerator("soffice: _getBrailleRegionsForList", obj)
-
-        if not obj.getState().contains(pyatspi.STATE_FOCUSABLE):
-            return braille_generator.BrailleGenerator.\
-                       _getBrailleRegionsForList(self, obj)
-
-        text = ""
-        label = self._script.getDisplayedLabel(obj)
-        if not label:
-            label = obj.name
-        if label and len(label):
-            text = self._script.appendString(text, label)
-
-        text = self._script.appendString(text, self._getTextForRole(obj))
-        text = self._script.appendString(text,
-                                         self._getTextForRequiredObject(obj))
-        regions = []
-        componentRegion = braille.Component(obj, text)
-        regions.append(componentRegion)
-
-        return [regions, componentRegion]
+    def _generateRoleName(self, obj, **args):
+        result = []
+        role = args.get('role', obj.getRole())
+        if role != pyatspi.ROLE_DOCUMENT_FRAME:
+            result.extend(braille_generator.BrailleGenerator._generateRoleName(
+                self, obj, **args))
+        return result
 
     def _getBrailleRegionsForTableCellRow(self, obj):
         """Get the braille for a table cell row or a single table cell
@@ -275,24 +244,11 @@ class BrailleGenerator(braille_generator.BrailleGenerator):
 
         return regions
 
-    def _getBrailleRegionsForScrollPane(self, obj):
-        """Get the braille for a scroll pane.
-
-        Arguments:
-        - obj: the scroll pane
-
-        Returns a list where the first element is a list of Regions to display
-        and the second element is the Region which should get focus.
+    def _generateChildTab(self, obj, **args):
+        """If we are in the slide presentation scroll pane, also announce the
+        current page tab. See bug #538056 for more details.
         """
-
-        self._debugGenerator("soffice: _getBrailleRegionsForScrollPane", obj)
-
-        scrollRegions = braille_generator.BrailleGenerator.\
-                               _getBrailleRegionsForScrollPane(self, obj)
-
-        # If we are in the slide presentation scroll pane, also announce
-        # the current page tab. See bug #538056 for more details.
-        #
+        result = []
         rolesList = [pyatspi.ROLE_SCROLL_PANE, \
                      pyatspi.ROLE_PANEL, \
                      pyatspi.ROLE_PANEL, \
@@ -305,9 +261,16 @@ class BrailleGenerator(braille_generator.BrailleGenerator):
                     for tab in child:
                         eventState = tab.getState()
                         if eventState.contains(pyatspi.STATE_SELECTED):
-                            tabRegions = self.getBrailleRegions(tab)
-                            tabRegions[0].append(braille.Region(" ")) 
-                            tabRegions[0].extend(scrollRegions[0])
-                            return tabRegions
-
-        return scrollRegions
+                            args['role'] = tab.getRole()
+                            result.extend(self.generate(tab, **args))
+        return result
+
+    def generateBraille(self, obj, **args):
+        result = []
+        args['useDefaultFormatting'] = \
+            ((obj.getRole() == pyatspi.ROLE_LIST) \
+                and (not obj.getState().contains(pyatspi.STATE_FOCUSABLE)))
+        result.extend(braille_generator.BrailleGenerator.\
+                          generateBraille(self, obj, **args))
+        del args['useDefaultFormatting']
+        return result
diff --git a/src/orca/scripts/apps/soffice/formatting.py b/src/orca/scripts/apps/soffice/formatting.py
index 8680714..4fffc2c 100644
--- a/src/orca/scripts/apps/soffice/formatting.py
+++ b/src/orca/scripts/apps/soffice/formatting.py
@@ -67,6 +67,17 @@ formatting = {
             #
             'basicWhereAmI': 'roleName + column + columnHeader + row + rowHeader + (textContent or spreadSheetCell) + anyTextSelection'
             },
+    },
+    'braille': {
+        pyatspi.ROLE_LIST: {
+            'unfocused': '[Component(obj,\
+                                     asString(labelOrName + roleName + required))]'
+        },
+        pyatspi.ROLE_SCROLL_PANE: {
+            'unfocused': 'asPageTabOrScrollPane\
+                          + (childTab\
+                             and ([Region(" ")] + childTab) or [])'
+        }
     }
 }
 
@@ -74,3 +85,10 @@ class Formatting(orca.formatting.Formatting):
     def __init__(self, script):
         orca.formatting.Formatting.__init__(self, script)
         self.update(copy.deepcopy(formatting))
+        self._defaultFormatting = orca.formatting.Formatting(script)
+
+    def getFormat(self, **args):
+        if args.get('useDefaultFormatting', False):
+            return self._defaultFormatting.getFormat(**args)
+        else:
+            return orca.formatting.Formatting.getFormat(self, **args)



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