python - updating wx.Gauge and keep current frame alive? -


i'm writing little tool downloads file website using python , wxpython. i've got working, thing's been bugging me want use progress bar show completion, , after urlretrieve, thing's moving progressbar, gui become unresponsive. know that's threading i'm new @ this. can give me hint?

the idea @ main frame search result site, , give result downloadlistingframe, generates buttons , statictext on fly. problem after click download button, progressbar updates file's being download, other whole app hangs. after reading else's code other example, thought put dodownload function in thread , executed it, acts same not using threading...

thanks in advanced.

class downloadlistingframe ( wx.frame ):

data = ''  def __init__( self, parent, result ):     wx.frame.__init__ ( self, parent, id = wx.id_any, title = u'result', pos = wx.defaultposition, size = wx.size( 500,300 ), style = wx.default_frame_style|wx.tab_traversal )     self.setsizehintssz( wx.defaultsize, wx.defaultsize )      self.statusbar = self.createstatusbar()     self.statusbar.setfieldscount(3)      self.progessbar = wx.gauge(self.statusbar, -1, style=wx.ga_horizontal|wx.ga_smooth)     rect = self.statusbar.getfieldrect(1)     self.progessbar.setposition((rect.x+2, rect.y+2 ))     self.progessbar.setsize((rect.width, rect.height-4))      buttonpos = 20     item in result:         label = wx.statictext( self, wx.id_any, item, wx.point( 120 ,buttonpos+2 ), wx.defaultsize, 0 )         button = wx.button(self, id=-1,label=u'download', pos=(20, buttonpos))         buttonpos = buttonpos + 30         self.bind(wx.evt_button, lambda x: self.downloader(item, result[item]), button)      self.centre( wx.both )   def progressupdate(self, blockcount, blocksize, totalsize):     progresssofar = int((float(blockcount) * float(blocksize) / float(totalsize)) * 100)     self.progessbar.setvalue(progresssofar)  def dodownloade(self, realaddress, saveasfilename):     urllib.urlretrieve(realaddress, saveasfilename, self.progressupdate)  def downloader(self, title, url):     saveaspath = wx.dirdialog(self, u"save to...")     if saveaspath.showmodal() == wx.id_ok:         realaddress = self.getrealaddress(url)         saveasfilename = os.path.join(saveaspath.getpath(), title + os.path.splitext(realaddress)[1])         thread = threading.thread(target=self.dodownloade(realaddress, saveasfilename))         thread.setdaemon(true)         thread.start()  def getrealaddress(self, url):     import httplib     siteurl = 'www.yyets.com'     httpconnection = httplib.httpconnection(siteurl)     httpconnection.request("get", url)     resp = httpconnection.getresponse()     realaddress = resp.getheaders()[6][1]     return realaddress  def __del__( self ):     pass 

when run command:

thread = threading.thread(target=self.dodownloade(realaddress, saveasfilename)) 

it first runs self.dodownloade(realaddress, saveasfilename) , passes return value of (which none) target.

instead want:

thread = threading.thread(target=self.dodownloade, args=(realaddress, saveasfilename)) 

note, here, i've passed in function self.dodownloade, , thread call agrs gave when call thread.start.

by way, can wx.timer. find better tool gauges since it's easier , can control how gauge updated , therefore how resources used gauge. main wxpython demo's gauge example uses wx.timer want starting point.


Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -