Re: Stuck inside button click callback



Thanks for the prompt replies.

>      - Inside your run code while loop, insert the lines
>          while (gtk_events_pending())
>             gtk_main_itteration (FALSE);
>        at the end of every itteration.

That did it just fine. Everything shows ok now.
Thanks a lot.

Fabio

On 9/1/05, Tristan Van Berkom <tristan van berkom gmail com> wrote:
> Fabio Margarido wrote:
> > Hey there folks,
> >
> > I'm new to this list, and tried to search for similar questions, but
> > couldn't find anything (actually I was not quite sure how to search
> > for this :)), so sorry if this has been answered here before.
> > As a matter of fact, I'm a GTK newbie, and this is my first try. I'm
> > trying to create a GUI with some buttons, text entry fields and a
> > progress bar. When the user clicks the Run button, I want to make
> > everything in the window uneditable and unclickable while processing
> > is taking place, while I update the progress bar. The problem is that
> > when I click the run button, the callback attached is called, and it
> > seems the window only gets refreshed when the callback function
> > finishes running, i. e., the button remains clicked through all the
> > processing, and when it comes back, the progress bar is already at
> > 100%. I would like to know how to make the window immediately reflect
> > the changes I make to the other widgets while inside the button click
> > callback.
> 
>     The problem is that you are hijacking the main loop, there are a few
> ways you can get around this:
> 
>      - Split up your "Run" code whatever it is into small itterations and
>        run one itteration at a time in an idle or timeout handler
>        (see glib API reference "Mainloop and events bla bla section")
>        This is what I'd recommend.
> 
>      - Inside your run code while loop, insert the lines
>          while (gtk_events_pending())
>             gtk_main_itteration (FALSE);
>        at the end of every itteration.
> 
>      - If you are calling a third party library function that takes
>        a long time to finish and cannot split up into itterations,
>        you'll have to use threads, WAIT, this does *not* mean that
>        you need to use the gdk_threads_mutex described in the API/tutorial,
>        you only need to report your progress via a g_idle_add and
>        *dont make any gtk+ calls from your thread*.
> 
> The moral of the story is; no `while (1)'s in your code, and when you would
> usually do something like `sched_yield()', just `return' instead ;-)
> 
> Cheers,
>                                          -Tristan
> 
>



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