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 81 82 83 84 85 86 87 88 89 90 91 92
|
=begin header
sample.rb - a part of testgtk.c rewritten in Ruby/GTK2
Copyright (C) 2002,2003 Ruby-GNOME2 Project Team
$Id: sample.rb,v 1.7 2003/02/01 16:46:23 mutoh Exp $
=end
require 'gtk2'
class Object
alias :type :class if defined?(:class)
end
module Sample
def destroy
super
@destroyed = true
end
def destroyed?
@destroyed
end
end
module SampleClass
def invoke
@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
def initialize(title)
super()
set_title(title)
set_border_width(0)
@destroyed = false
signal_connect("destroy") do destroy end
end
end
class << SampleWindow
include SampleClass
end
class SampleDialog < Gtk::Dialog
include Sample
def initialize(title)
super()
set_title(title)
set_border_width(0)
@destroyed = false
signal_connect("destroy") do destroy end
end
end
class << SampleDialog
include SampleClass
end
def new_pixmap(filename, window, background)
pixmap, mask = Gdk::Pixmap::create_from_xpm(window, background, filename)
wpixmap = Gtk::Image.new(pixmap, mask)
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.set_active(true) if i == history
menu_item.show
end
omenu.set_menu(menu)
omenu.set_history(history)
omenu
end
|