GObject Subclassing in Ruby for custom CellRenderer in GtkTreeView
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开发者_JAVA技巧 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&file=faq13.045.htp
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)
精彩评论