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
\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