November 7th, 2004, 05:12 PM
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?
November 8th, 2004, 09:10 AM
November 8th, 2004, 11:11 AM
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)
November 8th, 2004, 01:26 PM
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.
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.
menu5 = wxMenu()
for macro in self.MacroList:
ID = wxNewId()
def OnExecuteMacro(self, event):
eID = event.GetId()
MacroName = os.path.join(self.UserMacroDirectory,self.MacroDict[eID])