-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_region_selector.py
More file actions
74 lines (60 loc) · 2.07 KB
/
test_region_selector.py
File metadata and controls
74 lines (60 loc) · 2.07 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python3
"""测试区域选择器的脚本"""
import sys
import os
import tempfile
import json
from region_selector import RegionSelector
def create_test_layout_file():
"""创建测试用的布局文件"""
layout = [
['1', '2', '3', '4', '5'],
['q', 'w', 'e', 'r', 't'],
['a', 's', 'd', 'f', 'g'],
['z', 'x', 'c', 'v', 'b']
]
temp_dir = tempfile.gettempdir()
layout_file = os.path.join(temp_dir, "test_layout.tmp")
coords_file = os.path.join(temp_dir, "test_coords.tmp")
with open(layout_file, 'w', encoding='utf-8') as f:
json.dump(layout, f)
print(f"布局文件创建于: {layout_file}")
print(f"坐标文件将输出到: {coords_file}")
return layout_file, coords_file
def main():
print("开始测试区域选择器...")
# 创建测试文件
layout_file, coords_file = create_test_layout_file()
try:
# 启动区域选择器
app = RegionSelector(
[
['1', '2', '3', '4', '5'],
['q', 'w', 'e', 'r', 't'],
['a', 's', 'd', 'f', 'g'],
['z', 'x', 'c', 'v', 'b']
],
coords_file
)
print("区域选择器已启动。按任意布局上的键来选择区域...")
print("第一级:选择大区域(数字1-5或字母q-t等)")
print("第二级:选择精确位置")
print("按ESC或点击空白区域退出")
app.mainloop()
# 检查结果
if os.path.exists(coords_file):
with open(coords_file, 'r', encoding='utf-8') as f:
coords = f.read().strip()
if coords:
print(f"选择的坐标: {coords}")
else:
print("没有选择任何坐标")
os.remove(coords_file)
else:
print("没有生成坐标文件")
finally:
# 清理
if os.path.exists(layout_file):
os.remove(layout_file)
if __name__ == "__main__":
main()