forked from ruby-gnome/ruby-gnome
-
Notifications
You must be signed in to change notification settings - Fork 0
/
type-register2.rb
104 lines (88 loc) · 2.64 KB
/
type-register2.rb
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
93
94
95
96
97
98
99
100
101
102
103
104
=begin
type-register2.rb - Sample for GLib::Object
You also need Ruby/GTK.
Copyright (C) 2004-2006 Ruby-GNOME2 Project Team
This program is licenced under the same licence as Ruby-GNOME2.
$Date: 2006/06/17 14:31:22 $
$Id: type-register2.rb,v 1.3 2006/06/17 14:31:22 mutoh Exp $
=end
require 'gtk2'
class MyButton < Gtk::Button
type_register
def initialize(label = nil)
# XXX:
# When type_register() is used.
# super is equivalent to GLib::Object#initialize.
super("label" => label)
@fuga = 0
end
# override existing default handler of "clicked" signal.
def signal_do_clicked(*args)
puts "MyButton#signal_do_clicked enter"
#p caller
super
puts "MyButton#signal_do_clicked leave"
end
# define new signal "hoge"
define_signal("hoge", # name
GLib::Signal::RUN_FIRST, # flags
nil, # accumulator (XXX: not supported yet)
GLib::Type["void"], # return type
GLib::Type["gint"], GLib::Type["gint"] # parameter types
)
# define default handler of "hoge" signal
def signal_do_hoge(a, b)
puts "MyButton#signal_do_hoge enter"
#p caller
puts "MyButton#signal_do_hoge leave"
end
# define new property "fuga"
install_property(GLib::Param::Int.new("fuga", # name
"Fuga", # nick
"fuga hoge", # blurb
0, # min
10000, # max
0, # default
GLib::Param::READABLE |
GLib::Param::WRITABLE))
# implementation of the property "fuga"
def fuga
puts "MyButton#fuga is called"
@fuga
end
def fuga=(arg)
puts "MyButton#fuga= is called"
@fuga = arg
notify("fuga")
end
end
class MyButton2 < MyButton
type_register("MyButton2")
# override default handler of "clicked" signal
def signal_do_clicked(*args)
puts "MyButton2#signal_do_clicked enter"
super(*args)
puts "MyButton2#signal_do_clicked leave"
end
# override default handler of "hoge" signal
def signal_do_hoge(a, b)
puts "MyButton2#signal_do_hoge enter"
puts "a, b = #{a}, #{b}"
#p caller
super
puts "MyButton2#signal_do_hoge leave"
end
end
b = MyButton2.new("Hello")
p b
p b.label
p b.gtype
b.clicked
b.signal_emit("hoge", 1, 2)
b.signal_connect("notify"){|obj, pspec|
puts "#{b} notify #{pspec}"
}
p b.get_property("fuga")
b.set_property("fuga", 1)
p b.get_property("fuga")
p MyButton2.ancestors