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



commit a3b80869dae8554293904cbfb1dd35ed1b1ba491
Author: Joanmarie Diggs <jdiggs igalia com>
Date:   Mon Nov 4 07:03:58 2013 -0500

    Update the Gcalctool script for the focus: event deprecation; remove obsolete hacks

 src/orca/scripts/apps/gcalctool/Makefile.am        |    3 +-
 src/orca/scripts/apps/gcalctool/script.py          |  144 +++++---------------
 .../scripts/apps/gcalctool/speech_generator.py     |   62 ---------
 3 files changed, 35 insertions(+), 174 deletions(-)
---
diff --git a/src/orca/scripts/apps/gcalctool/Makefile.am b/src/orca/scripts/apps/gcalctool/Makefile.am
index 9f783f4..f07b700 100644
--- a/src/orca/scripts/apps/gcalctool/Makefile.am
+++ b/src/orca/scripts/apps/gcalctool/Makefile.am
@@ -1,7 +1,6 @@
 orca_python_PYTHON = \
        __init__.py \
-       script.py \
-       speech_generator.py
+       script.py
 
 orca_pythondir=$(pkgpythondir)/scripts/apps/gcalctool
 
diff --git a/src/orca/scripts/apps/gcalctool/script.py b/src/orca/scripts/apps/gcalctool/script.py
index 81d8a80..efefdd8 100644
--- a/src/orca/scripts/apps/gcalctool/script.py
+++ b/src/orca/scripts/apps/gcalctool/script.py
@@ -28,12 +28,7 @@ __license__   = "LGPL"
 import pyatspi
 
 import orca.scripts.default as default
-import orca.input_event as input_event
 import orca.messages as messages
-import orca.orca_state as orca_state
-import orca.speech as speech
-
-from .speech_generator import SpeechGenerator
 
 ########################################################################
 #                                                                      #
@@ -54,16 +49,9 @@ class Script(default.Script):
 
         default.Script.__init__(self, app)
 
-        self._lastProcessedKeyEvent = None
-        self._lastSpokenContents = None
         self._resultsDisplay = None
         self._statusLine = None
 
-    def getSpeechGenerator(self):
-        """Returns the speech generator for this script.
-        """
-        return SpeechGenerator(self)
-
     def onWindowActivated(self, event):
         """Called whenever one of gcalctool's toplevel windows is activated.
 
@@ -71,40 +59,24 @@ class Script(default.Script):
         - event: the window activated Event
         """
 
-        # Locate the results display and the status line if we've not yet
-        # done so.
-        #
-        if not (self._resultsDisplay and self._statusLine) \
-           and event.source.getRole() == pyatspi.ROLE_FRAME:
-            objs = self.utilities.descendantsWithRole(
-                event.source, pyatspi.ROLE_EDITBAR)
-            if len(objs) == 0:
-                contents = messages.CALCULATOR_DISPLAY_NOT_FOUND
-                speech.speak(contents)
-                self.displayBrailleMessage(contents)
-            else:
-                self._resultsDisplay = objs[0]
-                contents = self.utilities.substring(self._resultsDisplay, 0, -1)
-                self.displayBrailleMessage(contents)
-                # The status line in gcalctool 5.29 is a sibling of the
-                # edit bar.
-                #
-                objs = self.utilities.descendantsWithRole(
-                    self._resultsDisplay.parent, pyatspi.ROLE_TEXT)
-                for obj in objs:
-                    if not obj.getState().contains(pyatspi.STATE_EDITABLE):
-                        self._statusLine = obj
-                        break
-                else:
-                    # The status line in gcalctool 5.28 is a label in the
-                    # status bar in which text is inserted as need be.
-                    #
-                    statusBar = self.utilities.statusBar(event.source)
-                    if statusBar:
-                        objs = self.utilities.descendantsWithRole(
-                            statusBar, pyatspi.ROLE_LABEL)
-                        if len(objs):
-                            self._statusLine = objs[0]
+        if self._resultsDisplay and self._statusLine:
+            default.Script.onWindowActivated(self, event)
+            return
+
+        obj = event.source
+        role = obj.getRole()
+        if role != pyatspi.ROLE_FRAME:
+            default.Script.onWindowActivated(self, event)
+            return
+
+        isEditbar = lambda x: x and x.getRole() == pyatspi.ROLE_EDITBAR
+        self._resultsDisplay = pyatspi.findDescendant(obj, isEditbar)
+        if not self._resultsDisplay:
+            self.presentMessage(messages.CALCULATOR_DISPLAY_NOT_FOUND)
+
+        isStatusLine = lambda x: x and x.getRole() == pyatspi.ROLE_TEXT \
+                       and not x.getState().contains(pyatspi.STATE_EDITABLE)
+        self._statusLine = pyatspi.findDescendant(obj, isStatusLine)
 
         default.Script.onWindowActivated(self, event)
 
@@ -115,68 +87,20 @@ class Script(default.Script):
         - event: the text inserted Event
         """
 
-        # Always update the Braille display but only speak if the last
-        # key pressed was Return, space, or equals.
-        #
-        if self.utilities.isSameObject(event.source, self._resultsDisplay):
-            contents = self.utilities.substring(self._resultsDisplay, 0, -1)
-            self.displayBrailleMessage(contents)
-            lastKey, mods = self.utilities.lastKeyAndModifiers()
-            if lastKey in ["space", "Return", "="]:
-                # gcalctool issues several identical text inserted events
-                # for a single press of keys such as enter, space, or equals.
-                # In fact, it's usually about 4, but we cannot depend upon
-                # that.  In addition, keyboard events are decoupled from
-                # text insertion events, so we may get key press/release
-                # events before an insertion occurs, or we might get a
-                # press, an insertion, and then a release.
-                #
-                # So, what we do is try to infer that an insertion event
-                # was the cause of a single key event.
-                #
-                speakIt = True
-                if self._lastProcessedKeyEvent:
-                    # This catches text insertion events where the last
-                    # keyboard event we looked at was the key release event.
-                    #
-                    if self._lastProcessedKeyEvent.timestamp \
-                       == orca_state.lastNonModifierKeyEvent.timestamp:
-                        speakIt = False
-                    # This catches text insertion events where the last
-                    # keyboard event we looked at was the key press event,
-                    # but the current one is now the associated key release
-                    # event.  We infer they are the same by looking at the
-                    # hardware code, the time delta between the press and
-                    # the release, and that we are on the verge of repeating
-                    # something we just spoke.
-                    #
-                    # It would be tempting to look at just the contents that
-                    # we previous spoke, but a use case we need to handle is
-                    # when the user enters a number (e.g., "666") and then
-                    # presses Return several times.  In this case, we get
-                    # the text insertion events and they are all "666".
-                    #
-                    elif (self._lastProcessedKeyEvent.type \
-                          == pyatspi.KEY_PRESSED_EVENT) \
-                          and (orca_state.lastNonModifierKeyEvent.type \
-                               == pyatspi.KEY_RELEASED_EVENT) \
-                          and (orca_state.lastNonModifierKeyEvent.hw_code \
-                               == self._lastProcessedKeyEvent.hw_code) \
-                          and (orca_state.lastNonModifierKeyEvent.timestamp \
-                               - self._lastProcessedKeyEvent.timestamp) < 1000 \
-                          and (contents == self._lastSpokenContents):
-                        speakIt = False
-                if speakIt:
-                    speech.speak(contents)
-                    self._lastSpokenContents = contents
-
-            if not lastKey:
-                return
-
-            self._lastProcessedKeyEvent = \
-                input_event.KeyboardEvent(orca_state.lastNonModifierKeyEvent)
-
-        elif self.utilities.isSameObject(event.source, self._statusLine):
-            contents = self.utilities.substring(self._statusLine, 0, -1)
-            speech.speak(contents)
+        if self.utilities.isSameObject(event.source, self._statusLine):
+            self.presentMessage(self.utilities.displayedText(self._statusLine))
             return
+
+        default.Script.onTextInserted(self, event)
+
+    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 completed, this method should be removed from this script.
+        if event.type == "focus:":
+            return True
+
+        if event.type == "object:state-changed:focused":
+            return False
+
+        return default.Script.skipObjectEvent(self, event)


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