From: MRAB on
eric dexter wrote:
> On Jun 27, 5:56 pm, MRAB <pyt...(a)mrabarnett.plus.com> wrote:
>> Eric_Dex...(a)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.
>
That is what the line was in your original post, and I explained the
change you needed to do.

> 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.
>
I've noticed that you're opening the menu file before the class
statement but reading from it in the __init__ method. It would be better
if you opened the file in the __init__ method itself. You can split a
line on whitespace with:

t = line.split()

It won't then matter how many spaces or tabs are between the fields.