-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlabelFromUWPObj.py
More file actions
36 lines (30 loc) · 1.26 KB
/
labelFromUWPObj.py
File metadata and controls
36 lines (30 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# -*- coding: UTF-8 -*-
# LabelAutofinder module
# Copyright (C) 2025 Alberto Buffolino
# Released under GPL 2
import UIAHandler
from NVDAObjects.UIA import UIA
from .explorers import ObjExplorer
from .search import SearchConfig
from .utils import debugLog, measureTime
def getLabelFromUWPObj(obj, config):
# recreate config, to specify strategy
config = SearchConfig(oldConfig=config, obj=obj, strategy="uwp")
staticUIAElements = getAllStaticUIAElements(config.maxParent)
if not staticUIAElements:
debugLog("No UIA elements found!")
return
objRect = config.obj.location.toLTRB()
# explorer that looks for labels around obj
explorer = ObjExplorer(objRect, config)
staticObjs = [UIA(UIAElement=element) for element in staticUIAElements]
res = explorer.getDistanceAndLabelText(staticObjs)
return res
# to collect UIAElement of all TextBlock objs
def getAllStaticUIAElements(parent):
client = UIAHandler.handler.clientObject
classCondition = client.CreatePropertyCondition(UIAHandler.UIA_ClassNamePropertyId, "TextBlock")
cacheRequest = UIAHandler.handler.baseCacheRequest
UIAArray = parent.UIAElement.FindAllBuildCache(UIAHandler.TreeScope_Descendants, classCondition, cacheRequest)
results = [UIAArray.GetElement(n) for n in range(UIAArray.Length)]
return results