[wxPython-users] wxProgressDialog problems
Robin Dunn
robin at alldunn.com
Wed Feb 20 14:31:16 PST 2008
Larry Bates wrote:
> I am trying to implement a file upload dialog (see code below). It
> almost works, except that I can't get the cancel button to respond as
> expect. I'm certain it is something really small.
Events (like the cancel button event) won't be delivered if program flow
is not in the main loop. In real life that probably won't be a problem
for most apps, as long as you don't block some event handler in a long
running task. In your sample it can be taken care of by using a timer
to update the progress dialog. See
http://wiki.wxpython.org/LongRunningTasks for ideas on how to approach
other situations.
class MyApp(wx.App):
def OnInit(self):
self.callback = Callback("test file upload")
self.callback.start(100)
self.timer = wx.Timer(self)
self.Bind(wx.EVT_TIMER, self.OnTimer, self.timer)
self.timer.Start(200)
self.count = 0
return True
def OnTimer(self, evt):
if self.count < 100:
self.callback(100, self.count)
self.count += 1
else:
self.callback.complete()
app = MyApp(0)
app.MainLoop()
--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!
More information about the wxpython-users
mailing list