Re: gtk_entry_set is a bit late.





On Mon, Jul 4, 2016 at 9:46 PM, Ian Chapman <ichapman videotron ca> wrote:
extern "C"
void on_Signal_activate()    {
/*    Phase 1  */
                gtk_entry_set_text(Status, "Starting phase 1"); //just show activity.
                std::cout << "Starting phase 1"  << std::endl;
/*    Phase 2  */
                gtk_entry_set_text(Status, "Starting phase 2"); //just show activity.
                std::cout << "Starting phase 2"  << std::endl;
/*    etc */
                gtk_entry_set_text(Status, "All phases complete"); //just show activity.
                std::cout << "All phases complete"  << std::endl;
                return; }
I guess the guys who understand gtk can see what happens.  The progress
messages come out on the terminal in order as expected from cout. The
only message in the status field (GtkEntry) is the last one at the termination
of servicing the signal.

You've got some fairly basic work to do on understanding how GUI programs work. Lets start with the basic "event loop" that surrounds any GUI application:

    while (not told to quit) {
          wait_for_next_event ();
          process_events ();
          redraw_stuff ();
    }

in the context of GTK, your signal handlers execute as part of process_events(). From the structure above, you can see that nothing will be redrawn on the screen until process_events() is done, and redraw_stuff() is called.

Thus, you only see the final message/text that was set at the end of your signal handler, drawn as part of redraw_stuff().

There are variety of ways to accomplish what you want, all of them more complicated than the normal simple programming you might be hoping for.

The simplest is to run the main event loop yourself (recursively) after each phase. This will get drawing done, and thus the text for that phase will show up. The problem is that you have no control over what your recursive main loop will do, and this can cause issues of both subtle and disastrous proportions (though it usually is OK).

The best method is use threads, and carry out the work of each phase there, queuing updates to the GUI via gtk_idle_add() or its contemporary equivalent.

Other people may make other suggestions.



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