Re: Why doesn't my label show up in the window



On Sat, 25 Aug 2012 16:49:14 +0800
Ardhan Madras wrote:

You call sleep() in mainloop causes it block, you can use
g_timeout_*() functions to create event in mainloop in timely manner.
Below I modify your code to implement g_timeout_*() functions.

So the sleep() causes the g_main_context_iteration function to stop before it
completes its operation?

The example I posted isn't actually what I'm doing, but it is (was?) the
simplest way to demonstrate it.  The real objective is to bring up a subwindow
with status reports in the form of a label that updates at intervals as a
function runs without returning to gtk_main() until completion.  So I create the
subwindow, create a label and add it to the subwindow, do task x, update the
label, do task y, destroy the subwindow and return to gtk_main().

What I have discovered is that the subwindow appears as expected prior to
starting task x, but the label is missing (the subwindow is blank) until it
updates at the start of task y.

1. Create subwindow, create label "Talking to John", gtk_show_all (subwindow).
subwindow shows up with no text.

2. Talk to John.

3. Update label "Now talking to Mary".  Text shows up in the subwindow as
expected, "Now talking to Mary"

4. Talk to Mary.

5. Destroy subwindow.

I never get told that we're talking John, even though John does get talked to.

http://developer.gnome.org/gtk-faq/stable/x601.html

That webpage appears to say that nothing gtk-related will normally be executed
until the program gets back to gtk_main(), and I can get around this by
putting a "while (g_main_context_iteration (NULL, FALSE));" into my code at the
point that I want to run the pending gtk-related stuff (like updating my label).

But it doesn't work so my understanding of what's going on here is either
incomplete or wrong.

I guess my question comes down to how can I process everything from within
a function that would normally get processed by returning to gtk_main(), without
having to actually return to gtk_main()?  "Go and update everything, then come
right back here and continue this job".


-- 
MELVILLE THEATRE ~ Real D 3D Digital Cinema ~ www.melvilletheatre.com
www.creekfm.com - FIFTY THOUSAND WATTS of POW WOW POWER!



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