[orca] Add unbound command to present current object's size and position



commit 3a7e23d6555758eebf0a35ce6cd3947987099b8f
Author: Joanmarie Diggs <jdiggs igalia com>
Date:   Mon Jan 7 15:27:38 2019 -0500

    Add unbound command to present current object's size and position

 help/C/commands_where_am_i.page |  5 ++++-
 src/orca/cmdnames.py            |  5 +++++
 src/orca/common_keyboardmap.py  |  3 +++
 src/orca/messages.py            | 12 ++++++++++++
 src/orca/scripts/default.py     | 25 +++++++++++++++++++++++++
 5 files changed, 49 insertions(+), 1 deletion(-)
---
diff --git a/help/C/commands_where_am_i.page b/help/C/commands_where_am_i.page
index 3ca5f9411..1d756b6f8 100644
--- a/help/C/commands_where_am_i.page
+++ b/help/C/commands_where_am_i.page
@@ -55,7 +55,7 @@
   </list>
   <p>
     In addition to the dedicated Where Am I commands, <app>Orca</app> has
-    two additional commands related to obtaining your present location:
+    additional commands related to obtaining information about your present location:
   </p>
   <list>
     <item>
@@ -88,6 +88,9 @@
             (double-clicked)
           </p>
         </item>
+        <item>
+          <p>Present size and location of current object in pixels: (Unbound)</p>
+        </item>
       </list>
     </item>
   </list>
diff --git a/src/orca/cmdnames.py b/src/orca/cmdnames.py
index 48e11a160..d3d562132 100644
--- a/src/orca/cmdnames.py
+++ b/src/orca/cmdnames.py
@@ -531,6 +531,11 @@ PRESENT_CURRENT_TIME = _("Present current time.")
 # braille.
 PRESENT_CURRENT_DATE = _("Present current date.")
 
+# Translators: Orca has a command to present the pixel size and location of
+# the current object. This string is how this command is described in the list
+# of keyboard shortcuts.
+PRESENT_SIZE_AND_POSITION = _("Present size and location of current object.")
+
 # Translators: Orca normally intercepts all keyboard commands and only passes
 # them along to the current application when they are not Orca commands. This
 # command causes the next command issued to be passed along to the current
diff --git a/src/orca/common_keyboardmap.py b/src/orca/common_keyboardmap.py
index d9dc25549..246af2e18 100644
--- a/src/orca/common_keyboardmap.py
+++ b/src/orca/common_keyboardmap.py
@@ -199,4 +199,7 @@ keymap = (
 
     ("", defaultModifierMask, NO_MODIFIER_MASK,
     "whereAmILinkHandler"),
+
+    ("", defaultModifierMask, NO_MODIFIER_MASK,
+    "presentSizeAndPositionHandler"),
 )
diff --git a/src/orca/messages.py b/src/orca/messages.py
index 9e3b0df76..e5ea8321c 100644
--- a/src/orca/messages.py
+++ b/src/orca/messages.py
@@ -2060,6 +2060,18 @@ SELECTION_DELETED = _("Selection deleted.")
 # which was just inserted.
 SELECTION_RESTORED = _("Selection restored.")
 
+# Translators: Orca has a command which presents the size and position of the
+# current object in pixels. This string refers to the brief/non-verbose output
+# presented in response to the command. The string substitutions are all for
+# quantities (in pixels).
+SIZE_AND_POSITION_BRIEF = _("Size: %d, %d. Location: %d, %d.")
+
+# Translators: Orca has a command which presents the size and position of the
+# current object in pixels. This string refers to the full/verbose output
+# presented in response to the command. The string substitutions are all for
+# quantities (in pixels).
+SIZE_AND_POSITION_FULL = _("Width: %d. Height: %d. %d from left. %d from top.")
+
 # Translators: This message is presented to the user when speech synthesis
 # has been temporarily turned off.
 SPEECH_DISABLED = _("Speech disabled.")
diff --git a/src/orca/scripts/default.py b/src/orca/scripts/default.py
index 643139969..541112606 100644
--- a/src/orca/scripts/default.py
+++ b/src/orca/scripts/default.py
@@ -516,6 +516,11 @@ class Script(script.Script):
                 Script.bypassNextCommand,
                 cmdnames.BYPASS_NEXT_COMMAND)
 
+        self.inputEventHandlers["presentSizeAndPositionHandler"] = \
+            input_event.InputEventHandler(
+                Script.presentSizeAndPosition,
+                cmdnames.PRESENT_SIZE_AND_POSITION)
+
         self.inputEventHandlers.update(notification_messages.inputEventHandlers)
 
     def getInputEventHandlerKey(self, inputEventHandler):
@@ -4311,3 +4316,23 @@ class Script(script.Script):
         message = time.strftime(dateFormat, time.localtime())
         self.presentMessage(message)
         return True
+
+    def presentSizeAndPosition(self, inputEvent):
+        """ Presents the size and position of the locusOfFocus. """
+
+        if self.flatReviewContext:
+            obj = self.flatReviewContext.getCurrentAccessible()
+        else:
+            obj = orca_state.locusOfFocus
+
+        x, y, width, height = self.utilities.getBoundingBox(obj)
+        if (x, y, width, height) == (-1, -1, 0, 0):
+            full = messages.LOCATION_NOT_FOUND_FULL
+            brief = messages.LOCATION_NOT_FOUND_BRIEF
+            self.presentMessage(full, brief)
+            return True
+
+        full = messages.SIZE_AND_POSITION_FULL % (width, height, x, y)
+        brief = messages.SIZE_AND_POSITION_BRIEF % (width, height, x, y)
+        self.presentMessage(full, brief)
+        return True


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