wxProgressDialog problems

Larry Bates larry.bates at websafe.com
Wed Feb 20 15:55:40 PST 2008


Robin Dunn wrote:
> 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,

My problem is that the thing that calls this Callback is WAY down deep in
other code.  I want to register the Callback instance with that and it
gets called as the file is streamed (once per (65K block) over a WEBDAV 
connection.  I don't see how to adapt what you wrote or the examples on
the wiki like you sent.  When the cancel button is pushed it needs to
return False so I can cancel the streaming upload and work my way back
through all the layers back to my main program.

Thoughts?

Thanks in advance,
Larry





More information about the wxpython-users mailing list