中文 | English
API: UIA ProgressBar
The ProgressBar control displays the progress of an operation, such as loading progress, download progress, or installation progress.
Important: ProgressBars are usually read-only; their value cannot be set via script.
Finding a ProgressBar
Note: ProgressBars usually have descriptive names.
from wingman import uia
# 查找名为"下载进度"的进度条
progress = uia.find_by_name("下载进度")
if progress:
print("找到进度条")2
3
4
5
6
Getting the progress value
Not implemented (planned): The
get_info()return keys have no numeric progress field (novalue/minimum/maximum);get_value()returns the element text (implemented asgetText), not a numeric progress. If the application happens to write the progress into the element text/name (e.g. "80%"), you can read it viaget_value()and parse it yourself, but this is not a guaranteed form.
from wingman import uia
progress = uia.find_by_name("安装进度")
if progress:
# get_info 无数值进度字段,这里只读取通用信息
info = progress["get_info"]()
print(f"名称: {info.get('name', '')}")
# get_value 返回元素文本(部分应用会写入进度文本)
text = progress["get_value"]()
print(f"元素文本: {text}")2
3
4
5
6
7
8
9
10
11
Waiting for progress to complete
Note: Poll the progress bar until it reaches 100% or times out.
Use cases:
- Wait for a file download to finish
- Wait for an installation to finish
- Wait for loading to finish
from wingman import uia, util
def wait_for_progress_complete(progress_name, timeout=30000):
"""
等待进度完成
参数:
progress_name: 进度条名称
timeout: 超时时间(毫秒),默认 30 秒
返回:
True 表示完成,False 表示超时
"""
start_time = util.get_time()
while util.get_time() - start_time < timeout:
progress = uia.find_by_name(progress_name)
if progress:
# get_info 无数值进度字段;若应用把进度写进元素文本(如 "100%"),
# 可经 get_value() 读取并自行解析
text = progress["get_value"]() or ""
if "100" in text:
print("进度完成!")
return True
util.sleep(500) # 每 0.5 秒检查一次
print("等待超时")
return False
# 使用
if wait_for_progress_complete("安装进度", 60000):
print("安装已完成")
else:
print("安装未完成(超时)")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
Available Interfaces
| Python function | Lua function | Description |
|---|---|---|
find_by_name(name) | find_by_name(name) | Find by name |
| Python method | Lua method | Description |
|---|---|---|
get_value() | :get_value() | Get the element text (not a numeric progress; see above) |
get_info() | :get_info() | Get general information about the progress bar |
Note: ProgressBars are usually read-only; their value cannot be set via script.