|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
wxPython:Automatic generation of menu
I am currently working on my first GUI, using wxPython, and would like to implement an idea but I'm not sure how to proceed.
In addition to the basic functions of the GUI I have a number of little scripts in a subdirectory that do some simple tasks. The idea is that users can add any new scripts to the directory and then run them from the GUI. To do this the GUI needs to automatically build a menu and then associate each entry with running the script in question. I can easily build the menu but I haven't a clue how to then run the scripts. Can anyone help or is this not a practical idea? |
|
#2
|
|||
|
|||
|
solved
It's OK. Problem solved.
|
|
#3
|
||||
|
||||
|
How was it solved?
(It might be solved for you but it's always nice to post how you got it done incase someone with the same question searches for the same thing) -MBirchmeier
__________________
My blog on programming related things. Hopefully I won't bog it down with details on my life Apparently even computers have freudian slips. 0x4279 7465 204D 6521 |
|
#4
|
|||
|
|||
|
Run a loop through the list of macros which generates a new ID for each macro, creates the menu entry, binds it to an event/function then adds the macro name to a dictionary with the ID as a key.
Code:
self.MacroDict= {}
menu5 = wxMenu()
for macro in self.MacroList:
ID = wxNewId()
menu5.Append(ID,macro)
self.Bind(wx.EVT_MENU, self.OnExecuteMacro,id=ID)
self.MacroDict[ID]= macro
menubar.Append(menu5,"UserMacros")
The function then extracts the ID of the event that triggered it and uses that to obtain the macro name from the dictionary and passes it to the command line. Code:
def OnExecuteMacro(self, event):
eID = event.GetId()
MacroName = os.path.join(self.UserMacroDirectory,self.MacroDict[eID])
os.system('python '+MacroName)
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > wxPython:Automatic generation of menu |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|