#!/usr/bin/python

from gi.repository import Gtk, GObject

class Window(Gtk.Window):

    def __init__(self):
        Gtk.Window.__init__(self)
        self.connect("destroy", Gtk.main_quit)
        self.set_title("Progress!")
        self.grid = Gtk.Grid()
        self.grid.set_border_width(30)
        self.grid.set_column_spacing(20)
        self.add(self.grid)
        button = Gtk.Button("Add Progress Bar")
        button.connect("clicked", self.addProgressBar)
        self.grid.attach(button, 0, 0, 1, 1)
        self.show_all()

        self.timer = 0
        self.timeout = 1500
        self.updateCount = 0

    def addProgressBar(self, button):
        grid = Gtk.Grid()
        grid.set_column_spacing(20)
        label = Gtk.Label("Making SLOW progress:")
        grid.attach(label, 0, 0, 1, 1)

        self.progressBar = Gtk.ProgressBar()
        self.progressBar.set_fraction(0.0)
        grid.attach(self.progressBar, 1, 0, 1, 1)
        grid.show_all()

        self.grid.attach(grid, 1, 0, 1, 1)
        self.timer = GObject.timeout_add(self.timeout, self.updateProgress)

    def updateProgress(self):
        self.updateCount += 1
        print "Update of widget #%s" % (self.updateCount)

        newValue = self.progressBar.get_fraction() + 0.05
        if newValue > 1.0:
            return False

        self.progressBar.set_fraction(newValue)

        return True

if __name__ == '__main__':
    window = Window()
    Gtk.main()
