wxPython.button.disabled still catching clicks

Hello! (sorry for
my english)

I have a
problem with buttons in wxPython. When button is disabled

(by .Disable() or .Enable(False)) it is grayed out but still receive

clicks.

Eg. i have
button that disable itself, runs long action and enable

itself:

def
onClick(self, evt):

self.btn.Enable(False)

for i in range (1000):

    print i

self.btn.Enable(True)

when for loop
is running button is greyed out and when i click on it

nothing happens but when loop ends another one is started because

button “remebered” thad i click on it when was diabled. My only idea

is to reposition button outside frame instead of disabling it but this

solution is…not good.

ps. i solved this
by using subprocess but someone suggested to mail this group for
simplier solution. See also original topic at:
thanks for any help.

···

http://groups.google.com/group/comp.lang.python/browse_thread/thread/dd96cfb7519f1cb6#

mynth wrote:

Hello! (sorry for my english)

I have a problem with buttons in wxPython. When button is disabled
(by .Disable() or .Enable(False)) it is grayed out but still receive
clicks.

Eg. i have button that disable itself, runs long action and enable
itself:

def onClick(self, evt):
    self.btn.Enable(False)
    for i in range (1000):
        print i
    self.btn.Enable(True)

what about something like this:

    def onClick(self, evt):
       evt.GetEventObject().Disable()
       wx.CallAfter(self.doOnClick)

    def doOnClick(self):
       do your long running task
       self.btn.Enable(True)

You might also want to check the wiki.

http://wiki.wxpython.org/LongRunningTasks

Werner

what about something like this:

  def onClick(self, evt):
     evt.GetEventObject().Disable()
     wx.CallAfter(self.doOnClick)

  def doOnClick(self):
     do your long running task
     self.btn.Enable(True)

You might also want to check the wiki.

LongRunningTasks - wxPyWiki

Werner

It doeasnt work, but i looked at wikipage and found example with
using threads instead of processes and rewrite my script. It work well
now. Thanks for link.