Class to Widget

I’d like to learn how to convert a class to a widget. Is there someone
who can help me with this? The Ruby tutorial on this subject hasn’t
been written yet. I’d like to write that section using listbox.rb as an
example.

Your class should be a child of Gtk::TreeView, not Gtk::Widget. Updated
example attached.

Mathieu

Mathieu B. wrote:

Your class should be a child of Gtk::TreeView, not Gtk::Widget. Updated
example attached.

Mathieu
Thanks, Mathieu! That takes care of the reason it wouldn’t run. But,
does the fact that TreeView is a widget automatically make ListBox a
widget?

Alan L. wrote:

Mathieu B. wrote:

Thanks, Mathieu! That takes care of the reason it wouldn’t run. But,
does the fact that TreeView is a widget automatically make ListBox a
widget?

Yes it is because Gtk::TreeView is itself a Gtk::Widget (and otherwise
you wouldn’t be able to add your ListBox object to the window). Have a
look at the object hierarchy of a Gtk::TreeView:

http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gtk%3A%3ATreeView

[email protected]:~$ irb
irb(main):001:0> require “gtk2”
=> true
irb(main):002:0> Gtk::TreeView.ancestors
=> [Gtk::TreeView, Gtk::Container, Gtk::Widget, Atk::Implementor,
GLib::Interface, GLib::MetaInterface, Gtk::Object,
GLib::InitiallyUnowned, GLib::Object, GLib::Instantiatable, Object,
Kernel]
irb(main):003:0> tv = Gtk::TreeView.new
=> #<Gtk::TreeView:0xb67d37d0 ptr=0x8328120>
irb(main):004:0> tv.is_a? Gtk::Widget
=> true

HTH,
Mathieu

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs