1- #This file does not support direct editing
1+ #此文件不支持直接编辑
22#coding=utf-8
33import os
44from os .path import abspath , dirname
99G_UIElementArray = {}
1010G_UIElementVariableArray = {}
1111G_UIInputDataArray = {}
12+ G_UIElementAlias = {}
13+ G_UIGroupDictionary = {}
14+ G_UIStyleDictionary = {}
1215G_CurrentFilePath = None
1316G_CutContent = None
1417#注册一个控件,用于记录它:参数1:界面类名, 参数2:控件名称,参数3:控件。
15- def Register (uiName ,elementName ,element ):
18+ def Register (uiName ,elementName ,element , alias = None , groupName = None , styleName = None ):
1619 if uiName not in G_UIElementArray :
1720 G_UIElementArray [uiName ]= {}
21+ G_UIElementAlias [uiName ]= {}
22+ G_UIGroupDictionary [uiName ]= {}
23+ G_UIStyleDictionary [uiName ]= {}
1824 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
1931#取得控件:参数1:界面类名, 参数2:控件名称。
2032def 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 ]
2236 if uiName in G_UIElementArray :
2337 if elementName in G_UIElementArray [uiName ]:
2438 return G_UIElementArray [uiName ][elementName ]
@@ -42,18 +56,33 @@ def AddTKVariable(uiName,elementName,defaultValue = None):
4256#设置控件的tkinter变量.参数1:界面类名, 参数2:控件名称,参数3:值。
4357def SetTKVariable (uiName ,elementName ,value ):
4458 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 ]
4561 if elementName in G_UIElementVariableArray [uiName ]:
4662 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 )
4767#取得控件的tkinter变量.参数1:界面类名, 参数2:控件名称。
4868def GetTKVariable (uiName ,elementName ):
4969 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 ]
5072 if elementName in G_UIElementVariableArray [uiName ]:
5173 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
5279#为控件添加一个用户数据,参数dataname为数据名,datatype为数据类型,可以包括int、float、string、list、dictionary等,一般在设计软件中用鼠标右键操作控件,在弹出的“绑定数据”对话枉中设置,参数datavalue为数据值,而ismaptotext则是是否将数据直接反映到控件的text变量中。
5380def AddUserData (uiName ,elementName ,dataName ,datatype ,datavalue ,isMapToText ):
5481 global G_UIElementUserDataArray
5582 if uiName not in G_UIElementUserDataArray :
5683 G_UIElementUserDataArray [uiName ]= {}
84+ if uiName in G_UIElementAlias .keys () and elementName in G_UIElementAlias [uiName ].keys ():
85+ elementName = G_UIElementAlias [uiName ][elementName ]
5786 if elementName not in G_UIElementUserDataArray [uiName ]:
5887 G_UIElementUserDataArray [uiName ][elementName ]= []
5988 G_UIElementUserDataArray [uiName ][elementName ].append ([dataName ,datatype ,datavalue ,isMapToText ])
@@ -62,6 +91,8 @@ def SetUserData(uiName,elementName,dataName,datavalue):
6291 global G_UIElementArray
6392 global G_UIElementUserDataArray
6493 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 ]
6596 if elementName in G_UIElementUserDataArray [uiName ]:
6697 for EBData in G_UIElementUserDataArray [uiName ][elementName ]:
6798 if EBData [0 ] == dataName :
@@ -73,6 +104,8 @@ def SetUserData(uiName,elementName,dataName,datavalue):
73104def GetUserData (uiName ,elementName ,dataName ):
74105 global G_UIElementUserDataArray
75106 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 ]
76109 if elementName in G_UIElementUserDataArray [uiName ]:
77110 for EBData in G_UIElementUserDataArray [uiName ][elementName ]:
78111 if EBData [0 ] == dataName :
@@ -87,19 +120,24 @@ def GetUserData(uiName,elementName,dataName):
87120def SetTKAttrib (uiName ,elementName ,AttribName ,attribValue ):
88121 global G_UIElementArray
89122 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 ]
90125 if AttribName in G_UIElementArray [uiName ][elementName ].configure ().keys ():
91126 G_UIElementArray [uiName ][elementName ][AttribName ]= attribValue
92127#获取控件的tkinter属性值。
93128def GetTKAttrib (uiName ,elementName ,AttribName ):
94129 global G_UIElementArray
95130 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 ]
96133 return G_UIElementArray [uiName ][elementName ].cget (AttribName )
97- return None
98134#设置控件的文本(label, button, entry and text)。
99135def SetText (uiName ,elementName ,textValue ):
100136 global G_UIElementArray
101137 global G_UIElementVariableArray
102138 showtext = str ("%s" % textValue )
139+ if uiName in G_UIElementAlias .keys () and elementName in G_UIElementAlias [uiName ].keys ():
140+ elementName = G_UIElementAlias [uiName ][elementName ]
103141 if uiName in G_UIElementVariableArray :
104142 if elementName in G_UIElementVariableArray [uiName ]:
105143 G_UIElementVariableArray [uiName ][elementName ].set (showtext )
@@ -115,6 +153,8 @@ def SetText(uiName,elementName,textValue):
115153def GetText (uiName ,elementName ):
116154 global G_UIElementArray
117155 global G_UIElementVariableArray
156+ if uiName in G_UIElementAlias .keys () and elementName in G_UIElementAlias [uiName ].keys ():
157+ elementName = G_UIElementAlias [uiName ][elementName ]
118158 if uiName in G_UIElementVariableArray :
119159 if elementName in G_UIElementVariableArray [uiName ]:
120160 return G_UIElementVariableArray [uiName ][elementName ].get ()
@@ -130,6 +170,8 @@ def GetText(uiName,elementName):
130170#设置控件的背景图片(Label,Button)。
131171def SetImage (uiName ,elementName ,imagePath ):
132172 global G_UIElementVariableArray
173+ if uiName in G_UIElementAlias .keys () and elementName in G_UIElementAlias [uiName ].keys ():
174+ elementName = G_UIElementAlias [uiName ][elementName ]
133175 if elementName .find ('Label_' ) == 0 or elementName .find ('Button_' ) == 0 :
134176 Control = GetElement (uiName ,elementName )
135177 if Control != None :
@@ -153,6 +195,8 @@ def SetImage(uiName,elementName,imagePath):
153195#获取控件的背景图像文件(标签、按钮)。
154196def GetImage (uiName ,elementName ):
155197 global G_UIElementVariableArray
198+ if uiName in G_UIElementAlias .keys () and elementName in G_UIElementAlias [uiName ].keys ():
199+ elementName = G_UIElementAlias [uiName ][elementName ]
156200 if elementName .find ('Label_' ) == 0 or elementName .find ('Button_' ) == 0 :
157201 Control = GetElement (uiName ,elementName )
158202 if Control != None :
@@ -164,6 +208,8 @@ def GetImage(uiName,elementName):
164208 return str ("" )
165209#设置ListBox和ComboBox的选中项。
166210def SetSelectIndex (uiName ,elementName ,index ):
211+ if uiName in G_UIElementAlias .keys () and elementName in G_UIElementAlias [uiName ].keys ():
212+ elementName = G_UIElementAlias [uiName ][elementName ]
167213 Control = GetElement (uiName ,elementName )
168214 if Control != None :
169215 if elementName .find ('ComboBox_' ) == 0 :
@@ -172,6 +218,8 @@ def SetSelectIndex(uiName,elementName,index):
172218 Control .select_set (index )
173219#取得ListBox和ComboBox的选中项。
174220def GetSelectIndex (uiName ,elementName ):
221+ if uiName in G_UIElementAlias .keys () and elementName in G_UIElementAlias [uiName ].keys ():
222+ elementName = G_UIElementAlias [uiName ][elementName ]
175223 Control = GetElement (uiName ,elementName )
176224 if Control != None :
177225 if elementName .find ('ComboBox_' ) == 0 :
@@ -195,15 +243,17 @@ def InitElementStyle(uiName,Style):
195243 StyleArray = ReadStyleFile (Style + ".py" )
196244 global G_UIElementArray
197245 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' ]
198251 for elementName in G_UIElementArray [uiName ].keys ():
199252 Widget = G_UIElementArray [uiName ][elementName ]
200253 try :
201254 if Widget .winfo_exists () == 1 :
202255 WinClass = Widget .winfo_class ()
203256 StyleName = ".T" + WinClass
204- if StyleName == '.TLabel' :
205- Root = GetElement (uiName ,'root' )
206- Root ['background' ] = StyleArray [StyleName ]['background' ]
207257 for attribute in StyleArray [StyleName ].keys ():
208258 Widget [attribute ] = StyleArray [StyleName ][attribute ]
209259 except BaseException :
0 commit comments