[orca] Create a custom localized role for menu buttons



commit 270dba388bcb0e1f334736e29006585b7573d1ec
Author: Joanmarie Diggs <jdiggs igalia com>
Date:   Tue Sep 6 14:37:33 2016 -0400

    Create a custom localized role for menu buttons

 src/orca/generator.py         |    3 +++
 src/orca/object_properties.py |    6 ++++++
 src/orca/script_utilities.py  |   33 +++++++++++++++++++++++++++++++++
 3 files changed, 42 insertions(+), 0 deletions(-)
---
diff --git a/src/orca/generator.py b/src/orca/generator.py
index 66fc3d5..6fb2f7a 100644
--- a/src/orca/generator.py
+++ b/src/orca/generator.py
@@ -1181,6 +1181,9 @@ class Generator:
                 if isVertical:
                     return object_properties.ROLE_SPLITTER_HORIZONTAL
 
+        if self._script.utilities.isMenuButton(obj):
+            return object_properties.ROLE_MENU_BUTTON
+
         if self._script.utilities.isLandmark(obj):
             if self._script.utilities.isLandmarkBanner(obj):
                 return object_properties.ROLE_LANDMARK_BANNER
diff --git a/src/orca/object_properties.py b/src/orca/object_properties.py
index b88d8a7..3087d93 100644
--- a/src/orca/object_properties.py
+++ b/src/orca/object_properties.py
@@ -202,6 +202,12 @@ ROLE_LANDMARK_SEARCH = C_("role", "search")
 # already read.
 ROLE_VISITED_LINK = _("visited link")
 
+# Translators: This string should be treated as a role describing an object.
+# Examples of roles include "checkbox", "radio button", "paragraph", and "link."
+# A menu button is button widget that causes a menu to appear when the user
+# activates the button.
+ROLE_MENU_BUTTON = _("menu button")
+
 # Translators: This is a state which applies to elements in document content
 # which have an "onClick" action.
 STATE_CLICKABLE = _("clickable")
diff --git a/src/orca/script_utilities.py b/src/orca/script_utilities.py
index f9233fd..c765d31 100644
--- a/src/orca/script_utilities.py
+++ b/src/orca/script_utilities.py
@@ -3225,6 +3225,39 @@ class Utilities:
 
         return child
 
+    def popupMenuFor(self, obj):
+        if not obj and obj.childCount:
+            return None
+
+        menus = [child for child in obj if child.getRole() == pyatspi.ROLE_MENU]
+        for menu in menus:
+            try:
+                state = menu.getState()
+            except:
+                msg = "ERROR: Exception getting state for %s" % menu
+                debug.println(debug.LEVEL_INFO, msg, True)
+                continue
+            if state.contains(pyatspi.STATE_ENABLED):
+                return menu
+
+        return None
+
+    def isMenuButton(self, obj):
+        if not obj:
+            return False
+
+        try:
+            role = obj.getRole()
+        except:
+            msg = "ERROR: Exception getting role for %s" % obj
+            debug.println(debug.LEVEL_INFO, msg, True)
+            return False
+
+        if role not in [pyatspi.ROLE_PUSH_BUTTON, pyatspi.ROLE_TOGGLE_BUTTON]:
+            return False
+
+        return self.popupMenuFor(obj) is not None
+
     def isEntryCompletionPopupItem(self, obj):
         return False
 


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