Andrew
Andrew

Reputation: 434

Wxpython's gauge not refreshing

I'd like to make an upload program with uploading gauge. I've got function which is callback function:

def myupdater(self, current, total):

    m = (Decimal(current)/Decimal(total))
    print "uploaded {0}/{1} so far".format(current, total)
    self.gauge_1.SetValue(m)
    print(m)
    print (self.gauge_1.GetValue)
    wx.Yield()
    print"----------------------"

And it shows (gauge only changes to 100% at the end):

http://pastebin.com/eM40e6mv

Full code: http://pastebin.com/uaThd5sD

Upvotes: 1

Views: 561

Answers (2)

falsetru
falsetru

Reputation: 369034

Gauge's range is int type. Passing value lower than 1 is treated as 0. Change gauge_1 .. line as follow:

self.gauge_1 = wx.Gauge(self.notebook_1_pane_1, -1, 100)

Change myupdater as follow:

def myupdater(self, current, total):
    m = 100 * current / total
    self.gauge_1.SetValue(m)
    wx.Yield()

Upvotes: 1

Dan Doe
Dan Doe

Reputation: 1156

It looks like you need a worker thread to update your GUI while the file is uploading. Try the threading module:

import threading

def myupdater(self):
    while self.still_uploading:
        #do stuff

threading.Thread(target=myupdater).start()
#upload stuff here

Upvotes: 0

Related Questions