Skip to content

Commit a0b2fff

Browse files
authored
Merge 35ee022 into 99a9ea8
2 parents 99a9ea8 + 35ee022 commit a0b2fff

1 file changed

Lines changed: 18 additions & 9 deletions

File tree

source/appModules/notepad.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
# A part of NonVisual Desktop Access (NVDA)
2-
# Copyright (C) 2022 NV Access Limited, Joseph Lee
2+
# Copyright (C) 2022-2023 NV Access Limited, Joseph Lee
33
# This file is covered by the GNU General Public License.
44
# See the file COPYING for more details.
55

66
"""App module for Windows Notepad.
77
While this app module also covers older Notepad releases,
88
this module provides workarounds for Windows 11 Notepad."""
99

10+
from comtypes import COMError
1011
import appModuleHandler
1112
import api
13+
import UIAHandler
14+
from NVDAObjects.UIA import UIA
15+
from NVDAObjects import NVDAObject
1216

1317

1418
class AppModule(appModuleHandler.AppModule):
1519

16-
def _get_statusBar(self):
20+
def _get_statusBar(self) -> NVDAObject:
1721
"""Retrieves Windows 11 Notepad status bar.
1822
In Windows 10 and earlier, status bar can be obtained by looking at the bottom of the screen.
1923
Windows 11 Notepad uses Windows 11 UI design (top-level window is labeled "DesktopWindowXamlSource",
@@ -32,11 +36,16 @@ def _get_statusBar(self):
3236
# Thankfully, of all the UIA objects encountered, document window has a unique window class name.
3337
if api.getFocusObject().windowClassName != "RichEditD2DPT":
3438
raise NotImplementedError()
35-
# Look for a specific child as some children report the same UIA properties such as class name.
36-
# Make sure to look for a foreground UIA element which hosts status bar content if visible.
37-
notepadStatusBarIndex = 7
38-
statusBar = api.getForegroundObject().children[notepadStatusBarIndex].firstChild
39-
# No location for a disabled status bar i.e. location is 0 (x, y, width, height).
40-
if not any(statusBar.location):
41-
raise NotImplementedError()
39+
# Obtain status bar text across Notepad 11 releases.
40+
clientObject = UIAHandler.handler.clientObject
41+
condition = clientObject.createPropertyCondition(UIAHandler.UIA_AutomationIdPropertyId, "ContentTextBlock")
42+
walker = clientObject.createTreeWalker(condition)
43+
notepadWindow = UIAHandler.handler.clientObject.elementFromHandle(api.getForegroundObject().windowHandle)
44+
try:
45+
element = walker.getFirstChildElement(notepadWindow)
46+
# Is status bar even showing?
47+
element = element.buildUpdatedCache(UIAHandler.handler.baseCacheRequest)
48+
except (ValueError, COMError):
49+
raise NotImplementedError
50+
statusBar = UIA(UIAElement=element).parent
4251
return statusBar

0 commit comments

Comments
 (0)