Forum: Ruby-Gnome 2 Problem with new signals

4913bcb685792f601ae9813b4713abb9?d=identicon&s=25 Detlef Reichl (Guest)
on 2013-05-03 05:16
(Received via mailing list)
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:in `initialize'
  from box.rb:21:in `new'
  from box.rb:21:in `<main>'


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

Thanks, detlef
Ee6ffca720cc428d70247dcd7377dd48?d=identicon&s=25 Kouhei Sutou (Guest)
on 2013-05-03 13:56
(Received via mailing list)
Hi,

In <51832B9E.3000703@gmx.org>
  "[ruby-gnome2-devel-en] Problem with new signals" on Fri, 03 May 2013
05:14:38 +0200,
  Detlef Reichl <detlef.reichl@gmx.org> 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
4913bcb685792f601ae9813b4713abb9?d=identicon&s=25 Detlef Reichl (Guest)
on 2013-05-03 18:16
(Received via mailing list)
Am 03.05.2013 13:56, schrieb Kouhei Sutou:
> 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
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.