OSDN Git Service

NVDAObject: Add isFocusable and hasFocus properties.
authorJames Teh <jamie@jantrid.net>
Mon, 10 Sep 2012 06:44:46 +0000 (16:44 +1000)
committerJames Teh <jamie@jantrid.net>
Mon, 10 Sep 2012 06:44:46 +0000 (16:44 +1000)
The base implementation just checks states, but subclasses may wish to override these rather than using states, as fetching all states can be expensive.

source/NVDAObjects/__init__.py

index 8b98d30..c5b3fae 100644 (file)
@@ -659,6 +659,18 @@ class NVDAObject(baseObject.ScriptableObject):
                """\r
                return None\r
 \r
+       def _get_isFocusable(self):\r
+               """Whether this object is focusable.\r
+               @rtype: bool\r
+               """\r
+               return controlTypes.STATE_FOCUSABLE in self.states\r
+\r
+       def _get_hasFocus(self):\r
+               """Whether this object has focus.\r
+               @rtype: bool\r
+               """\r
+               return controlTypes.STATE_FOCUSED in self.states\r
+\r
        def setFocus(self):\r
                """\r
 Tries to force this object to take the focus.\r
@@ -910,6 +922,16 @@ This code is executed if a gain focus event is received by this object.
                        ret = "exception: %s" % e\r
                info.append("states: %s" % ret)\r
                try:\r
+                       ret = repr(self.isFocusable)\r
+               except Exception as e:\r
+                       ret = "exception: %s" % e\r
+               info.append("isFocusable: %s" % ret)\r
+               try:\r
+                       ret = repr(self.hasFocus)\r
+               except Exception as e:\r
+                       ret = "exception: %s" % e\r
+               info.append("hasFocus: %s" % ret)\r
+               try:\r
                        ret = repr(self)\r
                except Exception as e:\r
                        ret = "exception: %s" % e\r