|
| 1 | +#This file does not support direct editing |
| 2 | +#coding=utf-8 |
| 3 | +import os |
| 4 | +from os.path import abspath, dirname |
| 5 | +import tkinter |
| 6 | +import tkinter.simpledialog |
| 7 | + |
| 8 | +G_ElementBindingDataArray={} |
| 9 | +G_UIElementArray={} |
| 10 | +G_UIElementVariableArray={} |
| 11 | +G_UIInputDataArray={} |
| 12 | +#Add Element to G_UIElementArray:Param1:uiName, Param2:elementName,Param3:element |
| 13 | +def AddElement(uiName,elementName,element): |
| 14 | + if uiName not in G_UIElementArray: |
| 15 | + G_UIElementArray[uiName]={} |
| 16 | + G_UIElementArray[uiName][elementName]=element |
| 17 | +#Add Data to G_UIElementVariableArray:Param1:uiName, Param2:elementName |
| 18 | +def AddElementVariable(uiName,elementName): |
| 19 | + if uiName not in G_UIElementVariableArray: |
| 20 | + G_UIElementVariableArray[uiName]={} |
| 21 | + NameLower = elementName.lower() |
| 22 | + if NameLower.find('combobox_') >= 0: |
| 23 | + G_UIElementVariableArray[uiName][elementName]=tkinter.IntVar() |
| 24 | + elif NameLower.find('group_') >= 0: |
| 25 | + G_UIElementVariableArray[uiName][elementName]=tkinter.IntVar() |
| 26 | + elif NameLower.find('checkbutton_') >= 0: |
| 27 | + G_UIElementVariableArray[uiName][elementName]=tkinter.BooleanVar() |
| 28 | + else: |
| 29 | + G_UIElementVariableArray[uiName][elementName]=tkinter.StringVar() |
| 30 | + return G_UIElementVariableArray[uiName][elementName] |
| 31 | +#Set Data of G_UIElementVariableArray:Param1:uiName, Param2:elementName, Param3:value |
| 32 | +def SetElementVariable(uiName,elementName,value): |
| 33 | + if uiName in G_UIElementVariableArray: |
| 34 | + if elementName in G_UIElementVariableArray[uiName]: |
| 35 | + G_UIElementVariableArray[uiName][elementName].set(value) |
| 36 | +#Get Data of G_UIElementVariableArray:Param1:uiName, Param2:elementName |
| 37 | +def GetElementVariable(uiName,elementName): |
| 38 | + if uiName in G_UIElementVariableArray: |
| 39 | + if elementName in G_UIElementVariableArray[uiName]: |
| 40 | + return G_UIElementVariableArray[uiName][elementName].get() |
| 41 | +#Add Element 's BindingData :Param1:uiName, Param2:elementName,Param3:DataName,Param4:datatype, Param5: DataValue, Param6: isMapToText |
| 42 | +def AddUIData(uiName,elementName,dataName,datatype,datavalue,isMapToText): |
| 43 | + global G_ElementBindingDataArray |
| 44 | + if uiName not in G_ElementBindingDataArray: |
| 45 | + G_ElementBindingDataArray[uiName]={} |
| 46 | + if elementName not in G_ElementBindingDataArray[uiName]: |
| 47 | + G_ElementBindingDataArray[uiName][elementName]=[] |
| 48 | + G_ElementBindingDataArray[uiName][elementName].append([dataName,datatype,datavalue,isMapToText]) |
| 49 | +#Set Element 's BindingData :Param1:uiName, Param2:elementName,Param3:DataName,Param4:DataValue |
| 50 | +def SetUIData(uiName,elementName,dataName,datavalue): |
| 51 | + global G_UIElementArray |
| 52 | + global G_ElementBindingDataArray |
| 53 | + if uiName in G_ElementBindingDataArray: |
| 54 | + if elementName in G_ElementBindingDataArray[uiName]: |
| 55 | + for EBData in G_ElementBindingDataArray[uiName][elementName]: |
| 56 | + if EBData[0] == dataName: |
| 57 | + EBData[2] = datavalue |
| 58 | + if EBData[3] == 1: |
| 59 | + SetUIText(uiName,elementName,datavalue) |
| 60 | + return |
| 61 | +#Get Element 's BindingData :Param1:uiName, Param2:elementName,Param3:DataName |
| 62 | +def GetUIData(uiName,elementName,dataName): |
| 63 | + global G_ElementBindingDataArray |
| 64 | + if uiName in G_ElementBindingDataArray: |
| 65 | + if elementName in G_ElementBindingDataArray[uiName]: |
| 66 | + for EBData in G_ElementBindingDataArray[uiName][elementName]: |
| 67 | + if EBData[0] == dataName: |
| 68 | + if EBData[1]=='int': |
| 69 | + return int(EBData[2]) |
| 70 | + elif EBData[1]=='float': |
| 71 | + return float(EBData[2]) |
| 72 | + else: |
| 73 | + return EBData[2] |
| 74 | + return None |
| 75 | +#Set Element 's Attrib :Param1:uiName, Param2:elementName,Param3:AttribName,Param4:AttribValue |
| 76 | +def SetUIAttrib(uiName,elementName,AttribName,attribValue): |
| 77 | + global G_UIElementArray |
| 78 | + if uiName in G_UIElementArray: |
| 79 | + G_UIElementArray[uiName][elementName].configure(AttribName=attribValue) |
| 80 | +#Get Element's Attrib :Param1:uiName, Param2:elementName,Param3:attributeName |
| 81 | +def GetUIAttrib(uiName,elementName,AttribName): |
| 82 | + global G_UIElementArray |
| 83 | + if uiName in G_UIElementArray: |
| 84 | + return G_UIElementArray[uiName][elementName].cget(AttribName) |
| 85 | + return None |
| 86 | +#Get Element:Param1:uiName, Param2:elementName |
| 87 | +def GetUIEle(uiName,elementName): |
| 88 | + global G_UIElementArray |
| 89 | + if uiName in G_UIElementArray: |
| 90 | + return G_UIElementArray[uiName][elementName] |
| 91 | +#Set Element 's Text:Param1:uiName, Param2:elementName,Param3:textValue |
| 92 | +def SetUIText(uiName,elementName,textValue): |
| 93 | + global G_UIElementArray |
| 94 | + global G_UIElementVariableArray |
| 95 | + showtext = str("%s"%textValue) |
| 96 | + if uiName in G_UIElementVariableArray: |
| 97 | + if elementName in G_UIElementVariableArray[uiName]: |
| 98 | + G_UIElementVariableArray[uiName][elementName].set(showtext) |
| 99 | + return |
| 100 | + if uiName in G_UIElementArray: |
| 101 | + if elementName in G_UIElementArray[uiName]: |
| 102 | + if elementName.find('Text_') >= 0: |
| 103 | + G_UIElementArray[uiName][elementName].delete('0.0',tkinter.END) |
| 104 | + G_UIElementArray[uiName][elementName].insert(tkinter.END,showtext) |
| 105 | + else: |
| 106 | + G_UIElementArray[uiName][elementName].configure(text=showtext) |
| 107 | +#Get Element 's Text:Param1:uiName, Param2:elementName |
| 108 | +def GetUIText(uiName,elementName): |
| 109 | + global G_UIElementArray |
| 110 | + global G_UIElementVariableArray |
| 111 | + if uiName in G_UIElementVariableArray: |
| 112 | + if elementName in G_UIElementVariableArray[uiName]: |
| 113 | + return G_UIElementVariableArray[uiName][elementName].get() |
| 114 | + if uiName in G_UIElementArray: |
| 115 | + if elementName in G_UIElementArray[uiName]: |
| 116 | + if elementName.find('Text_') >= 0: |
| 117 | + return G_UIElementArray[uiName][elementName].get('0.0', tkinter.END) |
| 118 | + else: |
| 119 | + return G_UIElementArray[uiName][elementName].cget('text') |
| 120 | + return str("") |
| 121 | +#Init Element 's Data:Param1:uiName |
| 122 | +def InitElementData(uiName): |
| 123 | + global G_ElementBindingDataArray |
| 124 | + if uiName in G_ElementBindingDataArray: |
| 125 | + for elementName in G_ElementBindingDataArray[uiName].keys(): |
| 126 | + for EBData in G_ElementBindingDataArray[uiName][elementName]: |
| 127 | + if EBData[3] == 1: |
| 128 | + SetUIText(uiName,elementName,EBData[2]) |
| 129 | + SetUIText(uiName,elementName,EBData[2]) |
| 130 | +#Update Element 's Input Data Array:Param1:uiName |
| 131 | +def UpdateUIInputDataArray(uiName): |
| 132 | + global G_UIElementArray |
| 133 | + global G_UIInputDataArray |
| 134 | + global G_UIElementVariableArray |
| 135 | + G_UIInputDataArray.clear() |
| 136 | + if uiName in G_UIElementArray: |
| 137 | + for elementName in G_UIElementArray[uiName].keys(): |
| 138 | + G_UIInputDataArray[elementName] = [] |
| 139 | + Widget = G_UIElementArray[uiName][elementName] |
| 140 | + if elementName.find('Text_') >= 0: |
| 141 | + content = Widget.get('0.0', tkinter.END) |
| 142 | + G_UIInputDataArray[elementName].append(content) |
| 143 | + elif elementName.find('Entry_') >= 0: |
| 144 | + content = G_UIElementVariableArray[uiName][elementName].get() |
| 145 | + G_UIInputDataArray[elementName].append(content) |
| 146 | + if uiName in G_UIElementVariableArray: |
| 147 | + for elementName in G_UIElementVariableArray[uiName].keys(): |
| 148 | + if elementName.find('Group_') >= 0: |
| 149 | + ElementIntValue = G_UIElementVariableArray[uiName][elementName].get() |
| 150 | + G_UIInputDataArray[elementName] = [] |
| 151 | + G_UIInputDataArray[elementName].append(ElementIntValue) |
| 152 | + return G_UIInputDataArray |
| 153 | +#MessageBox |
| 154 | +def MessageBox(text): |
| 155 | + tkinter.messagebox.showwarning('info',text) |
| 156 | +#InputBox |
| 157 | +def InputBox(title,text): |
| 158 | + res = tkinter.simpledialog.askstring(title,'Input Box',initialvalue=text) |
| 159 | + return res |
| 160 | +#Return a file list from dir |
| 161 | +def WalkAllResFiles(parentPath,alldirs=True): |
| 162 | + ResultFilesArray = [] |
| 163 | + if os.path.exists(parentPath) == True: |
| 164 | + for fileName in os.listdir(parentPath): |
| 165 | + if '__pycache__' not in fileName: |
| 166 | + if '.git' not in fileName: |
| 167 | + newPath = parentPath +'\\'+ fileName |
| 168 | + if os.path.isdir(newPath): |
| 169 | + ResultFilesArray.append(newPath) |
| 170 | + if alldirs == True: |
| 171 | + ResultFilesArray.extend(WalkAllResFiles(newPath,alldirs)) |
| 172 | + else: |
| 173 | + ResultFilesArray.append(newPath) |
| 174 | + return ResultFilesArray |
| 175 | +#Add params to event functions |
| 176 | +def EventFunction_Adaptor(fun, **params): |
| 177 | + return lambda event, fun=fun, params=params: fun(event, **params) |
0 commit comments