LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 04-03-2005, 09:32 PM   #1
bendeco13
Member
 
Registered: Oct 2004
Distribution: Fedora 7
Posts: 232

Rep: Reputation: 30
PROBLEM: pygtk progress bar


I'm really new to python and pygtk...
Everytime this 'StartRemove' class is called, it's supposed to popup a progress bar with some other labels. The problem is: the progress bar, labels, etc., don't show up until the progress gets to 100% or progbar.set_fraction(1). I don't have a clue as to whats causing this...

Here's what I have.

Code:
class StartRemove:

    def callback(self, widget, data):
        if (data == "stop"):
            print data

    def __init__(self):
        global filelist, message, numaffected

        if (recrusive == False):
            findcommand = "-maxdepth 1 "
        else:
            findcommand = ""

        filelist = os.popen('find "' + directory + '" ' + findcommand + '-name *.mp3 | sort').read()
        filelist = filelist.splitlines()
        numfiles = len(filelist)
        if (numfiles == 0):
            message = "No .mp3 Files Were Found In:\n" + directory
            ErrorBox()
        else:
            self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
            self.window.set_title("IH8id3 - Progress")
            self.window.connect("destroy", self.callback, "stop")
            self.window.set_border_width(5)

            main_vbox = gtk.VBox(gtk.FALSE, 0)
            vbox = gtk.VBox(gtk.FALSE, 0)
            vbox2 = gtk.VBox(gtk.FALSE, 0)

            self.window.add(main_vbox)

            align = gtk.Alignment(0.5, 0.5, 0, 0)
            vbox.pack_start(align, gtk.FALSE, gtk.FALSE, 5)

            progbar = gtk.ProgressBar(adjustment=None)
            progbar.set_fraction(0)
            progbar.set_orientation(gtk.PROGRESS_LEFT_TO_RIGHT)
            align.add(progbar)

            separator = gtk.HSeparator()
            vbox.pack_start(separator, gtk.FALSE, gtk.FALSE, 5)

            label1 = gtk.Label("Starting...")
            vbox.pack_start(label1, gtk.FALSE, gtk.FALSE, 5)

            main_vbox.pack_start(vbox, gtk.FALSE, gtk.FALSE, 0)

            label2 = gtk.Label("Files Scanned:")
            label2.set_justify(gtk.JUSTIFY_LEFT)
            vbox2.pack_start(label2, gtk.FALSE, gtk.FALSE, 0)
            label3 = gtk.Label("Files Affected:")
            label3.set_justify(gtk.JUSTIFY_LEFT)
            vbox2.pack_start(label3, gtk.FALSE, gtk.FALSE, 0)
            label4 = gtk.Label("Version 1:")
            label4.set_justify(gtk.JUSTIFY_LEFT)
            vbox2.pack_start(label4, gtk.FALSE, gtk.FALSE, 0)
            label5 = gtk.Label("Version 2:")
            label5.set_justify(gtk.JUSTIFY_LEFT)
            vbox2.pack_start(label5, gtk.FALSE, gtk.FALSE, 0)

            frame1 = gtk.Frame("Stats:")
            frame1.add(vbox2)
            main_vbox.pack_start(frame1, gtk.FALSE, gtk.FALSE, 0)

            button1 = gtk.Button("Stop")
            button1.connect("clicked", self.callback, "stopbttn")
            button1.set_border_width(5)
            main_vbox.pack_start(button1, gtk.FALSE, gtk.FALSE, 0)

            self.window.show_all()
	    self.window.activate_focus()

	    #self.progbar.configure(0, 0, numfiles)
            numaffected = 0
            count = 1
	    
	    import time

            for i in filelist:
		time.sleep(.2)
                percent = float(count) / numfiles
		print percent
                progbar.set_text(str(int(percent * 100)) + "%")
                label1.set_text(i)
                label2.set_text("Files Scanned: " + str(count))
                label3.set_text("Files Affected: " + str(numaffected))
                label4.set_text("Version 1: ")
                label5.set_text("Version 2: ")
                progbar.set_fraction(percent)
                count = count + 1

            label1.set_text("Finished")

            button1.set_label("Ok")
            button1.connect("clicked", lambda w: self.window.hide())
Pleeeeeeaaaaaseee Help.
Thanks in Advance,
Bendeco
 
Old 04-03-2005, 11:17 PM   #2
95se
Member
 
Registered: Apr 2002
Location: Windsor, ON, CA
Distribution: Ubuntu
Posts: 740

Rep: Reputation: 32
nvm

Last edited by 95se; 04-03-2005 at 11:18 PM.
 
Old 04-03-2005, 11:31 PM   #3
bendeco13
Member
 
Registered: Oct 2004
Distribution: Fedora 7
Posts: 232

Original Poster
Rep: Reputation: 30
Quote:
nvm
I'm sorry... but what does nvm mean (nevermind?)

Last edited by bendeco13; 04-03-2005 at 11:33 PM.
 
Old 04-05-2005, 02:54 PM   #4
bendeco13
Member
 
Registered: Oct 2004
Distribution: Fedora 7
Posts: 232

Original Poster
Rep: Reputation: 30
Ok I fixed it.
Obviously, the window needs to be redraw everytime the progress gets updated.
Here what I added...

Code:
while gtk.events_pending():
    gtk.mainiteration()
so it looks like this...

Code:
            numaffected = 0
            count = 1
	    
	    import time

            for i in filelist:

		while gtk.events_pending():
		    gtk.mainiteration()
                
		time.sleep(.2)
                percent = float(count) / numfiles
		print percent
                progbar.set_text(str(int(percent * 100)) + "%")
Hope this helps anyone else who has this problem...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
cp with progress bar? Rotwang Linux - General 5 04-27-2005 07:49 PM
PROGRESS BAR with shell script murugesan Linux - Software 5 12-13-2004 09:03 AM
Progress bar image craigs1987 Fedora 0 05-27-2004 02:31 PM
cp: progress bar chii-chan Linux - General 2 10-30-2003 06:30 PM
Progress Bar zael Programming 3 10-01-2003 12:20 PM


All times are GMT -5. The time now is 02:48 PM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration