[orca] Fix BGO#621873 - custom script for eclipse may be refactored



commit 54014736140372bb52f60ab14315b0d838f10054
Author: José Vilmar Estácio de Souza <vilmar informal com br>
Date:   Wed Jun 16 17:05:32 2010 -0300

    Fix BGO#621873 - custom script for eclipse may be refactored
    
    This patch saves the object spoken in the functions onFocus, onTextInserted
    and onTextDeleted.
    so it is possible in the function _presentTextAtNewCaretPosition test
    whether object was announced and discards it.

 src/orca/scripts/apps/Eclipse/script.py |   63 ++++++++++++++-----------------
 1 files changed, 28 insertions(+), 35 deletions(-)
---
diff --git a/src/orca/scripts/apps/Eclipse/script.py b/src/orca/scripts/apps/Eclipse/script.py
index f9efde4..f4a0da4 100644
--- a/src/orca/scripts/apps/Eclipse/script.py
+++ b/src/orca/scripts/apps/Eclipse/script.py
@@ -39,9 +39,8 @@ class Script(default.Script):
     def __init__(self, app):
         """Creates a new script for the given application."""
         default.Script.__init__(self, app)
-        self._textInserted = False
         self.movementKeys = ["Up", "Down", "Left", "Right", "Page_Up",
-                             "Page_Down", "Home", "End"]
+                   "Page_Down", "Home", "End"]
 
     def _presentTextAtNewCaretPosition(self, event, otherObj=None):
         """Updates braille, magnification, and outputs speech for the
@@ -52,48 +51,27 @@ class Script(default.Script):
         if self.utilities.isDuplicateEvent(event):
             return
 
-        # We will retrieve information from the last object spoken
-        try:
-            oldObj, oldOffset = self.pointOfReference["lastCursorPosition"]
-        except:
-            oldObj = None
-            oldOffset = -1
-
         # Let the default script's normal behavior do its thing
         #
         default.Script._presentTextAtNewCaretPosition(self, event, otherObj)
 
-        textInserted = self._textInserted
-        self._textInserted = False
         # check if the obj was spoken in the default script
         lastKey, mods = self.utilities.lastKeyAndModifiers()
         if lastKey in self.movementKeys:
             # already spoken in default script
             return
 
-        # check if text was inserted before
-        if textInserted:
-            # we will ignore this event because text was spoken in
-            # onTextInserted
-            return
-
         obj = otherObj or event.source
-        offset = obj.queryText().caretOffset
-
-        difChars = offset - oldOffset
-        if obj == oldObj and (difChars == 1 or difChars == -1):
-            # it seems that the caret moved one position, forward or backward
-            # probably the user is typing, we don't want to speak the entire
-            # line
+        if obj.getState().contains(pyatspi.STATE_SINGLE_LINE):
             return
 
         self.sayLine(obj)
+        self._saveLastTextPosition(obj)
 
     def onFocus(self, event):
         """Called whenever an object gets focus.  Overridden here so that
-        we can save the current text cursor position when the event is an
-        object:state-changed:focused and source is a pyatspi.ROLE_TEXT
-        Perhaps this should be moved to the default.py???
+        so that we can avoid speaking text when caret moves after new text
+        receives focus and is spoken.
 
         Arguments:
         - event: the Event
@@ -102,15 +80,11 @@ class Script(default.Script):
         # Let the default script's normal behavior do its thing
         #
         default.Script.onFocus(self, event)
-        #
-        if event.type.startswith("object:state-changed:focused") \
-                 and event.source.getRole() == pyatspi.ROLE_TEXT:
-            # probably it was announced, time to save.
-            self._saveLastCursorPosition(event.source, \
-                   event.source.queryText().caretOffset)
+
+        self._saveLastTextPosition(event.source)
 
     def getUtilities(self):
-        """Returns the utilites for this script."""
+        """Returns the utilities for this script."""
 
         return Utilities(self)
 
@@ -126,5 +100,24 @@ class Script(default.Script):
         # Let the default script's normal behavior do its thing
         #
         default.Script.onTextInserted(self, event)
+        self._saveLastTextPosition(event.source)
+
+    def onTextDeleted(self, event):
+        """Called whenever text is deleted from an object.  Overridden here
+        so that we can avoid speaking text when caret moves after new text
+        is deleted.
+
+        Arguments:
+        - event: the Event
+        """
+
+        # Let the default script's normal behavior do its thing
+        #
+        default.Script.onTextDeleted(self, event)
+        self._saveLastTextPosition(event.source)
+
+    def _saveLastTextPosition(self, obj):
+        if self.utilities.isTextArea(obj):
+            self._saveLastCursorPosition(obj, obj.queryText().caretOffset)
+
 
-        self._textInserted = (event.source.getRole() == pyatspi.ROLE_TEXT)



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