[orca] Fix for RFE/Bug 588403 - Implement ability to route the mouse pointer without clicking



commit 625a64b4212f2ee58212a9ca4af03d2903c321f2
Author: Joanmarie Diggs <joanmarie diggs gmail com>
Date:   Sun Jul 12 17:04:54 2009 -0400

    Fix for RFE/Bug 588403 - Implement ability to route the mouse pointer without clicking
    
    This implements support for routing the pointer to the current location
    (either the area under flat review or the locusOfFocus).

 src/orca/default.py          |   44 ++++++++++++++++++++++++++++++++++++++++++
 src/orca/eventsynthesizer.py |   38 ++++++++++++++++++++++++++++++++++++
 src/orca/flat_review.py      |   18 +++++++++++++++++
 3 files changed, 100 insertions(+), 0 deletions(-)
---
diff --git a/src/orca/default.py b/src/orca/default.py
index 06d84dd..83e1d00 100644
--- a/src/orca/default.py
+++ b/src/orca/default.py
@@ -38,6 +38,7 @@ import pyatspi
 import braille
 import chnames
 import debug
+import eventsynthesizer
 import find
 import flat_review
 import input_event
@@ -130,6 +131,14 @@ class Script(script.Script):
         """Defines InputEventHandler fields for this script that can be
         called by the key and braille bindings."""
 
+        self.inputEventHandlers["routePointerToItemHandler"] = \
+            input_event.InputEventHandler(
+                Script.routePointerToItem,
+                # Translators: this command will move the mouse pointer
+                # to the current item without clicking on it.
+                #
+                _("Routes the pointer to the current item."))
+
         self.inputEventHandlers["leftClickReviewItemHandler"] = \
             input_event.InputEventHandler(
                 Script.leftClickReviewItem,
@@ -1059,6 +1068,13 @@ class Script(script.Script):
 
         keyBindings = keybindings.KeyBindings()
 
+        keyBindings.add(
+            keybindings.KeyBinding(
+                "KP_Divide",
+                settings.defaultModifierMask,
+                settings.ORCA_MODIFIER_MASK,
+                self.inputEventHandlers["routePointerToItemHandler"]))
+
         # We want the user to be able to combine modifiers with the
         # mouse click (e.g. to Shift+Click and select), therefore we
         # do not "care" about the modifiers.
@@ -1449,6 +1465,13 @@ class Script(script.Script):
 
         keyBindings = keybindings.KeyBindings()
 
+        keyBindings.add(
+            keybindings.KeyBinding(
+                "9",
+                settings.defaultModifierMask,
+                settings.ORCA_MODIFIER_MASK,
+                self.inputEventHandlers["routePointerToItemHandler"]))
+
         # We want the user to be able to combine modifiers with the
         # mouse click (e.g. to Shift+Click and select), therefore we
         # do not "care" about the modifiers (other than the Orca
@@ -5064,6 +5087,27 @@ class Script(script.Script):
 
         return True
 
+    def routePointerToItem(self, inputEvent=None):
+        """Moves the mouse pointer to the current item."""
+
+        if self.flatReviewContext:
+            self.flatReviewContext.routeToCurrent()
+        else:
+            try:
+                eventsynthesizer.routeToCharacter(orca_state.locusOfFocus)
+            except:
+                try:
+                    eventsynthesizer.routeToObject(orca_state.locusOfFocus)
+                except:
+                    # Translators: Orca has a command that allows the user
+                    # to move the mouse pointer to the current object. If
+                    # for some reason Orca cannot identify the current
+                    # location, it will speak this message.
+                    #
+                    speech.speak(_("Could not find current location."))
+
+        return True
+
     def leftClickReviewItem(self, inputEvent=None):
         """Performs a left mouse button click on the current item."""
 
diff --git a/src/orca/eventsynthesizer.py b/src/orca/eventsynthesizer.py
index 35abc6d..a438830 100644
--- a/src/orca/eventsynthesizer.py
+++ b/src/orca/eventsynthesizer.py
@@ -49,6 +49,44 @@ def generateMouseEvent(x, y, eventName):
 
     pyatspi.Registry.generateMouseEvent(x, y, eventName)
 
+def routeToCharacter(obj):
+    """Moves the mouse pointer to the given character
+
+    Arguments:
+    - obj: the Accessible which implements the accessible text
+      interface
+    """
+    text = obj.queryText()
+    # We try to move to the left of center.  This is to
+    # handle toolkits that will offset the caret position to
+    # the right if you click dead on center of a character.
+    #
+    extents = text.getCharacterExtents(text.caretOffset,
+                                       pyatspi.DESKTOP_COORDS)
+    x = max(extents[0], extents[0] + (extents[2] / 2) - 1)
+    y = extents[1] + extents[3] / 2
+    routeToPoint(x, y, "abs")
+
+def routeToObject(obj):
+    """Moves the mouse pointer to the given Accessible.
+
+    Arguments:
+    - obj: the Accessible
+    """
+    extents = obj.queryComponent().getExtents(pyatspi.DESKTOP_COORDS)
+    x = extents.x + extents.width / 2
+    y = extents.y + extents.height / 2
+    routeToPoint(x, y, "abs")
+
+def routeToPoint(x, y, eventName="abs"):
+    """Moves the mouse pointer to the given point.
+
+    Arguments:
+    - x, y: the point
+    - eventName: absolute("abs") or relative("rel")
+    """
+    generateMouseEvent(x, y, eventName)
+
 def clickObject(obj, button):
     """Performs a button click on the given Accessible.
 
diff --git a/src/orca/flat_review.py b/src/orca/flat_review.py
index 260d983..ba173d7 100644
--- a/src/orca/flat_review.py
+++ b/src/orca/flat_review.py
@@ -1476,6 +1476,24 @@ class Context:
         #print "Current line=%d zone=%d word=%d char=%d" \
         #      % (lineIndex, zoneIndex, wordIndex, charIndex)
 
+    def routeToCurrent(self):
+        """Routes the mouse pointer to the current accessible."""
+
+        if (not self.lines) \
+           or (not self.lines[self.lineIndex].zones):
+            return
+
+        [string, x, y, width, height] = self.getCurrent(Context.CHAR)
+        try:
+            # We try to move to the left of center.  This is to
+            # handle toolkits that will offset the caret position to
+            # the right if you click dead on center of a character.
+            #
+            x = max(x, x + (width / 2) - 1)
+            eventsynthesizer.routeToPoint(x, y + height / 2, "abs")
+        except:
+            debug.printException(debug.LEVEL_SEVERE)
+
     def clickCurrent(self, button=1):
         """Performs a mouse click on the current accessible."""
 



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