From: ronny de w. <ron...@gm...> - 2005-02-26 23:00:40
|
Hello, I have a Test button which should perform an action, like sleeping 5 secs in the example below. During this action the button should not accept any event. So one should not be able to click the button again before the action related to the button is finished. During the action any Test button clicks should be ignored. How can i do that? Why doe the code below does not show this behavious ? def on_Test_mouseClick(self, event): print "*** button clicked" # why can i not disable the button with: self.components.Test.enabled = False time.sleep(5) self.components.Test.enabled = True Ronny De Winter |
From: Liam C. <cy...@gm...> - 2005-02-27 03:54:55
|
def on_Test_mouseClick(self, event): print "*** button clicked" # why can i not disable the button with: self.components.Test.enabled = False time.sleep(5) self.components.Test.enabled = True Because, you're not repainting in there - alternately, you could use wx.timer instead. (This is straight copy and paste from the Pythoncard manual.) from wxPython import wx def on_Test_mouseClick(self, event): self.myTimer = wx.wxTimer(self.components.Test, -1) # create a timer self.components.Test.enabled = False self.myTimer.Start(5000) # launch timer, to fire every 5000ms (5 seconds) def on_Test_timer(self, event): self.myTimer.Stop() self.components.Test.enabled = True That's guaranteed to do it for you but it's a bit of a hackish brute way of doing it. You have to force a repaint, iirc, and how do that is buried deep within wxPython. On Sun, 27 Feb 2005 00:00:31 +0100, ronny de winter <ron...@gm...> wrote: > Hello, > > I have a Test button which should perform an action, like sleeping > 5 secs in the example below. During this action the button should not accept > any event. So one should not be able to click the button again before the action > related to the button is finished. During the action any Test button > clicks should > be ignored. > > How can i do that? > Why doe the code below does not show this behavious ? > > def on_Test_mouseClick(self, event): > print "*** button clicked" > # why can i not disable the button with: > self.components.Test.enabled = False > time.sleep(5) > self.components.Test.enabled = True > > Ronny De Winter > > ------------------------------------------------------- > SF email is sponsored by - The IT Product Guide > Read honest & candid reviews on hundreds of IT Products from real users. > Discover which products truly live up to the hype. Start reading now. > http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click > _______________________________________________ > Pythoncard-users mailing list > Pyt...@li... > https://lists.sourceforge.net/lists/listinfo/pythoncard-users > -- 'There is only one basic human right, and that is to do as you damn well please. And with it comes the only basic human duty, to take the consequences. |
From: Ronny De W. <ron...@gm...> - 2005-02-27 13:22:59
|
Liam Clarke wrote: >def on_Test_mouseClick(self, event): > print "*** button clicked" > # why can i not disable the button with: > self.components.Test.enabled = False > > time.sleep(5) > self.components.Test.enabled = True > >Because, you're not repainting in there - alternately, you could use >wx.timer instead. >(This is straight copy and paste from the Pythoncard manual.) > >You have to force a repaint, iirc, and how do that is >buried deep within wxPython. > > > I tried with self.components.Test.Update() after disabling the button, without success. wx.timer is no alternative for me, in fact i don't sleep(5) but do some processing for about 5 secs (didnt post the whole processing since it is not relevant to the problem). Forcing the repaint is the message, but how ? How to best explore the deeply buried functionality of wxPython/wxWidgets ? Do you use specific tools for that ? published API documentation on the internet ? dynamic exploration via debuggers, ... ? A couple of days ago i posted a similar question about autosizing the columns of a multicolumnlist. Also there the answer is probably buried in wxPython/wxWidgets. What is the fastest way to find the answer to these kind of problems ? Best regards, Ronny De Winter |
From: Kevin A. <al...@se...> - 2005-02-27 16:56:29
|
On Feb 27, 2005, at 5:22 AM, Ronny De Winter wrote: > Liam Clarke wrote: > >> def on_Test_mouseClick(self, event): >> print "*** button clicked" >> # why can i not disable the button with: >> self.components.Test.enabled = False >> >> time.sleep(5) >> self.components.Test.enabled = True >> >> Because, you're not repainting in there - alternately, you could use >> wx.timer instead. >> (This is straight copy and paste from the Pythoncard manual.) >> >> You have to force a repaint, iirc, and how do that is >> buried deep within wxPython. >> >> > I tried with > self.components.Test.Update() > > after disabling the button, without success. Try Test.redraw(), the redraw method was made specifically for this purpose. The method is defined in widget.py def redraw(self): """Force an immediate redraw without waiting for an event handler to finish.""" self.Refresh() self.Update() > > wx.timer is no alternative for me, in fact i don't sleep(5) but do > some processing for about 5 secs (didnt post the whole processing > since it > is not relevant to the problem). Actually, I think using a timer is the right way to reenable the button. You may also need to consider calling SafeYield() depending on how responsive you want the UI to be during your processing. There are many samples that do long processing, so take a look at them for more examples. > Forcing the repaint is the message, but how ? > How to best explore the deeply buried functionality of > wxPython/wxWidgets ? > Do you use specific tools for that ? published API documentation > on the internet ? dynamic exploration via debuggers, ... ? > > A couple of days ago i posted a similar question about autosizing the > columns of a multicolumnlist. Also there the answer is probably buried > in wxPython/wxWidgets. > What is the fastest way to find the answer to these kind of problems ? > > Best regards, > Ronny De Winter > For wxPython questions, please post your quest on wxPython-users. http://www.wxpython.org/maillist.php ka |
From: Ronny De W. <ron...@gm...> - 2005-02-27 19:57:50
|
Kevin, Thanks, using redraw() and Yield() solved my problem: def on_Test_mouseClick(self, event): if self.loading: return self.loading = True print "*** button clicked" self.components.Test.enabled = False self.components.Test.redraw() time.sleep(5) wx.Yield() self.loading = False self.components.Test.enabled = True Cheers/ rdw Kevin Altis wrote: > Try Test.redraw(), the redraw method was made specifically for this > purpose. The method is defined in widget.py > > def redraw(self): > """Force an immediate redraw without waiting for an event > handler to finish.""" > self.Refresh() > self.Update() > > Actually, I think using a timer is the right way to reenable the > button. You may also need to consider calling SafeYield() depending on > how responsive you want the UI to be during your processing. There are > many samples that do long processing, so take a look at them for more > examples. |