Detect that all windows are closed

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Detect that all windows are closed

Calle Erlandsson
Hi all!
I was directed here by those on the irc-channel.
I'm making an editor, and want to open new windows when I open a new
file. This is very easy as I have a class that creates a window and load
the file and so on. The problem is that I got more than one window in
the same application, so when I press the close button on one of them
all of them terminates and the application dies.

This is when my destroy_event callback function look like this:

def onQuit(self, widget, event):
        gtk.main_quit()
        return 0

To solve it I changed it to:

def onQuit(self, widget, event):
        self.window.destroy()
        return 0

But this create a new problem: When I've closed all the windows the app
is still running because I haven't run the gtk.main_quit().
How do I solve this problem?

Please help
And excuse my bad english, it aint my first language ;)

--

Helmutt

_______________________________________________
pygtk mailing list   [hidden email]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Reply | Threaded
Open this post in threaded view
|

Re: Detect that all windows are closed

David M. Cook
On Sun, May 29, 2005 at 09:11:34PM +0200, Calle Erlandsson wrote:

> But this create a new problem: When I've closed all the windows the app
> is still running because I haven't run the gtk.main_quit().
> How do I solve this problem?

The function

gtk.window_list_toplevels()

may be helpful here.  Just check after destroying a window for how many are
left.

Dave Cook
_______________________________________________
pygtk mailing list   [hidden email]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Reply | Threaded
Open this post in threaded view
|

Re: Detect that all windows are closed

Milton Galo Patricio
In reply to this post by Calle Erlandsson
El 29/05/05, Milton inostroza<[hidden email]> escribió:

> tienes que aplicarle a la ventana main el callback delete_event con
> las siguientes lineas de codigo:
>
> def onQuit(self, widget, event):
>           gtk.main_quit()  #matará a todas las ventanas en pantalla y
> a la aplicacion misma
>           return
>
> y a las otras ventanas que no son el main, el siguiente codigo:
>
>  def onQuit(self, widget, event):
>          self.window.destroy()
>          return 0
>
> --
> Milton Inostroza Aguilera
> Secretario Academico Centro de Alumnos
> Encargado de Auspicios y Patrocinios - 6to. Encuentro Nacional de Linux
> Desarrollador de RemuneX (sistema de remuneraciones amparado bajo GPL)
>


--
Milton Inostroza Aguilera
Secretario Academico Centro de Alumnos
Encargado de Auspicios y Patrocinios - 6to. Encuentro Nacional de Linux
Desarrollador de RemuneX (sistema de remuneraciones amparado bajo GPL)
_______________________________________________
pygtk mailing list   [hidden email]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Reply | Threaded
Open this post in threaded view
|

Re: Detect that all windows are closed

Christian Robottom Reis
In reply to this post by David M. Cook
On Sun, May 29, 2005 at 12:27:11PM -0700, David M. Cook wrote:

> On Sun, May 29, 2005 at 09:11:34PM +0200, Calle Erlandsson wrote:
>
> > But this create a new problem: When I've closed all the windows the app
> > is still running because I haven't run the gtk.main_quit().
> > How do I solve this problem?
>
> The function
>
> gtk.window_list_toplevels()
>
> may be helpful here.  Just check after destroying a window for how many are
> left.

Kiwi2 also has a quit_is_last function that may come in handy:

    def quit_if_last(*args):
        windows = [toplevel
                   for toplevel in gtk.window_list_toplevels()
                       if toplevel.get_property('type') == gtk.WINDOW_TOPLEVEL]
        if len(windows) == 1:
            gtk.main_quit()

The *args is only useful to allow you to use it as a signal handler. I have no
clue why list_toplevels would return windows which did not have the type
WINDOW_TOPLEVEL but..

Take care,
--
Christian Robottom Reis | http://async.com.br/~kiko/ | [+55 16] 3376 0125
_______________________________________________
pygtk mailing list   [hidden email]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/