[orca] Update the Evolution script for the focus: event deprecation; remove obsolete hacks



commit a38650044590bdae2d786704701014935b7c34c3
Author: Joanmarie Diggs <jdiggs igalia com>
Date:   Sun Nov 3 12:54:38 2013 -0500

    Update the Evolution script for the focus: event deprecation; remove obsolete hacks
    
    Note: This won't make Evolution accessible; there are still a number
    of accessibility bugs in Evolution that need to be fixed.

 src/orca/script_utilities.py                       |    2 +
 src/orca/scripts/apps/evolution/Makefile.am        |    1 -
 src/orca/scripts/apps/evolution/script.py          |  203 +----------
 .../scripts/apps/evolution/script_utilities.py     |  392 --------------------
 4 files changed, 18 insertions(+), 580 deletions(-)
---
diff --git a/src/orca/script_utilities.py b/src/orca/script_utilities.py
index c9c736e..912591a 100644
--- a/src/orca/script_utilities.py
+++ b/src/orca/script_utilities.py
@@ -2406,6 +2406,8 @@ class Utilities:
         adjustedLine = list(line)
         for n in range(nLinks, 0, -1):
             link = hyperText.getLink(n - 1)
+            if not link:
+                continue
 
             # We only care about links in the string, line:
             #
diff --git a/src/orca/scripts/apps/evolution/Makefile.am b/src/orca/scripts/apps/evolution/Makefile.am
index a2f3c7c..ba238e9 100644
--- a/src/orca/scripts/apps/evolution/Makefile.am
+++ b/src/orca/scripts/apps/evolution/Makefile.am
@@ -2,7 +2,6 @@ orca_python_PYTHON = \
     __init__.py \
     formatting.py \
     script.py \
-    script_utilities.py \
     speech_generator.py
 
 orca_pythondir=$(pkgpythondir)/scripts/apps/evolution
diff --git a/src/orca/scripts/apps/evolution/script.py b/src/orca/scripts/apps/evolution/script.py
index 7c3e3e3..54cf2c4 100644
--- a/src/orca/scripts/apps/evolution/script.py
+++ b/src/orca/scripts/apps/evolution/script.py
@@ -29,22 +29,13 @@ __license__   = "LGPL"
 
 import pyatspi
 
-import orca.cmdnames as cmdnames
-import orca.debug as debug
 import orca.scripts.default as default
-import orca.braille as braille
-import orca.messages as messages
-import orca.orca as orca
-import orca.orca_state as orca_state
 import orca.scripts.toolkits.WebKitGtk as WebKitGtk
-import orca.speech as speech
-import orca.speechserver as speechserver
 import orca.settings as settings
 import orca.settings_manager as settings_manager
 
 from .formatting import Formatting
 from .speech_generator import SpeechGenerator
-from .script_utilities import Utilities
 
 _settingsManager = settings_manager.getManager()
 
@@ -63,37 +54,9 @@ class Script(WebKitGtk.Script):
         - app: the application to create a script for.
         """
 
-        # Set the debug level for all the methods in this script.
-        #
-        self.debugLevel = debug.LEVEL_FINEST
-
         WebKitGtk.Script.__init__(self, app)
-
-        # This will be used to cache a handle to the message area in the
-        # Mail compose window.
-
-        self.message_panel = None
-
-        # A handle to the Spellcheck dialog.
-        #
-        self.spellCheckDialog = None
-
-        # The last row and column we were on in the mail message header list.
-
-        self.lastMessageColumn = -1
-        self.lastMessageRow = -1
-
-        # The last locusOfFocusChanged roles hierarchy.
-        #
-        self.rolesList = []
-
-        # By default, don't present if Evolution is not the active application.
-        #
         self.presentIfInactive = False
 
-        # Evolution defines new custom roles. We need to make them known
-        # to Orca for Speech and Braille output.
-
     def getSpeechGenerator(self):
         """Returns the speech generator for this script.
         """
@@ -104,11 +67,6 @@ class Script(WebKitGtk.Script):
         """Returns the formatting strings for this script."""
         return Formatting(self)
 
-    def getUtilities(self):
-        """Returns the utilites for this script."""
-
-        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
@@ -119,8 +77,6 @@ class Script(WebKitGtk.Script):
         to say it shouldn't.
         """
 
-        # If the Evolution window is not focused, ignore this event.
-        #
         window = self.utilities.topLevelObject(event.source)
         if window and not window.getState().contains(pyatspi.STATE_ACTIVE):
             return False
@@ -145,71 +101,16 @@ class Script(WebKitGtk.Script):
     #                                                                      #
     ########################################################################
 
-    def onActiveDescendantChanged(self, event):
-        """Called when an object who manages its own descendants detects a
-        change in one of its children.
+    def onNameChanged(self, event):
+        """Callback for object:property-change:accessible-name events."""
 
-        Arguments:
-        - event: the Event
-        """
-
-        # The default script's onActiveDescendantChanged method is cutting
-        # off speech with a speech.stop. If we're in the spellcheck dialog,
-        # this interrupts the presentation of the context.
-        #
-        if self.utilities.isSpellingSuggestionsList(event.source):
-            orca.setLocusOfFocus(event, event.any_data)
-
-            # We'll tuck away the activeDescendant information for future
-            # reference since the AT-SPI gives us little help in finding
-            # this.
-            #
-            if orca_state.locusOfFocus \
-               and (orca_state.locusOfFocus != event.source):
-                self.pointOfReference['activeDescendantInfo'] = \
-                    [orca_state.locusOfFocus.parent,
-                     orca_state.locusOfFocus.getIndexInParent()]
+        # Every time the selected mail folder changes, Evolution's frame is
+        # updated to display the newly-selected folder. We need to ignore
+        # this event so as not to double-present the selected folder.
+        if event.source.getRole() == pyatspi.ROLE_FRAME:
             return
 
-        default.Script.onActiveDescendantChanged(self, event)
-
-    def onFocus(self, event):
-        """Called whenever an object gets focus.
-
-        Arguments:
-        - event: the Event
-        """
-
-        # When a message is deleted from within the table of messages, we get
-        # two focus events:  One for the index of the new message prior to
-        # deletion and one for the index of the new message after deletion.
-        # This causes us to speak the message after the one that gets focus
-        # prior to speaking the actual message that gets focus.
-        # See bug #347964.
-        #
-        string, mods = self.utilities.lastKeyAndModifiers()
-        if string == "Delete":
-            roles = [pyatspi.ROLE_TABLE_CELL,
-                     pyatspi.ROLE_TREE_TABLE,
-                     pyatspi.ROLE_UNKNOWN,
-                     pyatspi.ROLE_SCROLL_PANE]
-            oldLocusOfFocus = orca_state.locusOfFocus
-            if self.utilities.hasMatchingHierarchy(event.source, roles) \
-               and self.utilities.hasMatchingHierarchy(oldLocusOfFocus, roles):
-                parent = event.source.parent
-                parentTable = parent.queryTable()
-                newIndex = self.utilities.cellIndex(event.source)
-                newRow = parentTable.getRowAtIndex(newIndex)
-                oldIndex = self.utilities.cellIndex(oldLocusOfFocus)
-                oldRow = parentTable.getRowAtIndex(oldIndex)
-                nRows = parentTable.nRows
-                if (newRow != oldRow) and (oldRow != nRows):
-                    return
-
-        # For everything else, pass the event onto the parent class
-        # to be handled in the default way.
-        #
-        default.Script.onFocus(self, event)
+        default.Script.onNameChanged(self, event)
 
     def onStateChanged(self, event):
         """Called whenever an object's state changes.
@@ -254,86 +155,14 @@ class Script(WebKitGtk.Script):
 
         default.Script.onStateChanged(self, event)
 
-    def onTextInserted(self, event):
-        """Called whenever text is inserted into an object.
-
-        Arguments:
-        - event: the Event
-        """
-
-        # When the active descendant in the list of misspelled words
-        # changes, we typically get an object:active-descendant-changed
-        # event. Unfortunately, we don't seem to get this event (or a
-        # focus: event) when the user presses a button without moving
-        # focus there explicitly. (e.g. pressing Alt+R) The label which
-        # is associated with the spelling list gets new text. So we'll
-        # try to look for that instead.
-        #
-        if event.source.getRole() == pyatspi.ROLE_LABEL:
-            relations = event.source.getRelationSet()
-            for relation in relations:
-                if relation.getRelationType() == pyatspi.RELATION_LABEL_FOR:
-                    target = relation.getTarget(0)
-                    if self.utilities.isSpellingSuggestionsList(target):
-                        [badWord, allTokens] = \
-                            self.utilities.misspelledWordAndBody(
-                                target, self.message_panel)
-                        self.speakMisspeltWord(allTokens, badWord)
-
-                        try:
-                            selection = target.querySelection()
-                        except NotImplementedError:
-                            selection = None
-                        if selection and selection.nSelectedChildren > 0:
-                            newFocus = selection.getSelectedChild(0)
-                            orca.setLocusOfFocus(event, newFocus)
-                            self.pointOfReference['activeDescendantInfo'] = \
-                                [target, newFocus.getIndexInParent()]
-
-                        return
-
-        default.Script.onTextInserted(self, event)
-
-    ########################################################################
-    #                                                                      #
-    # Methods for presenting content                                       #
-    #                                                                      #
-    ########################################################################
+    def skipObjectEvent(self, event):
+        # NOTE: This is here temporarily as part of the preparation for the
+        # deprecation/removal of accessible "focus:" events. Once the change
+        # has been complete, this method should be removed from this script.
+        if event.type == "focus:":
+            return True
 
-    def presentMessageLine(self, obj, newLocusOfFocus):
-        """Speak/braille the line at the current text caret offset.
-        """
-
-        [string, caretOffset, startOffset] = self.getTextLineAtCaret(obj)
-        self.updateBraille(newLocusOfFocus)
-        result = self.speechGenerator.generateTextIndentation(obj, line=string)
-        if result:
-            speech.speak(result[0])
-        line = self.utilities.adjustForRepeats(string)
-
-        if self.utilities.speakBlankLine(obj):
-            speech.speak(messages.BLANK, None, False)
-        else:
-            speech.speak(line, None, False)
-
-    def readPageTab(self, tab):
-        """Speak/Braille the given page tab. The speech verbosity is set
-           to VERBOSITY_LEVEL_BRIEF for this operation and then restored
-           to its previous value on completion.
-
-        Arguments:
-        - tab: the page tab to speak/braille.
-        """
-
-        brailleGen = self.brailleGenerator
-        speechGen = self.speechGenerator
-
-        savedSpeechVerbosityLevel = settings.speechVerbosityLevel
-        _settingsManager.setSetting(
-            'speechVerbosityLevel', settings.VERBOSITY_LEVEL_BRIEF)
-        utterances = speechGen.generateSpeech(tab)
-        speech.speak(utterances)
-        _settingsManager.setSetting(
-            'speechVerbosityLevel', savedSpeechVerbosityLevel)
+        if event.type == "object:state-changed:focused":
+            return False
 
-        self.displayBrailleRegions(brailleGen.generateBraille(tab))
+        return default.Script.skipObjectEvent(self, event)


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