[pygtk] progressbar for file managing
Fabian Braennstroem
f.braennstroem at gmx.de
Tue Apr 17 03:55:08 WST 2007
Hi,
I would like to add a progressbar for file managing such as copying,
deleting, moving. Unfortunately I don't understand the handling of
the progressbar...
As a first try I would like to use the 'pulse' function for the
progressbar, i.e. as long as I copying files I would like to 'pulse'
the bar. Below you can see a small example; I get the progressbar
moving, but not during the copying process :-(
#!/usr/bin/env python
import pygtk
pygtk.require('2.0')
import gtk
import shutil
from time import sleep
file1="/home/fab/.bashrc"
class Buttons:
def callback(self, widget, data=None):
i=0
n=100
self.progress.pulse()
self.progress.set_text("Calculating....")
self.progress.grab_add()
shutil.copy(file1,"progressbar_copy")
while i < n:
sleep(0.015)
# self.progress.set_fraction(i/(n - 1.0))
self.progress.pulse()
i += 1
while gtk.events_pending():
gtk.main_iteration_do(False)
self.progress.set_fraction(0.0)
self.progress.set_text("")
self.progress.grab_remove()
def __init__(self):
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.window.connect("destroy", lambda wid: gtk.main_quit())
self.window.connect("delete_event", lambda
a1,a2:gtk.main_quit())
self.window.set_border_width(10)
box = gtk.HBox()
self.progress= gtk.ProgressBar()
button = gtk.Button("Button")
button.connect("clicked", self.callback, "cool button")
button.show()
self.progress.show()
box.add(self.progress)
box.add(button)
box.show()
self.window.add(box)
self.window.show()
def main():
gtk.main()
return 0
if __name__ == "__main__":
Buttons()
main()
A next step would be, to display the remaing bytes and percentage of
the copied file until completion (like the midnight commander is
doing). How can I achive this? The progressbar has to know the size
and the actual copied/moved/deleted number of bytes... Does anyone
has an idea? Would be nice ...
I am doing the file managing with 'shutil' or 'os' modules.
Greetings!
Fabian
More information about the pygtk
mailing list