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
Welcome to
LinuxQuestions.org , a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free.
Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please
contact us . If you need to reset your password,
click here .
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
04-03-2005, 09:32 PM
#1
Member
Registered: Oct 2004
Distribution: Fedora 7
Posts: 232
Rep:
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
04-03-2005, 11:17 PM
#2
Member
Registered: Apr 2002
Location: Windsor, ON, CA
Distribution: Ubuntu
Posts: 740
Rep:
nvm
Last edited by 95se; 04-03-2005 at 11:18 PM .
04-03-2005, 11:31 PM
#3
Member
Registered: Oct 2004
Distribution: Fedora 7
Posts: 232
Original Poster
Rep:
I'm sorry... but what does nvm mean (nevermind?)
Last edited by bendeco13; 04-03-2005 at 11:33 PM .
04-05-2005, 02:54 PM
#4
Member
Registered: Oct 2004
Distribution: Fedora 7
Posts: 232
Original Poster
Rep:
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...
Thread Tools
Search this Thread
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
All times are GMT -5. The time now is 02:48 PM .
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know .
Latest Threads
LQ News