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'

Recommended Answers

All 5 Replies

Is there really no one who knows how to use the pygtk progressbar?

I just need to know how the pygtk progressbar works, on the internet I can't find any good info about it ...

the progress bar only shows 100% and doesn't progress at all..

A progress bar is only useful if you're actually progressing through something. The steps that happen before you send the 100% to the progress bar are like going so fast that you can't see the "progress" of your function.

Also, to call a function you need to use parenthesis. None of your calls to progress_timeout are actually running. All you're doing is getting is the reference to that object on stdout. Reading through that function I'm not sure you should even be calling it at all though. But that's for you to discover.

Additionally, you should really use a function to do the progress updates since you have so much repeat code, it will cut down on the clutter and make it easier to read what this function does:

def set_progress(self, percent):
        ''' Sets the text, fraction and then calls progress_timeout
        @ Inputs
        - percent    Floating point representing the progress percent
        '''

        self.pbar.set_text('%i%%' % progress)
        self.pbar.set_fraction(progress)
        self.progress_timeout(self)
        return

Then each of your "updates" for the progress bar should be called as self.set_progress(0.1) . But the problem of executing code quickly before seeing progress still exists... You could add time.sleep(1) to the function so that after each update the program hangs for 1 second.

EDIT: I also have to re-iterate that I REALLY don't think you should be trying to call progress_timeout.

Oh, and also in response to:

I just need to know how the pygtk progressbar works, on the internet I can't find any good info about it ...

Not sure what you were using to search, but try this

EDIT: And one more thing.

I see that your function ftp is part of a class (has self as the first parameter) along with progress_timeout , but progress_timeout lacks the self parameter. This is incorrect usage. Either add the self parameter or move that function back out to the global level like my above linked example.

Thanks alot :) maybe I indeed shouldnt use the progressbar in this case.

Btw: OFCOURSE i used google, but the infog I found wasn't relevant on my case, or it was bad explained.
Otherwise I wouldn't ask it here!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.