Hello,

I've been vexed by a problem with gtk.progressBar not updating.

Program background:
Written in two section. Section is a 'class'. The __init() uses fork()
and execv() to start a program, and then attach fileptr to the outputs. 
Additional routines are provide to read the fileptrs, provide the data,
watch for and set the exit conditions.

This routine works independently of any superclassing programs.

The other section deals with gtk/glade functionality. There two status
tools. A gtk.progressBar and gtk.statusBar. When a user presss a button,
the first section is called.
The first sections's init is called (causing the fork/execv)
Two interrupts (gtk.input_add_full() and gtk.timeout_add()) are set to
watch the forked programs output and update a progressbar.

I noted on an early mailing that I should include a:

        while gtk.pending_events():
                gtk.mainiteration()
        
I wrapped this as:
        def pendingEvents( self ):
                while gtk.pending_events():
                        gtk.mainiteration()

Then passed the pendingEvents() to the inputhandler (gtk.input_add_full(
filno, 'ACTION',callback, callback params ). Up to this point a
gtk.statusBar was not updating. Now it was.

Progressbar updates should have been handled through the timeout
callback. THe callback called the section 1 function:

        def getProgress( self ):
                return (self.current, self.total ) 

to retrieve it's data. Then compute a fraction then update the
progressbar with:
        pgbar.set_fraction( float( current ) / total ). 

(also tried: 
        frac =  float( current ) / total 
        pgbar.set_fraction( frac )
no difference)

Yet the progressbar does not visually update. The pending_events (I
verified it was being called) was not picking up the changed fraction. 

Then I got it to work. Using an old FORTRAN programming technique, I
retrieved the fraction value with pgbar.get_fraction(), the printed it.
Suddenly the progress bar is updating.

Anyone want to take a crack at explaining this behavior? Seem to me that
the call to set_fraction() was optimized away (or at least out of the
pending_events queue), then forced back into the code by the
get_fraction().  


version info:
        Redhat 9
        python-2.2.2-26
        pygtk2-devel-1.99.14-4
        pygtk2-1.99.14-4
        pygtk2-libglade-1.99.14-4
        libglade-devel-0.17-11
        libglade2-devel-2.0.1-3
        libglade2-2.0.1-3
        glade2-1.1.3-3
        libglade-0.17-11

p.s. the FORTRAN compiler used by DEC/COMPAQ/HP had a nasty 'feature'
that would initialize variables to zero, if not initialized. Also it
would optimize away a variable not used in a subroutine, even when you
mistakenly thought you'd declared it global. When you printed the
variable, it would be compiled into the code, then your program would
suddenly work correctly or at least differently. 

I preferred the default SGI FORTRAN compiler, if you didn't initialize,
the variable would have any data left in it. This often as not would
trigger a NaN (not a number) exception when you tried to use the
variable as a number, telling you most explicitly that you hadn't
initialized a variable.


-- 
Steven Howe <[EMAIL PROTECTED]>

_______________________________________________
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

Reply via email to