Problem with new signals

Hi,

if I add a signal to a Gtk::Box super() doesn’t work like expected. The
following code works:

require ‘gtk3’

class MBox < Gtk::Box
def initialize
super(:vertical)
pack_start Gtk::Label.new(‘bla1’)
pack_start Gtk::Label.new(‘bla2’)
end
end

win = Gtk::Window.new
box = MBox.new
win.add box
win.show_all
Gtk.main

but if I add a new signal:

require ‘gtk3’

class MBox < Gtk::Box
self.type_register
self.signal_new(:value_changed, GLib::Signal::RUN_FIRST,
nil, GLib::Type[‘void’], Float, Float)
def signal_do_value_changed foo, bla
end

 def initialize
     super(:vertical)
     pack_start Gtk::Label.new('bla1')
     pack_start Gtk::Label.new('bla2')
 end

end

win = Gtk::Window.new
box = MBox.new
win.add box
win.show_all
Gtk.main

I get this error:

box.rb:13:in initialize': wrong argument type Symbol (expected Hash) (TypeError) from box.rb:13:ininitialize’
from box.rb:21:in new' from box.rb:21:in

Line 13 is the line with the super call. What I’m doing wrong?

Thanks, detlef

Hi,

In [email protected]
“[ruby-gnome2-devel-en] Problem with new signals” on Fri, 03 May 2013
05:14:38 +0200,
Detlef R. [email protected] wrote:

if I add a signal to a Gtk::Box super() doesn’t work like
expected.

You can’t use super class’s initialize when you use
type_register. Because super class’s initialize uses super
class’s GType not your new GType.

Type_registered class’s initialize is similar to raw
g_object_new(). You need to set object properties by Hash
like:

def initialize
super(:orientation => :vertical)
end

Thanks,

kou

Am 03.05.2013 13:56, schrieb Kouhei S.:

Type_registered class’s initialize is similar to raw
g_object_new(). You need to set object properties by Hash
like:

def initialize
super(:orientation => :vertical)
end

OK, that works.

Thanks allot! detlef