-
Notifications
You must be signed in to change notification settings - Fork 0
/
BridgeN.py
95 lines (75 loc) · 2.36 KB
/
BridgeN.py
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
"""
桥接层
通过分析原GUI文件自动生成新GUI-class
与旧Bridge不同,这是一种新的实现思路,基于exec()
"""
import wx, wx.xrc
import cuwx
def Analyze(path):
"""
打开GUI文件并开始分析
---
arg:
path : str -> 文件路径
doc:
wx.Sizer
wx.Butt
针对wxFormBuilder (version 3.10.1-0-g8feb16b3)
"""
with open(path, "r", encoding="utf8") as data:
# Step:过滤无关字符
data_Dec = [] # 过滤后代码行list
for i in data.readlines():
##i = i.replace('\n','')
##i = i.replace('\t','')
if i == "":
pass
elif i[0] == "#":
pass
else:
data_Dec.append(i)
print("GUI有效行数:", len(data_Dec))
##print(data_Dec)
# Step:对控件进行调换wx.XX -> cuwx.XX
# TODO:支持更多控件的替换
cun = 0
for i in data_Dec:
if "Switch" in i and "=" in i:
head = i[: i.find("=") + 2]
bot = i[i.find("=") + 11 :]
mid = "cuwx.ToggleSwitch.ToggleSwitchN"
combin = head + mid + bot
data_Dec[cun] = combin
elif "wx.ToggleButton" in i and "=" in i:
head = i[: i.find("=") + 2]
bot = i[i.find("=") + 17 :]
mid = "cuwx.ToggleButton.ToggleButtonN"
combin = head + mid + bot
data_Dec[cun] = combin
elif "wx.Button" in i and "=" in i:
head = i[: i.find("=") + 2]
bot = i[i.find("=") + 11 :]
mid = "cuwx.Button.ButtonN"
combin = head + mid + bot
data_Dec[cun] = combin
elif "wx.CheckBox" in i and "=" in i:
head = i[: i.find("=") + 2]
bot = i[i.find("=") + 13 :]
mid = "cuwx.CheckBox.CheckBoxN"
combin = head + mid + bot
data_Dec[cun] = combin
elif "wx.ComboBox" in i and "=" in i:
head = i[: i.find("=") + 2]
bot = i[i.find("=") + 13 :]
mid = "cuwx.ComboBox.ComboBoxN"
combin = head + mid + bot
data_Dec[cun] = combin
cun = cun + 1
##print(data_Dec)
# Step:合并字符串
a = ""
for i in data_Dec:
a = a + i
return a
if __name__ == "__main__":
Analyze("./GUI_Base.py")