wxProgressDialog problems

Larry Bates larry.bates at websafe.com
Wed Feb 20 11:04:54 PST 2008


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.

Thanks in advance,
Larry

import wx
class Callback(object):
     def __init__(self, filename):
         if len(filename) > 90:
             self.filename=".."+filename[-90:]
         else:
             self.filename=filename

     def start(self, total):
         self.dlg=wx.ProgressDialog(title="WebSafe Upload",
                                    message=self.filename,
                                    maximum=total,
                                    style=wx.PD_APP_MODAL |
                                          wx.PD_AUTO_HIDE | \
                                          wx.PD_CAN_ABORT | \
                                          wx.PD_REMAINING_TIME)

         self.dlg.SetDimensions(-1, -1, width=500, height=-1,
                                sizeFlags=wx.SIZE_AUTO_HEIGHT)

         self.dlg.Show(True)
         self.total=total
         return True

     def __call__(self, total, position):
         percentstr=int(100.0*float(position)/float(total))
         msg="WebSafe Upload-%s%%" % percentstr
         self.dlg.SetLabel(msg)

         keepgoing, skip=self.dlg.Update(position)
         if not keepgoing:
             self.cancel()

         return True

     def complete(self):
         self.dlg.Destroy()
         return True

     def cancel(self):
         self.dlg.Destroy()
         return False

if __name__=="__main__":
     app=wx.PySimpleApp(0)
     wx.InitAllImageHandlers()
     a=Callback('test file upload')
     a.start(100)
     for i in xrange(100):
         a(100, i)
         wx.MilliSleep(200)





More information about the wxpython-users mailing list