[pygtk] Problems with gtk.ProgressBar

Marcus Vinicius Eiffle Duarte eiffleduarte at gmail.com
Thu May 8 21:40:26 WST 2008


Hi, folks!

I am developing a GUI to process a lot of data files in batch. So, the user
selects a folder, press a button and the application process all the files
in this folder. As the processing of each files takes a couple of seconds or
more, and there may be dozens of files, I want to display a nice progress
bar.

First problem: my first approach was to put a gtk.ProgressBar overlapping a
part of the gtk.StatusBar of the main window (please, bear in mind that I am
using Glade3 to develop my application). So, I would keep the ProgressBar
hidden, show it when necessary and hide it again. Using this approach (a
gtk.ProgressBar as a child of a gtk.StatusBar), the progress bar widget is
not found in the gladefile when I run get_wiget(). The relevant part ot the
__init__ function of my GUI is:

(...)
        self.pbProgresso =3D self.wTree.get_widget( "pbProgresso" )
        print self.pbProgresso
(...)

and I just get a "None" printed to the terminal. I checked my gladefile, and
the gtk.ProgressBar is there, and the name is right ("pbProgresso"). I am
copying below the relevant part of my gladefile:

(...)
          <widget class=3D"GtkStatusbar" id=3D"statusbar1">
            <property name=3D"visible">True</property>
            <property name=3D"events">GDK_POINTER_MOTION_MASK |
GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK |
GDK_BUTTON_RELEASE_MASK</property>
            <property name=3D"spacing">2</property>
            <child>
              <widget class=3D"GtkProgressBar" id=3D"pbProgresso">
                <property name=3D"no_show_all">True</property>
                <property name=3D"show_text">True</property>
                <property name=3D"text" translatable=3D"yes"></property>
              </widget>
              <packing>
                <property name=3D"expand">False</property>
                <property name=3D"fill">False</property>
                <property name=3D"pack_type">GTK_PACK_END</property>
                <property name=3D"position">1</property>
              </packing>
            </child>
          </widget>
          <packing>
            <property name=3D"expand">False</property>
            <property name=3D"position">3</property>
          </packing>
(...)

Then I substituted this approach by anothet one: I put a HBox in the bottom
of my window, and inside this HBox there is a gtk.StatusBar (first widget,
to the left) and a gtk.ProgressBar (second widget, to the right). The names
of the widgets are the same. When I run the code again, the ProgessBar is
loaded, and "<gtk.ProgressBar object at 0x85a66e4 (GtkProgressBar at
0x87f7ea0)>" is printed to the terminal.
So, my question is: what difference does it make the gtk.ProgressBar being a
child of gtk.HBox instead of a child of gtk.StatusBar?

Second problem: I am running a loop and want to increment the fraction of
the ProgressBar once per pass. However, when I run my code, I only see the
final ProgressBar, fully painted at the end of the loop. How can I force the
ProgressBar to be immediately updated, before the next pass of my loop? The
loop looks like

(...)
        indice =3D 0

        self.pbProgresso.show()

        for item in modelo:
            arquivoTXT =3D item[ 0 ]

            print arquivoTXT
            print ( ( indice/items ) ), indice, items

            self.pbProgresso.set_fraction( ( indice/items ) )

           <... does a lot of stuff ...>

            indice =3D indice + 1

(...)

Thanks in advance,
-- =

Marcus Vinicius Eiffle Duarte
eiffleduarte at gmail.com
Niter=F3i, RJ, Brasil
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.daa.com.au/pipermail/pygtk/attachments/20080508/2d77f244/at=
tachment.htm


More information about the pygtk mailing list