OSDN Git Service

Developer Guide: Provide a better example for overlay classes, since simple labelling...
authorJames Teh <jamie@jantrid.net>
Tue, 14 Aug 2012 04:22:43 +0000 (14:22 +1000)
committerJames Teh <jamie@jantrid.net>
Tue, 14 Aug 2012 04:22:43 +0000 (14:22 +1000)
developerGuide.t2t

index ca19bbd..e0375fc 100644 (file)
@@ -508,26 +508,34 @@ Inside this method, you should decide which custom NVDA Object class(es) (if any
 If a custom class should be used, it must be inserted into the class list, usually at the beginning.\r
 You can also remove classes chosen by NVDA from the class list, although this is rarely required.\r
 \r
-++ Example 5: Labelling the Notepad Edit Field using a Custom NVDA Object ++\r
-This app module for notepad makes NVDA report Notepad's main edit field as having a name of "content".\r
-That is, when it receives focus, NVDA will say "Content edit".\r
+++ Example 5: Command to Retrieve the Length of Text in an Edit Field Using a Custom NVDA Object ++\r
+This app module for notepad provides a command to report the number of characters in edit fields.\r
+You can activate it using NVDA+l.\r
+Notice that the command is specific to edit fields; i.e. it only works while you are focused in an edit field, rather than anywhere in the application.\r
 \r
 The following code can be copied and pasted in to a text file, then saved in the appModules directory with the name of notepad.py.\r
 \r
 ```\r
 --- start ---\r
 import appModuleHandler\r
-from NVDAObjects.window import Window\r
+from NVDAObjects.IAccessible import IAccessible\r
+import controlTypes\r
+import ui\r
 \r
 class AppModule(appModuleHandler.AppModule):\r
 \r
        def chooseNVDAObjectOverlayClasses(self, obj, clsList):\r
-               if isinstance(obj, Window) and obj.windowClassName == "Edit" and obj.windowControlID == 15:\r
-                       clsList.insert(0, LabelledEditField)\r
+               if obj.windowClassName == "Edit" and obj.role == controlTypes.ROLE_EDITABLETEXT:\r
+                       clsList.insert(0, EnhancedEditField)\r
+\r
+class EnhancedEditField(IAccessible):\r
 \r
-class LabelledEditField(Window):\r
+       def script_reportLength(self, gesture):\r
+               ui.message("%d" % len(self.value))\r
 \r
-       name="Content"\r
+       __gestures = {\r
+               "kb:NVDA+l": "reportLength",\r
+       }\r
 \r
 --- end ---\r
 ```\r
@@ -544,7 +552,7 @@ The event_NVDAObject_init method takes two arguments:
 \r
 Inside this method, you can check whether this object is relevant and then override properties accordingly.\r
 \r
-++ Example 5: Labelling the Notepad Edit Field Using event_NVDAObject_init ++\r
+++ Example 6: Labelling the Notepad Edit Field Using event_NVDAObject_init ++\r
 This app module for notepad makes NVDA report Notepad's main edit field as having a name of "content".\r
 That is, when it receives focus, NVDA will say "Content edit".\r
 \r