From: Masao Mutoh Date: 2003-12-16T23:49:07+09:00 Subject: Re: ruby-gtk2 extension Hi, On Tue, 16 Dec 2003 16:14:09 +0900 Gregory Millam wrote: > I'm writing a script based off a ruby-gtk2 extension, and I'd like to know if there exists a standard (or ruby-gtk2 built in) method of exiting the program only after the last window closes. There isn't one main window that controls the rest, but several windows open in parallel. > > If this was solely for my own application, I could keep a running track of open windows with an array, making each window delete itself from the array and calling Gtk.main_quit if there are no more objects in it. But this obviously isn't too portable across scripts; it is too unlikely that another coder who's going to use my script will use the same method. > > So ... is there any consistent method of forcing main_quit to be called only if there are no more guis displaying, timer events, etc? Hmm, I think your solution is not so bad. The sample below is an example to use Gtk::Window.toplevels, though I don't know this is better than yours. require 'gtk2' class SampleWindow < Gtk::Window def initialize super() button = Gtk::Button.new("open a new window") button.signal_connect("clicked") do SampleWindow.new.show_all end add(button) signal_connect("destroy") do availables = Gtk::Window.toplevels.select{|win| ! win.destroyed?} Gtk.main_quit if availables.size < 2 end end end Gtk.init SampleWindow.new.show_all Gtk.main -- .:% Masao Mutoh