views:

71

answers:

1

I am trying to implement a customized CellRenderer in Ruby/GTK, and I've already found this suggestion:

GObject subclassing in Ruby

However, when I try the following:

class CellRendererCustom < Gtk::CellRendererText
  type_register #register within gobject system?
  def initialize
    super
  end
  def get_size(widget, cell_area)
    puts "Never called :-("
    return 0,0,100,100
  end
  def signal_do_get_size(widget, cell_area)
    puts "Never called :-("
    return 0,0,100,100
  end
  def signal_do_on_get_size(widget, cell_area)
    puts "Never called :-("
    return 0,0,100,100
  end
  def on_get_size(widget, cell_area)
    puts "Never called :-("
    return 0,0,100,100
  end
end

Those signals are never called. I guess there this has something to do with how Ruby is connected to the GObject API, but honestly, I have no idea how this all works.

What I want to do is subclass CellRendererText, and overwrite a method, in this example get_size, which gets called by TreeView. However, I think because CellRendererText is a C Module, and not a ruby class, I cannot overwrite its methods without actually making the system aware of that.

Also I am CellRenderers need to be assigned to a TreeViewColumn, which then calls get_size and other methods.

As far as I know, a similar problem existed in PyGtk, where it was somehow circumvented by adding a "GenericCellRenderer" class:

http://faq.pygtk.org/index.py?req=show&amp;file=faq13.045.htp

A: 

I suspect get_size delegates the width and height to object properties, and the parent widget uses the properties directly instead of hitting your get_size method. get_size isn't a signal, which is why signal_do_get_size won't get called either.

Try:

set_property("width", 100)
Tobu
I added some clarification to the above question, I actually want to overwrite the get_size method in my subclass.
genericus666
I got what you tried to do, and my point stands.I think get_signal isn't called, neither your implementation nor the implementation in any parent class.I therefore recommend setting the width and height properties.
Tobu