ruby-gtk2 extension

G

Gregory Millam

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?
 
M

Masao Mutoh

Hi,

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top