Re: Updating a statusbar widget



Tony Denault <denault@hawaii.edu> writes:

> On Sun, 23 Jul 2000, Vlad Harchev wrote:
> 
> > 
> > while (gtk_events_pending())
> >         gtk_main_iteration();
> > 
> 
> 
> I am doing this, see my print_status function to write text
> status to a label:
> 
> int print_status( char *fmt, ... )
> {
>    char buf[256];
>    va_list argptr;
> 
>    va_start( argptr, fmt);
>    vsprintf( buf, fmt, argptr);
>    va_end( argptr );
> 
>    /* update single line feedback widget on main screen */
>    gtk_label_set_text( GTK_LABEL(Feedback_search_w), buf );
> 
>    /* force update of widgets */
>    while ( gtk_events_pending() ) 
>       gtk_main_iteration();
>    // while ( gtk_main_iteration());   <- this one from the FAQ don't  work!

As was said, this should be g_main_iteration (FALSE); if the
FAQ as gtk_main_iteration, please send mail to gale@gtk.org.

>    return ERR_NONE;
> }
> 
> Some problems:
> 
> 1. The suggested code from the FAQ doesn't work:
>      "while (gtk_main_iteration(FALSE));"
>    I am using GTK 1.2.7. Is the FAQ out of date with the GTK release?
> 
> 2. Worse, this solution does more than just drawing updates. It also
>    processing other events on the queue. If I call print_status(), any
>    user input to widget and their call backs are called, expired timers
>    call backs get called, etc This make the cure, worse that the problem.
 
> Is there a better method to handle this situation?

You really need to handle events, otherwise, for example, your
window won't be redrawn.

So, this probably means you should probably plan on having a way
of dealing with the fact that you don't want the user to interact
with the application

 - turn off your timers
 - put a modal dialog (this way the user will know that something
   is going on and won't click furiously at the app, only to
   be surprised when it suddently starts handling the queued
   events a minute later...) 

If you don't want to handle events, then you can call
gtk_widget_draw(some_parent_of_label_with_a_window), and it
will refresh. But other parts of your app won't if they
get obscured and neeed to be redrawn.

> I think this is the best gtk 1.2.x can do. Will 1.4.x work better?

It will work pretty much the same in this regard. I don't have
much of any idea how it could work better.

[There is a call in GTK+-2.0: 

 void gdk_window_process_all_updates (void); 

which handles all queued redraws. But even if you call this function
regularly, since incoming expose events are never removed from the
queue your app still won't work correctly if you don't process
events. ]

Regards,
                                        Owen




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]