orca r4161 - in trunk: . src/orca src/orca/scripts/apps/soffice



Author: joanied
Date: Sat Sep  6 18:30:21 2008
New Revision: 4161
URL: http://svn.gnome.org/viewvc/orca?rev=4161&view=rev

Log:
* src/orca/scripts/apps/soffice/speech_generator.py:
  src/orca/scripts/apps/soffice/where_am_i.py:
  src/orca/speechgenerator.py:
  src/orca/where_am_I.py:
  Fix for bug #515923 - 'Area' labels of Calc Headers/Footers
  dialog not always announced.


Modified:
   trunk/ChangeLog
   trunk/src/orca/scripts/apps/soffice/speech_generator.py
   trunk/src/orca/scripts/apps/soffice/where_am_i.py
   trunk/src/orca/speechgenerator.py
   trunk/src/orca/where_am_I.py

Modified: trunk/src/orca/scripts/apps/soffice/speech_generator.py
==============================================================================
--- trunk/src/orca/scripts/apps/soffice/speech_generator.py	(original)
+++ trunk/src/orca/scripts/apps/soffice/speech_generator.py	Sat Sep  6 18:30:21 2008
@@ -52,6 +52,17 @@
     def __init__(self, script):
         speechgenerator.SpeechGenerator.__init__(self, script)
 
+    def getSpeechForObjectRole(self, obj, role=None):
+        if obj.getRoleName() == "text frame" \
+           or (obj.getRole() == pyatspi.ROLE_PARAGRAPH \
+               and self._script.getAncestor(obj,
+                                            [pyatspi.ROLE_DIALOG],
+                                            [pyatspi.ROLE_APPLICATION])):
+            role = pyatspi.ROLE_TEXT
+            
+        return speechgenerator.SpeechGenerator.\
+            getSpeechForObjectRole(self, obj, role)
+
     def _getSpeechForComboBox(self, obj, already_focused):
         """Get the speech for a combo box. If the combo box already has focus,
         then only the selection is spoken.
@@ -289,6 +300,49 @@
 
         return utterances
 
+    def _getSpeechForText(self, obj, already_focused):
+        """Get the speech for a paragraph which is serving as a text object
+        in a dialog.
+
+        Arguments:
+        - obj: the text component
+        - already_focused: False if object just received focus
+
+        Returns a list of utterances to be spoken for the object.
+        """
+
+        utterances = []
+        if obj.getRole() == pyatspi.ROLE_PARAGRAPH \
+           and self._script.getAncestor(obj,
+                                        [pyatspi.ROLE_DIALOG],
+                                        [pyatspi.ROLE_APPLICATION]):
+            utterances.extend(self._getSpeechForObjectLabel(obj))
+            if len(utterances) == 0 and obj.parent:
+                parentLabel = self._getSpeechForObjectLabel(obj.parent)
+                # If we aren't already focused, we will have spoken the
+                # parent as part of the speech context and do not want
+                # to repeat it.
+                #
+                if already_focused:
+                    utterances.extend(parentLabel)
+                # If we still don't have a label, look to the name.
+                #
+                if not parentLabel and obj.name and len(obj.name):
+                    utterances.append(obj.name)
+
+            utterances.append(self._script.getTextLineAtCaret(obj)[0])
+            utterances.extend(self._getSpeechForAllTextSelection(obj))
+
+            self._debugGenerator("soffice _getSpeechForText",
+                                 obj,
+                                 already_focused,
+                                 utterances)
+        else:
+            utterances.extend(speechgenerator.SpeechGenerator.\
+                _getSpeechForText(self, obj, already_focused))
+
+        return utterances
+
     def _getSpeechForToggleButton(self, obj, already_focused):
         """Get the speech for a toggle button.  We always want to speak the
         state if it's on a toolbar.

Modified: trunk/src/orca/scripts/apps/soffice/where_am_i.py
==============================================================================
--- trunk/src/orca/scripts/apps/soffice/where_am_i.py	(original)
+++ trunk/src/orca/scripts/apps/soffice/where_am_i.py	Sat Sep  6 18:30:21 2008
@@ -136,6 +136,8 @@
             self._speakCalc(obj, basicOnly)
         elif top and top.name.endswith(" Writer"):
             self._speakText(obj, basicOnly)
+        else:
+            where_am_I.WhereAmI._speakParagraph(self, obj, basicOnly)
 
     def _speakCalc(self, obj, basicOnly):
         """Speak a OpenOffice Calc cell.
@@ -251,3 +253,36 @@
         debug.println(self._debugLevel,
                       "Calc status bar utterances=%s" % utterances)
         speech.speakUtterances(utterances)
+
+    def _getObjLabel(self, obj):
+        """Returns the label to speak for an object.
+        """
+
+        label = self._script.getDisplayedLabel(obj) or ""
+        if not label and obj.getRole() == pyatspi.ROLE_PARAGRAPH \
+           and self._script.getAncestor(obj,
+                                        [pyatspi.ROLE_DIALOG],
+                                        [pyatspi.ROLE_APPLICATION]):
+            label = self._script.getDisplayedLabel(obj.parent) or ""
+
+        return label.strip()
+
+    def _speakObjDescription(self, obj):
+        """Speaks the object's description if it is not the same as
+        the object's name and displayed contents.
+        """
+
+        if not obj.description:
+            return
+
+        # The descriptions of some OOo paragraphs consists of the name and
+        # the displayed text, with punctuation added. Try to spot this and,
+        # if found, ignore the description.
+        #
+        text = self._script.getDisplayedText(obj) or ""
+        desc = obj.description.replace(text, "")
+        for item in obj.name.split():
+            desc = desc.replace(item, "")
+        for char in desc.decode("UTF-8").strip():
+            if char.isalnum():
+                return where_am_I.WhereAmI._speakObjDescription(self, obj)

Modified: trunk/src/orca/speechgenerator.py
==============================================================================
--- trunk/src/orca/speechgenerator.py	(original)
+++ trunk/src/orca/speechgenerator.py	Sat Sep  6 18:30:21 2008
@@ -1867,12 +1867,11 @@
                     #
                     if parent.getRole() not in [pyatspi.ROLE_TABLE_CELL,
                                                 pyatspi.ROLE_FILLER]:
-                        utterances.append(\
-                            rolenames.getSpeechForRoleName(parent))
+                        utterances.extend(self.getSpeechForObjectRole(parent))
                     utterances.append(text)
                     if parent.getRole() == pyatspi.ROLE_TABLE_CELL:
-                        utterances.append(\
-                            rolenames.getSpeechForRoleName(parent))
+                        utterances.extend(self.getSpeechForObjectRole(parent))
+
             parent = parent.parent
 
         utterances.reverse()

Modified: trunk/src/orca/where_am_I.py
==============================================================================
--- trunk/src/orca/where_am_I.py	(original)
+++ trunk/src/orca/where_am_I.py	Sat Sep  6 18:30:21 2008
@@ -28,7 +28,6 @@
 import pyatspi
 import debug
 import orca_state
-import rolenames
 import settings
 import speech
 import text_attribute_names
@@ -173,7 +172,7 @@
 
         utterances = []
         text = self.getObjLabelAndName(obj) + " " + \
-               rolenames.getSpeechForRoleName(obj)
+               self._getSpeechForRoleName(obj)
         text = text + " " + self._getCheckBoxState(obj)
         utterances.append(text)
 
@@ -213,7 +212,7 @@
             utterances.append(text)
 
         text = self.getObjLabelAndName(obj) + " " + \
-               rolenames.getSpeechForRoleName(obj)
+               self._getSpeechForRoleName(obj)
         utterances.append(text)
 
         state = obj.getState()
@@ -263,7 +262,7 @@
         text = self._getObjLabel(obj)
         utterances.append(text)
 
-        text = rolenames.getSpeechForRoleName(obj)
+        text = self._getSpeechForRoleName(obj)
         utterances.append(text)
 
         name = self._getObjName(obj)
@@ -299,7 +298,7 @@
         label = self._getObjLabel(obj)
         utterances.append(label)
 
-        text = rolenames.getSpeechForRoleName(obj)
+        text = self._getSpeechForRoleName(obj)
         utterances.append(text)
 
         name = self._getObjName(obj)
@@ -336,7 +335,7 @@
         text = self.getObjLabelAndName(obj)
         utterances.append(text)
 
-        text = rolenames.getSpeechForRoleName(obj)
+        text = self._getSpeechForRoleName(obj)
         utterances.append(text)
 
         text = self._getObjAccelerator(obj)
@@ -365,7 +364,7 @@
         text = self._getObjLabel(obj)
         utterances.append(text)
 
-        text = rolenames.getSpeechForRoleName(obj)
+        text = self._getSpeechForRoleName(obj)
         utterances.append(text)
 
         values = self._getSliderValues(obj)
@@ -403,7 +402,7 @@
 
         utterances = []
         text = self.getObjLabelAndName(obj.parent) + " " + \
-               rolenames.getSpeechForRoleName(obj.parent)
+               self._getSpeechForRoleName(obj.parent)
         utterances.append(text.strip())
 
         text = self.getObjLabelAndName(obj)
@@ -412,7 +411,7 @@
         state = obj.getState()
 
         if obj.getRole() != pyatspi.ROLE_MENU_ITEM:
-            text = rolenames.getSpeechForRoleName(obj)
+            text = self._getSpeechForRoleName(obj)
             utterances.append(text)
 
         if obj.getRole() == pyatspi.ROLE_CHECK_MENU_ITEM:
@@ -475,7 +474,7 @@
         """
 
         utterances = []
-        text = rolenames.getSpeechForRoleName(obj.parent)
+        text = self._getSpeechForRoleName(obj.parent)
         utterances.append(text)
 
         # Translators: "page" is the word for a page tab in a tab list.
@@ -537,7 +536,7 @@
            and self._script.isReadOnlyTextArea(obj):
             utterances.append(settings.speechReadOnlyString)
 
-        text = rolenames.getSpeechForRoleName(obj)
+        text = self._getSpeechForRoleName(obj)
         utterances.append(text)
 
         [textContents, startOffset, endOffset, selected] = \
@@ -554,6 +553,7 @@
         utterances.append(text)
         debug.println(self._debugLevel, "first text utterances=%s" % \
                       utterances)
+
         speech.speakUtterances(utterances)
 
         if not basicOnly:
@@ -603,7 +603,7 @@
             obj = obj.parent
         parent = obj.parent
 
-        text = rolenames.getSpeechForRoleName(parent)
+        text = self._getSpeechForRoleName(parent)
         utterances.append(text)
 
         try:
@@ -626,7 +626,7 @@
                 text = self._getObjName(header)
                 utterances.append(text)
 
-        text = rolenames.getSpeechForRoleName(obj)
+        text = self._getSpeechForRoleName(obj)
         utterances.append(text)
 
         if nColumns:
@@ -712,7 +712,7 @@
         if text:
             utterances.append(text)
 
-        text = rolenames.getSpeechForRoleName(obj)
+        text = self._getSpeechForRoleName(obj)
         utterances.append(text)
 
         text = self._getObjName(obj)
@@ -762,6 +762,7 @@
     def _speakParagraph(self, obj, basicOnly):
         """Speak a paragraph object.
         """
+
         self._speakText(obj, basicOnly)
 
     def _speakIconPanel(self, obj, basicOnly):
@@ -876,7 +877,7 @@
         text = self.getObjLabelAndName(obj)
         utterances.append(text)
 
-        text = rolenames.getSpeechForRoleName(obj)
+        text = self._getSpeechForRoleName(obj)
         utterances.append(text)
 
         if obj.getState().contains(pyatspi.STATE_CHECKED):
@@ -906,7 +907,7 @@
         text = self.getObjLabelAndName(obj)
         utterances.append(text)
 
-        text = rolenames.getSpeechForRoleName(obj)
+        text = self._getSpeechForRoleName(obj)
         utterances.append(text)
 
         valueString = self._script.getTextForValue(obj)
@@ -931,7 +932,7 @@
 
         utterances.extend(self._getSpeechForAllTextSelection(obj))
 
-        text = rolenames.getSpeechForRoleName(obj)
+        text = self._getSpeechForRoleName(obj)
         utterances.append(text)
 
         getTutorial = self._script.tutorialGenerator.getTutorial
@@ -952,7 +953,7 @@
         text = self.getObjLabelAndName(obj)
         utterances.append(text)
 
-        text = rolenames.getSpeechForRoleName(obj)
+        text = self._getSpeechForRoleName(obj)
         utterances.append(text)
         utterances.extend(self._getSelectedItemCount(obj, basicOnly))
 
@@ -1079,7 +1080,7 @@
         text = self.getObjLabelAndName(obj)
         utterances.append(text)
 
-        text = rolenames.getSpeechForRoleName(obj)
+        text = self._getSpeechForRoleName(obj)
         utterances.append(text)
 
         getTutorial = self._script.tutorialGenerator.getTutorial
@@ -1142,6 +1143,12 @@
 
         return text.strip()
 
+    def _getSpeechForRoleName(self, obj):
+        """Returns the rolename to be spoken for the object.
+        """
+
+        return self._script.speechGenerator.getSpeechForObjectRole(obj)[0]
+
     def _getGroupLabel(self, obj):
         """Returns the label for a group of components.
         """
@@ -1340,7 +1347,7 @@
                     break
 
         if isToggle:
-            text = rolenames.getSpeechForRoleName(obj, pyatspi.ROLE_CHECK_BOX)
+            text = self._getSpeechForRoleName(obj, pyatspi.ROLE_CHECK_BOX)
             text = text + " " + self._getCheckBoxState(obj)
         else:
             descendant = self._script.getRealActiveDescendant(obj)
@@ -1930,7 +1937,7 @@
 
         utterances = []
         text = self.getObjLabelAndName(obj) + " " + \
-               rolenames.getSpeechForRoleName(obj)
+               self._getSpeechForRoleName(obj)
         utterances.append(text.strip())
 
         debug.println(self._debugLevel, "toolbar utterances=%s" \



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