Can someone help me with this, if I run ftp, the page is downloaded and showed well, but the progress bar only shows 100% and doesn't progress at all..
def progress_timeout(pbobj):
# Calculate the value of the progress bar using the
# value range set in the adjustment object
new_val = pbobj.pbar.get_fraction() + 0.01
if new_val > 1.0:
new_val = 0.0
# Set the new value
pbobj.pbar.set_fraction(new_val)
# As this is a timeout function, return TRUE so that it
# continues to get called
return True
def ftp(self, w, date):
self.win = gtk.Window(gtk.WINDOW_POPUP)
self.win.set_resizable(True)
self.win.set_title("ProgressBar")
self.win.set_border_width(0)
fvbox = gtk.VBox(False, 5)
fvbox.set_border_width(10)
self.win.add(fvbox)
fvbox.show()
# Create a centering alignment object
align = gtk.Alignment(0.5, 0.5, 0, 0)
fvbox.pack_start(align, False, False, 5)
align.show()
# Create the ProgressBar
self.pbar = gtk.ProgressBar()
align.add(self.pbar)
self.pbar.show()
# Add a timer callback to update the value of the progress bar
self.timer = gobject.timeout_add (100, self.progress_timeout, self)
self.win.show()
self.progress_timeout
ftp = FTP(self.host)
percent = 0.1
self.pbar.set_text("10%")
self.pbar.set_fraction(percent)
self.progress_timeout
ftp.login(self.usr,self.pswd)
percent = 0.2
self.pbar.set_text("20%")
self.pbar.set_fraction(percent)
self.progress_timeout
ftp.cwd(self.dir)
percent = 0.3
self.pbar.set_text("30%")
self.pbar.set_fraction(percent)
self.progress_timeout
retr = 'RETR ' + self.ftpfile
ftpp = self.location + '/ftp.ded'
ftp.retrbinary(retr, open(ftpp, 'w').write)
percent = 0.4
self.pbar.set_text("40%")
self.pbar.set_fraction(percent)
self.progress_timeout
ftp.quit()
percent = 0.5
self.pbar.set_text("50%")
self.pbar.set_fraction(percent)
self.progress_timeout
txt = ''
f = open(ftpp, 'r')
percent = 0.6
self.pbar.set_text("60%")
self.pbar.set_fraction(percent)
self.progress_timeout
for line in f.readlines():
txt = txt + line
self.textbuffer.set_text(txt)
f.close()
percent = 0.9
self.pbar.set_text("90%")
self.pbar.set_fraction(percent)
self.progress_timeout
self.cmdbuf.set_text('Opened: ftp.ded')
percent = 1.0
self.pbar.set_text("100%")
self.pbar.set_fraction(percent)
self.progress_timeout
self.opnd = 'ftp.ded'