-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
56 lines (47 loc) · 1.33 KB
/
utils.py
File metadata and controls
56 lines (47 loc) · 1.33 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# -*- coding: UTF-8 -*-
# LabelAutofinder module
# Copyright (C) 2025 Alberto Buffolino
# Released under GPL 2
import time
from contextlib import contextmanager
from ctypes import windll
from logHandler import log
# to enable debug
DEBUG = False
# for logging
def debugLog(message):
if DEBUG:
log.info(message)
# for testing performances
@contextmanager
def measureTime(label):
start = time.time()
try:
yield
finally:
end = time.time()
log.info("%s: %.3f s"%(label, end-start))
# for forcing obj to correctly refresh its text content,
# useful in some (Delphi?) software;
# see SetWindowPos documentation:
# https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setwindowpos
SWP_FRAMECHANGED = 0x0020
SWP_NOCOPYBITS = 0x0100
SWP_NOMOVE = 0x0002
SWP_NOREPOSITION = 0x0200
SWP_NOSIZE = 0x0001
SWP_NOZORDER = 0x0004
SWP_SHOWWINDOW = 0x0040
# join together
SWP_FLAGS = SWP_FRAMECHANGED|SWP_NOCOPYBITS|SWP_NOMOVE|SWP_NOREPOSITION|SWP_NOSIZE|SWP_NOZORDER|SWP_SHOWWINDOW
def refreshTextContent(obj):
windll.user32.SetWindowPos(obj.windowHandle, None, None, None, None, None, SWP_FLAGS)
# generate ancestors of any obj
# in bottom-top order
def getReversedAncestors(obj, roleStop=None):
while (parent := obj.parent):
# useful for web strategy
yield parent
if roleStop and parent.role == roleStop:
return
obj = parent