1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
=begin header
sample.rb - a part of testgtk.c rewritten in Ruby/GTK2
Copyright (C) 2002-2005 Ruby-GNOME2 Project Team
$Id: sample.rb,v 1.9 2005/07/21 17:47:19 mutoh Exp $
=end
require 'gtk2'
module Sample
def destroy
super
@destroyed = true
end
def destroyed?
@destroyed
end
end
module SampleClass
def invoke
@singleton = nil unless defined? @singleton
@singleton = new if @singleton.nil? or @singleton.destroyed?
unless @singleton.visible?
@singleton.show_all
else
@singleton.destroy
end
end
end
class SampleWindow < Gtk::Window
include Sample
extend SampleClass
def initialize(title)
super(title)
@destroyed = false
signal_connect("destroy") do destroy end
end
end
class SampleDialog < Gtk::Dialog
include Sample
extend SampleClass
def initialize(title)
super(title)
@destroyed = false
signal_connect("destroy") do destroy end
end
end
OptionMenuItem = Struct.new("OptionMenuItem", :name, :block)
def build_option_menu(items, history)
omenu = Gtk::OptionMenu.new
menu = Gtk::Menu.new
group = nil
items.size.times do |i|
menu_item = Gtk::RadioMenuItem.new(group, items[i].name)
menu_item.signal_connect("activate") do |widget|
items[i].block.call(widget)
end
group = menu_item.group
menu.append(menu_item)
menu_item.active = true if i == history
menu_item.show
end
omenu.menu = menu
omenu.history = history
omenu
end
|