[orca] Begin cleaning up Gedit script: * Remove some old and no-longer-working hacks * Improve presentation



commit c84214d97a52351e479e361658fb21358ce6b0f1
Author: Joanmarie Diggs <jdiggs igalia com>
Date:   Mon Jan 27 22:19:05 2014 -0500

    Begin cleaning up Gedit script:
    * Remove some old and no-longer-working hacks
    * Improve presentation of the Gedit find entry and results

 src/orca/scripts/apps/gedit/script.py             |  128 ++-------------------
 src/orca/scripts/toolkits/gtk/script_utilities.py |   25 ++++-
 2 files changed, 35 insertions(+), 118 deletions(-)
---
diff --git a/src/orca/scripts/apps/gedit/script.py b/src/orca/scripts/apps/gedit/script.py
index 5150847..ff2caa2 100644
--- a/src/orca/scripts/apps/gedit/script.py
+++ b/src/orca/scripts/apps/gedit/script.py
@@ -30,8 +30,6 @@ import pyatspi
 import orca.debug as debug
 import orca.orca_state as orca_state
 import orca.scripts.toolkits.gtk as gtk
-import orca.settings as settings
-import orca.speech as speech
 
 from orca.orca_i18n import _
 
@@ -155,47 +153,6 @@ class Script(gtk.Script):
             self.lastBadWord = badWord
             self.lastEventType = event.type
 
-    def isFocusOnFindDialog(self):
-        """Return an indication of whether the current locus of focus is on
-        the Find button or the combo box in the Find dialog.
-        """
-
-        obj = orca_state.locusOfFocus
-        if not obj:
-            return False
-
-        rolesList1 = [pyatspi.ROLE_PUSH_BUTTON,
-                      pyatspi.ROLE_FILLER,
-                      pyatspi.ROLE_FILLER,
-                      pyatspi.ROLE_DIALOG,
-                      pyatspi.ROLE_APPLICATION]
-
-        rolesList2 = [pyatspi.ROLE_TEXT,
-                      pyatspi.ROLE_COMBO_BOX,
-                      pyatspi.ROLE_PANEL,
-                      pyatspi.ROLE_FILLER,
-                      pyatspi.ROLE_FILLER,
-                      pyatspi.ROLE_DIALOG,
-                      pyatspi.ROLE_APPLICATION]
-
-        # Translators: this is used to tell us if the focus is on the
-        # "Find" button in gedit's Find dialog.  It must match what
-        # gedit is using.  We hate keying off stuff like this, but
-        # we're forced to do so in this case.
-        #
-        tmp = obj.parent.parent
-        if (self.utilities.hasMatchingHierarchy(obj, rolesList1) \
-            and obj.name == _("Find")) \
-            or (self.utilities.hasMatchingHierarchy(obj, rolesList2) \
-                and tmp.parent.parent.parent.name == _("Find")):
-            return True
-        else:
-            return False
-
-    # This method tries to detect and handle the following cases:
-    # 1) Text area (for caching handle for spell checking purposes).
-    # 2) Check Spelling Dialog.
-
     def locusOfFocusChanged(self, event, oldLocusOfFocus, newLocusOfFocus):
         """Called when the visual object with focus changes.
 
@@ -291,7 +248,6 @@ class Script(gtk.Script):
 
     # This method tries to detect and handle the following cases:
     # 1) check spelling dialog.
-    # 2) find dialog - phrase not found.
 
     def onNameChanged(self, event):
         """Called whenever a property on an object changes.
@@ -336,81 +292,21 @@ class Script(gtk.Script):
                 self.readMisspeltWord(event, event.source.parent)
                 # Fall-thru to process the event with the default handler.
 
-        # 2) find dialog - phrase not found.
-        #
-        # If we've received an "object:property-change:accessible-name" for
-        # the status bar and the current locus of focus is on the Find
-        # button on the Find dialog or the combo box in the Find dialog
-        # and the last input event was a Return and the name for the current
-        # event source is "Phrase not found", then speak it.
-        #
-        # [[[TODO: richb - "Phrase not found" is spoken twice because we
-        # apparently get two identical "object:property-change:accessible-name"
-        # events.]]]
-
-        lastKey, mods = self.utilities.lastKeyAndModifiers()
-
-        # Translators: the "Phrase not found" is the result of a failed
-        # find command.  It must be the same as what gedit uses.  We hate
-        # keying off stuff like this, but we're forced to do so in this
-        # case.
-        #
-        if event.source.getRole() == pyatspi.ROLE_STATUS_BAR \
-           and self.isFocusOnFindDialog() \
-           and lastKey == "Return" \
-           and event.source.name == _("Phrase not found"):
-            debug.println(self.debugLevel,
-                          "gedit.onNameChanged - phrase not found.")
-            speech.speak(event.source.name)
-
-        # Pass the event onto the parent class to be handled in the default way.
         gtk.Script.onNameChanged(self, event)
 
-    # This method tries to detect and handle the following cases:
-    # 1) find dialog - phrase found.
-
-    def onCaretMoved(self, event):
-        """Called whenever the caret moves.
+    def onTextSelectionChanged(self, event):
+        """Callback for object:text-selection-changed accessibility events."""
 
-        Arguments:
-        - event: the Event
-        """
+        if event.source == orca_state.locusOfFocus:
+            gtk.Script.onTextSelectionChanged(self, event)
+            return
 
-        details = debug.getAccessibleDetails(self.debugLevel, event.source)
-        debug.printObjectEvent(self.debugLevel, event, details)
-
-        # If we've received a text caret moved event and the current locus
-        # of focus is on the Find button on the Find dialog or the combo
-        # box in the Find dialog and the last input event was a Return,
-        # and if the current line contains the phrase we were looking for,
-        # then speak the current text line, to give an indication of what
-        # we've just found.
-        #
-        lastKey, mods = self.utilities.lastKeyAndModifiers()
-        if self.isFocusOnFindDialog() and lastKey == "Return":
-            debug.println(self.debugLevel, "gedit.onCaretMoved - find dialog.")
-            allComboBoxes = self.utilities.descendantsWithRole(
-                orca_state.locusOfFocus.getApplication(),
-                pyatspi.ROLE_COMBO_BOX)
-            phrase = self.utilities.displayedText(allComboBoxes[0])
-            [text, caretOffset, startOffset] = \
-                self.getTextLineAtCaret(event.source)
-            if text.lower().find(phrase) != -1:
-                # Translators: this indicates a find command succeeded in
-                # finding something.
-                #
-                self.presentMessage(_("Phrase found."))
-                utterances = self.speechGenerator.generateSpeech(
-                    event.source, alreadyFocused=True)
-                speech.speak(utterances)
-
-        # If Ctrl+G was used to repeat a find command, speak the line that
-        # the caret moved to.
-        #
-        if lastKey == 'G' and mods & settings.CTRL_MODIFIER_MASK:
-            self.sayLine(event.source)
+        if not self.utilities.isSearchEntry(orca_state.locusOfFocus, True):
+            return
 
-        # For everything else, pass the caret moved event onto the parent
-        # class to be handled in the default way.
+        # To avoid extreme chattiness.
+        keyString, mods = self.utilities.lastKeyAndModifiers()
+        if keyString in ["BackSpace", "Delete"]:
+            return
 
-        gtk.Script.onCaretMoved(self, event)
+        self.sayLine(event.source)
diff --git a/src/orca/scripts/toolkits/gtk/script_utilities.py 
b/src/orca/scripts/toolkits/gtk/script_utilities.py
index 39f719e..cb38144 100644
--- a/src/orca/scripts/toolkits/gtk/script_utilities.py
+++ b/src/orca/scripts/toolkits/gtk/script_utilities.py
@@ -1,6 +1,6 @@
 # Orca
 #
-# Copyright (C) 2013 Igalia, S.L.
+# Copyright (C) 2013-2014 Igalia, S.L.
 #
 # Author: Joanmarie Diggs <jdiggs igalia com>
 #
@@ -22,7 +22,7 @@
 __id__ = "$Id$"
 __version__   = "$Revision$"
 __date__      = "$Date$"
-__copyright__ = "Copyright (c) 2013 Igalia, S.L."
+__copyright__ = "Copyright (c) 2013-2014 Igalia, S.L."
 __license__   = "LGPL"
 
 import pyatspi
@@ -46,3 +46,24 @@ class Utilities(script_utilities.Utilities):
 
         self._script.generatorCache[self.DISPLAYED_TEXT][obj] = displayedText
         return displayedText
+
+    def isSearchEntry(self, obj, focusedOnly=False):
+        # Another example of why we need subrole support in ATK and AT-SPI2.
+        try:
+            name = obj.name
+            state = obj.getState()
+        except:
+            return False
+
+        if not (name and state.contains(pyatspi.STATE_SINGLE_LINE)):
+            return False
+
+        if focusedOnly and not state.contains(pyatspi.STATE_FOCUSED):
+            return False
+
+        isIcon = lambda x: x and x.getRole() == pyatspi.ROLE_ICON
+        icons = list(filter(isIcon, [x for x in obj]))
+        if icons:
+            return True
+
+        return False


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