Thu, 1 Dec 2011 16:43:03 +0200
Neil Muller a écrit:

> Remember that gtk is not threaded, so, unless the main loop gets a
> chance to run, events aren't going to be processed. This delay
> construct explicitly forces the main loop to process events, but a
> call to subprocess.call will just block waiting for the command to
> finish, and the main loop isn't going to run, so nothing clears the
> event queue while waiting for the command to finish, and you'll get
> the behavior you describe. Adding a "while gtk.events_pending():
> gtk.main_iteration()" before reconnecting the handlers is a simple fix
> for this, although completely blocking gtk's event loop does introduce
> issues with redrawing and so forth.
> 
> I'd personally avoid the subprocess.call, and use subprocess.Popen
> instead, polling the command in an gobject idle task or by using a
> gobject.timer signal, and then reconnect handlers and cleanup when the
> command finishes - this allows the gtk main loop to run as normal.
> 
> Hope that helps.

Indeed, it does.

I used the gtk.events_pending and the gtk.main.iteration as I found them,
whithout taking the time to understand what they did.

Your explanation about the threading is clear. Now I understand what is
happening much clearer than I expected.

Regarding Popen, as a new user, I stopped at that sentence of the tutorial :
"The recommended approach to invoking subprocesses is to use the following
convenience functions for all use cases they can handle. For more advanced
use cases, the underlying Popen interface can be used directly."

Yet, as far as I understand, call() does things the blocking way (no way back
in main task, mouse and keyboard events are treated when back to gtk.main()),
while Popen authorizes a more subtle approach, for instance, letting the
external program do its job while still allowing the user to interfere with
the GUI and other stuff to happen. And I guess the only way to achieve this
is to go through all the gobject stuff you are pointing.

I think I understand the approach you are suggesting me, though I'm having
difficulties implementing it. I guess now that I have been playing with what
I knew, it's time to dive back into the tutorials to get some more background
knowledge before I go any further with this exercise.

Thank you very much for taking the time to read my question and "unblock" me.

-- 
Jérôme
_______________________________________________
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/

Reply via email to