Hi,
I found the following functions on a stackoverflow topic, and I want to apply it on c4d.gui.GeDialog.
I put more details in the code:
import urllib2
def chunk_report(bytes_so_far, chunk_size, total_size):
percent = float(bytes_so_far) / total_size
percent = round(percent*100, 2)
sys.stdout.write("Downloaded %d of %d bytes (%0.2f%%)\r" %
(bytes_so_far, total_size, percent))
if bytes_so_far >= total_size:
sys.stdout.write('\n')
def chunk_read(response, chunk_size=8192, report_hook=None):
total_size = response.info().getheader('Content-Length').strip()
total_size = int(total_size)
bytes_so_far = 0
while 1:
chunk = response.read(chunk_size)
bytes_so_far += len(chunk)
if not chunk:
break
if report_hook:
report_hook(bytes_so_far, chunk_size, total_size)
return bytes_so_far
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)
# I want take the percentage value from the function chunk_report() and apply it to the following CUSTOMGUI_PROGRESSBARCUSTOMGUI_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 Command(self, id, msg):
if id == self.UPDATE_BTN :
filedata = urllib2.urlopen('https://www.domainname.com/file.zip')
chunk_read(filedata, report_hook= chunk_report)
self.SetString(self.PROGRESS, "Or showing the write result of chunk_report() function here?") # <---
Thanks