problems getting os.system and wxmenu to read options from a file and then execute
eric dexter
irc.dexter at gmail.com
Sun Jun 27 21:43:48 EDT 2010
On Jun 27, 5:56 pm, MRAB <pyt... at mrabarnett.plus.com> wrote:
> Eric_Dex... at msn.com wrote:
> > I managed to get the program running and the menu options are
> > appearing on the list but the programs are not running. I suspect it
> > is my onexecutemethod
>
> [snip]
>
> > #add execute files from the text file list
> > idtool = 400
> > for e in menuoptions:
> > wx.EVT_MENU(self, idtool, self.OnExecute(idtool, e))
>
> This calls the OnExecute method and then passes its result to
> wx.EVT_MENU. If, for example, OnExecute is returning None, then that's
> what is being passed into wx.EVT_MENU.
>
> What you should actually be doing is passing a function which can be
> called when the menu item is clicked, something like this:
>
> wx.EVT_MENU(self, idtool, lambda idtool=idtool, e=e:
> self.OnExecute(idtool, e))
>
> > idtool += 1
> > ##print e
>
> [snip]
> > def OnExecute(self,tool,e):
> > print tool
> > os.system(e)
> > #print tool
> > # Get rid of the dialog to keep things tidy
>
> [snip]
wx.EVT_MENU(self, idtool, self.OnExecute(idtool, e))
I changed it to this and it seems to be calling self.OnExecute befour
the editor comes up and then after the editor is up it doesn't respond
to anything. I got rid off all the spaces but one in the text file (I
supose I need to use the strip method in real like though).. I was
able to get an infinite loop by calling the editor as one of the
options and then it keeps calling itself. It may be another problem
or perhaps I didn't grasp the answer.
More information about the Python-list
mailing list