[pygtk] Re: Interrupting a recursive mainloop from the outside...

Thomas Mills Hinkle tmhinkle at gmail.com
Thu Oct 19 08:43:34 WST 2006


On 10/18/06, Thomas Mills Hinkle <tmhinkle at gmail.com> wrote:
>
> I'm trying to interrupt an embedded mainloop from my application. The
> mainloop is run inside of a dialog (actually, it's a dialog that was then
> reframed in the main app (in a notebook tab) in order to create the feel =
of
> multiple "screens" rather than multiple windows). Anyway, when the window=
 on
> the main app is closed, my app quits (main_quit()), but the recursive
> mainloop isn't getting killed.
>
> I've tried making the dialog emit a RESPONSE_CANCEL signal and I've tried
> actually grabbing the cancel button in the dialog and making it emit a
> 'clicked' signal, but neither of these things work.
>
> Is there an easy way to interrupt the embedded mainloop or should do I
> have to abandon my loopy swallowed-dialog design?


I solved this myself but thought I'd write my solution below for posterity's
sake.

Thanks to the incredibly useful (but new to me) gtk.main_level() method, I
was able to figure out what my problem was. When my main window's "quit"
method was called, it was of course being called in the embedded mainloop,
so the remaining mainloop was actually my main mainloop, which explains why
all my efforts to kill the "dialog" were in vain.

The solution was to make my main app's quit_cb check whether it was being
called from an embedded mainloop.

e.g.

def quit_cb (self, *args):
    if main_level() > 1:
        gtk.main_quit()
        gobject.idle_add(self.quit_cb,100)
    else:
         # do normal stuff I do when the app quits...
         gtk.main_quit()

 Tom
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.daa.com.au/pipermail/pygtk/attachments/20061018/2963f35b/at=
tachment.htm


More information about the pygtk mailing list