MCPcopy Create free account
hub / github.com/ActiveState/code / Build

Function Build

recipes/Python/577038_Simple_Buttonbar_Utility/recipe-577038.py:181–252  ·  view source on GitHub ↗

Build menu from menu file The menu file may contain commands to set the current directory and to set specified environment variables. This is done while the file is being read. They are not dependent on the selected button. The last command encountered will be active. s

(pMenuName, pFileName, pLabelList)

Source from the content-addressed store, hash-verified

179 lCmd = subprocess.Popen(pCommand, shell=True)
180
181def Build(pMenuName, pFileName, pLabelList):
182 '''
183 Build menu from menu file
184 The menu file may contain commands to set the current directory and to
185 set specified environment variables. This is done while the file is
186 being read. They are not dependent on the selected button. The last
187 command encountered will be active.
188
189 set environment variable name to value
190 ;#set`name=value
191 set current directory to path
192 ;#cd`path
193 '''
194#
195 lFile = open(pMenuName,'r')
196 lFileText = lFile.readlines()
197 lFile.close
198
199 label = Tkinter.Label(frame, text=pFileName)
200 label.pack(side=TOP, fill=X)
201 lKeep = False
202
203 for lText in lFileText:
204 if len(lText) > 1:
205 if lText[0] != "[":
206 if lText[0] == "-":
207 pass
208 #label= Tkinter.Label(frame,text=lText[:-1])
209 #label.pack(side=TOP, fill=X)
210 elif lText.startswith(";#"): # <---- Special commands start with ;#
211 lPos = lText.find("`") # <---- Fields are separated by `
212 if lPos > 0:
213 lCh = lText[2]
214 if lCh == 's': # set environment variable
215 lEqPos = lText.find("=")
216 if lEqPos > lPos:
217 lKey = lText[lPos+1:lEqPos].strip()
218 lValue = lText[lEqPos+1:].strip()
219 os.environ[lKey] = lValue
220 elif lCh == 'c': # set working directory
221 if lPos > 0 and lPos < len(lText):
222 os.chdir(lText[lPos+1:].strip())
223 else: # ignore
224 pass
225 elif lText[0] == ";":
226 pass
227 elif lKeep == False:
228 pass
229 else:
230 lPos = lText.find(",")
231 if lPos > 0:
232 lPrompt = lText[:lPos]
233 lCommand = lText[lPos+1:]
234
235 lCommand = Expand(lCommand, pFileName)
236
237 mCmds[lPrompt] = lCommand
238 button = Tkinter.Button(frame,text=lPrompt)

Callers 1

recipe-577038.pyFile · 0.70

Calls 10

startswithMethod · 0.80
chdirMethod · 0.80
ExpandFunction · 0.70
openFunction · 0.50
readlinesMethod · 0.45
packMethod · 0.45
findMethod · 0.45
stripMethod · 0.45
bindMethod · 0.45
lowerMethod · 0.45

Tested by

no test coverage detected