Hi,
I found the solution.
import urllib2
class Update(c4d.gui.GeDialog):
UPDATE_BTN = 1000
PROGRESS = 1001
PROGRESSBAR = 1002
state = ""
def CreateLayout(self) :
self.AddButton(self.UPDATE_BTN, flags = c4d.BFH_LEFT, inith = 13, name = "Update")
self.AddStaticText(self.PROGRESS, flags=c4d.BFH_SCALEFIT, initw=0, inith=0, name=self.state, borderstyle=0)
# How to taking the percentage value from the function chunk_report() and apply it to the following CUSTOMGUI_PROGRESSBAR
self.GroupBegin(id=0, flags=c4d.BFH_LEFT, cols=1, rows=0)
self.GroupBorderNoTitle(c4d.BORDER_THIN_IN)
self.AddCustomGui(self.PROGRESSBAR, c4d.CUSTOMGUI_PROGRESSBAR, "", c4d.BFH_SCALEFIT|c4d.BFV_SCALEFIT,200, 8)
self.GroupEnd()
def chunk_read(self, response, chunk_size=8192):
total_size = response.info().getheader('Content-Length').strip()
total_size = int(total_size)
bytes_so_far = 0
progressMsg = c4d.BaseContainer(c4d.BFM_SETSTATUSBAR)
progressMsg[c4d.BFM_STATUSBAR_PROGRESSON] = True
while 1:
chunk = response.read(chunk_size)
bytes_so_far += len(chunk)
if not chunk:
break
percent = float(bytes_so_far) / total_size
percent = round(percent*100, 2)
progressMsg[c4d.BFM_STATUSBAR_PROGRESS] = percent/100
self.SendMessage(self.PROGRESSBAR, progressMsg)
self.SetString(self.PROGRESS, percent)
def Command(self, id, msg):
if id == self.UPDATE_BTN :
filedata = urllib2.urlopen('https://www.domainname.com/file.zip')
self.chunk_read(filedata)