tags:

views:

26

answers:

2

What's the point of doing the Gtk::Main::iteration() on the last two lines of the answer to this question? I'm using pygtk, so the equivalent question would be, why do gtk.main_iteration_do()? Isn't the main loop that's running already taking care of this?

A: 

These functions exist to let you create your own loop, and have an iteration of GTK's loop run somewhere in it.

You may want to take care of other stuff while the loop runs, in the same thread/process as the loop. Many libraries with main loops provide either a way to schedule tasks in their main loop, or a function to run a single iteration of the loop for you embed somewhere else.

Santiago Lezica
+1  A: 

When I wrote that answer, I was assuming that the items would be added in a long loop - for example in a callback somewhere. Unless you're explicitly doing the work in a separate thread, then the main loop is in fact not running during that code. The code there tells the window to scroll to the bottom, but the scrolling only actually happens when the main loop regains control.

"While events pending, do main interation" in whatever language is an often-used way to run the main loop until all waiting GUI updates have been processed.

ptomato
oh I think I see... so if I'm adding say 2500 items to a treeview, and after adding each item i run the main loop like in the answer, then it won't freeze up for the X seconds it takes to add them all?
Claudiu
@Claudiu, right.
ptomato
@ptomato: neat that answers a question i didn't know i had. and this one as well
Claudiu