1
- #This file does not support direct editing
1
+ #此文件不支持直接编辑
2
2
#coding=utf-8
3
3
import os
4
4
from os .path import abspath , dirname
9
9
G_UIElementArray = {}
10
10
G_UIElementVariableArray = {}
11
11
G_UIInputDataArray = {}
12
+ G_UIElementAlias = {}
13
+ G_UIGroupDictionary = {}
14
+ G_UIStyleDictionary = {}
12
15
G_CurrentFilePath = None
13
16
G_CutContent = None
14
17
#注册一个控件,用于记录它:参数1:界面类名, 参数2:控件名称,参数3:控件。
15
- def Register (uiName ,elementName ,element ):
18
+ def Register (uiName ,elementName ,element , alias = None , groupName = None , styleName = None ):
16
19
if uiName not in G_UIElementArray :
17
20
G_UIElementArray [uiName ]= {}
21
+ G_UIElementAlias [uiName ]= {}
22
+ G_UIGroupDictionary [uiName ]= {}
23
+ G_UIStyleDictionary [uiName ]= {}
18
24
G_UIElementArray [uiName ][elementName ]= element
25
+ if alias :
26
+ G_UIElementAlias [uiName ][alias ]= elementName
27
+ if groupName :
28
+ G_UIGroupDictionary [uiName ][elementName ]= groupName
29
+ if styleName :
30
+ G_UIStyleDictionary [uiName ][elementName ]= styleName
19
31
#取得控件:参数1:界面类名, 参数2:控件名称。
20
32
def GetElement (uiName ,elementName ):
21
- global G_UIElementArray
33
+ if uiName in G_UIElementAlias :
34
+ if uiName in G_UIElementAlias .keys () and elementName in G_UIElementAlias [uiName ].keys ():
35
+ elementName = G_UIElementArray [uiName ][elementName ]
22
36
if uiName in G_UIElementArray :
23
37
if elementName in G_UIElementArray [uiName ]:
24
38
return G_UIElementArray [uiName ][elementName ]
@@ -42,18 +56,33 @@ def AddTKVariable(uiName,elementName,defaultValue = None):
42
56
#设置控件的tkinter变量.参数1:界面类名, 参数2:控件名称,参数3:值。
43
57
def SetTKVariable (uiName ,elementName ,value ):
44
58
if uiName in G_UIElementVariableArray :
59
+ if uiName in G_UIElementAlias .keys () and elementName in G_UIElementAlias [uiName ].keys ():
60
+ elementName = G_UIElementAlias [uiName ][elementName ]
45
61
if elementName in G_UIElementVariableArray [uiName ]:
46
62
G_UIElementVariableArray [uiName ][elementName ].set (value )
63
+ if elementName in G_UIGroupDictionary [uiName ]:
64
+ GroupName = G_UIGroupDictionary [uiName ][elementName ]
65
+ if GroupName in G_UIElementVariableArray [uiName ]:
66
+ G_UIElementVariableArray [uiName ][GroupName ].set (value )
47
67
#取得控件的tkinter变量.参数1:界面类名, 参数2:控件名称。
48
68
def GetTKVariable (uiName ,elementName ):
49
69
if uiName in G_UIElementVariableArray :
70
+ if uiName in G_UIElementAlias .keys () and elementName in G_UIElementAlias [uiName ].keys ():
71
+ elementName = G_UIElementAlias [uiName ][elementName ]
50
72
if elementName in G_UIElementVariableArray [uiName ]:
51
73
return G_UIElementVariableArray [uiName ][elementName ].get ()
74
+ if elementName in G_UIGroupDictionary [uiName ]:
75
+ GroupName = G_UIGroupDictionary [uiName ][elementName ]
76
+ if GroupName in G_UIElementVariableArray [uiName ]:
77
+ return G_UIElementVariableArray [uiName ][GroupName ].get ()
78
+ return None
52
79
#为控件添加一个用户数据,参数dataname为数据名,datatype为数据类型,可以包括int、float、string、list、dictionary等,一般在设计软件中用鼠标右键操作控件,在弹出的“绑定数据”对话枉中设置,参数datavalue为数据值,而ismaptotext则是是否将数据直接反映到控件的text变量中。
53
80
def AddUserData (uiName ,elementName ,dataName ,datatype ,datavalue ,isMapToText ):
54
81
global G_UIElementUserDataArray
55
82
if uiName not in G_UIElementUserDataArray :
56
83
G_UIElementUserDataArray [uiName ]= {}
84
+ if uiName in G_UIElementAlias .keys () and elementName in G_UIElementAlias [uiName ].keys ():
85
+ elementName = G_UIElementAlias [uiName ][elementName ]
57
86
if elementName not in G_UIElementUserDataArray [uiName ]:
58
87
G_UIElementUserDataArray [uiName ][elementName ]= []
59
88
G_UIElementUserDataArray [uiName ][elementName ].append ([dataName ,datatype ,datavalue ,isMapToText ])
@@ -62,6 +91,8 @@ def SetUserData(uiName,elementName,dataName,datavalue):
62
91
global G_UIElementArray
63
92
global G_UIElementUserDataArray
64
93
if uiName in G_UIElementUserDataArray :
94
+ if uiName in G_UIElementAlias .keys () and elementName in G_UIElementAlias [uiName ].keys ():
95
+ elementName = G_UIElementAlias [uiName ][elementName ]
65
96
if elementName in G_UIElementUserDataArray [uiName ]:
66
97
for EBData in G_UIElementUserDataArray [uiName ][elementName ]:
67
98
if EBData [0 ] == dataName :
@@ -73,6 +104,8 @@ def SetUserData(uiName,elementName,dataName,datavalue):
73
104
def GetUserData (uiName ,elementName ,dataName ):
74
105
global G_UIElementUserDataArray
75
106
if uiName in G_UIElementUserDataArray :
107
+ if uiName in G_UIElementAlias .keys () and elementName in G_UIElementAlias [uiName ].keys ():
108
+ elementName = G_UIElementAlias [uiName ][elementName ]
76
109
if elementName in G_UIElementUserDataArray [uiName ]:
77
110
for EBData in G_UIElementUserDataArray [uiName ][elementName ]:
78
111
if EBData [0 ] == dataName :
@@ -87,19 +120,24 @@ def GetUserData(uiName,elementName,dataName):
87
120
def SetTKAttrib (uiName ,elementName ,AttribName ,attribValue ):
88
121
global G_UIElementArray
89
122
if uiName in G_UIElementArray :
123
+ if uiName in G_UIElementAlias .keys () and elementName in G_UIElementAlias [uiName ].keys ():
124
+ elementName = G_UIElementAlias [uiName ][elementName ]
90
125
if AttribName in G_UIElementArray [uiName ][elementName ].configure ().keys ():
91
126
G_UIElementArray [uiName ][elementName ][AttribName ]= attribValue
92
127
#获取控件的tkinter属性值。
93
128
def GetTKAttrib (uiName ,elementName ,AttribName ):
94
129
global G_UIElementArray
95
130
if uiName in G_UIElementArray :
131
+ if uiName in G_UIElementAlias .keys () and elementName in G_UIElementAlias [uiName ].keys ():
132
+ elementName = G_UIElementAlias [uiName ][elementName ]
96
133
return G_UIElementArray [uiName ][elementName ].cget (AttribName )
97
- return None
98
134
#设置控件的文本(label, button, entry and text)。
99
135
def SetText (uiName ,elementName ,textValue ):
100
136
global G_UIElementArray
101
137
global G_UIElementVariableArray
102
138
showtext = str ("%s" % textValue )
139
+ if uiName in G_UIElementAlias .keys () and elementName in G_UIElementAlias [uiName ].keys ():
140
+ elementName = G_UIElementAlias [uiName ][elementName ]
103
141
if uiName in G_UIElementVariableArray :
104
142
if elementName in G_UIElementVariableArray [uiName ]:
105
143
G_UIElementVariableArray [uiName ][elementName ].set (showtext )
@@ -115,6 +153,8 @@ def SetText(uiName,elementName,textValue):
115
153
def GetText (uiName ,elementName ):
116
154
global G_UIElementArray
117
155
global G_UIElementVariableArray
156
+ if uiName in G_UIElementAlias .keys () and elementName in G_UIElementAlias [uiName ].keys ():
157
+ elementName = G_UIElementAlias [uiName ][elementName ]
118
158
if uiName in G_UIElementVariableArray :
119
159
if elementName in G_UIElementVariableArray [uiName ]:
120
160
return G_UIElementVariableArray [uiName ][elementName ].get ()
@@ -130,6 +170,8 @@ def GetText(uiName,elementName):
130
170
#设置控件的背景图片(Label,Button)。
131
171
def SetImage (uiName ,elementName ,imagePath ):
132
172
global G_UIElementVariableArray
173
+ if uiName in G_UIElementAlias .keys () and elementName in G_UIElementAlias [uiName ].keys ():
174
+ elementName = G_UIElementAlias [uiName ][elementName ]
133
175
if elementName .find ('Label_' ) == 0 or elementName .find ('Button_' ) == 0 :
134
176
Control = GetElement (uiName ,elementName )
135
177
if Control != None :
@@ -153,6 +195,8 @@ def SetImage(uiName,elementName,imagePath):
153
195
#获取控件的背景图像文件(标签、按钮)。
154
196
def GetImage (uiName ,elementName ):
155
197
global G_UIElementVariableArray
198
+ if uiName in G_UIElementAlias .keys () and elementName in G_UIElementAlias [uiName ].keys ():
199
+ elementName = G_UIElementAlias [uiName ][elementName ]
156
200
if elementName .find ('Label_' ) == 0 or elementName .find ('Button_' ) == 0 :
157
201
Control = GetElement (uiName ,elementName )
158
202
if Control != None :
@@ -164,6 +208,8 @@ def GetImage(uiName,elementName):
164
208
return str ("" )
165
209
#设置ListBox和ComboBox的选中项。
166
210
def SetSelectIndex (uiName ,elementName ,index ):
211
+ if uiName in G_UIElementAlias .keys () and elementName in G_UIElementAlias [uiName ].keys ():
212
+ elementName = G_UIElementAlias [uiName ][elementName ]
167
213
Control = GetElement (uiName ,elementName )
168
214
if Control != None :
169
215
if elementName .find ('ComboBox_' ) == 0 :
@@ -172,6 +218,8 @@ def SetSelectIndex(uiName,elementName,index):
172
218
Control .select_set (index )
173
219
#取得ListBox和ComboBox的选中项。
174
220
def GetSelectIndex (uiName ,elementName ):
221
+ if uiName in G_UIElementAlias .keys () and elementName in G_UIElementAlias [uiName ].keys ():
222
+ elementName = G_UIElementAlias [uiName ][elementName ]
175
223
Control = GetElement (uiName ,elementName )
176
224
if Control != None :
177
225
if elementName .find ('ComboBox_' ) == 0 :
@@ -195,15 +243,17 @@ def InitElementStyle(uiName,Style):
195
243
StyleArray = ReadStyleFile (Style + ".py" )
196
244
global G_UIElementArray
197
245
if uiName in G_UIElementArray :
246
+ Root = GetElement (uiName ,'root' )
247
+ TFormKey = '.TForm'
248
+ if TFormKey in StyleArray :
249
+ if 'background' in StyleArray [TFormKey ]:
250
+ Root ['background' ] = StyleArray [TFormKey ]['background' ]
198
251
for elementName in G_UIElementArray [uiName ].keys ():
199
252
Widget = G_UIElementArray [uiName ][elementName ]
200
253
try :
201
254
if Widget .winfo_exists () == 1 :
202
255
WinClass = Widget .winfo_class ()
203
256
StyleName = ".T" + WinClass
204
- if StyleName == '.TLabel' :
205
- Root = GetElement (uiName ,'root' )
206
- Root ['background' ] = StyleArray [StyleName ]['background' ]
207
257
for attribute in StyleArray [StyleName ].keys ():
208
258
Widget [attribute ] = StyleArray [StyleName ][attribute ]
209
259
except BaseException :
0 commit comments