File: type-register.rb

package info (click to toggle)
ruby-gnome2 0.19.3-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 11,556 kB
  • ctags: 14,033
  • sloc: ansic: 83,294; ruby: 33,426; makefile: 3,721; cpp: 47; xml: 35
file content (104 lines) | stat: -rwxr-xr-x 2,682 bytes parent folder | download
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
#!/usr/bin/ruby
=begin
  type-register.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-register.rb,v 1.9 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"
  signal_new("hoge",                  # name
             GLib::Signal::RUN_FIRST, # flags
             nil,                     # accumulator (XXX: not supported yet)
             nil,                     # return type (void == nil)
	     Integer, Integer         # 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}"
    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