Hi,
I’m trying to figure out if it’s possible to create a custom cell
renderer using a Ruby class. Digging through the source, I found the
type_register example, and that does allow me to provide default
handlers for the editing signals, but in order to do my custom renderer,
I need to override some of the methods in the base class.
According to examples I’ve found, you can do this sort of thing with the
Python bindings, but I don’t see how you can do it from the Ruby ones.
I saw the following thread on the mailing list back in 2003
(http://sourceforge.net/mailarchive/message.php?msg_id=20030912092726.GA2014%40intersect-uk.co.uk))
as well as (
http://sourceforge.net/mailarchive/message.php?msg_id=14e8de370603312339ne957094y5a45753e65e419e8%40mail.gmail.com).
I’ve also been looking through how it’s implemented in the C source, but
I haven’t used C GLib/GTK+ in years, and I’ve never done anything other
than read about extending Ruby in C apart for adding a missing method to
the Ruby goocanvas bindings (patch to follow at some stage).
Does anyone have any idea how item #1 in the 2003 email message can be
accomplished? I really don’t want to have to write my custom cell
renderer in C, then wrap it in Ruby just so I can render one set of
cells in one table which represents about .000001 of the functionality
of what I’m trying to write.
I’m sure that solving this problem would also be very useful to the
general community for cell renderers and view models (which are the main
reasons you’d need to do something more sophisticated than the signal
handling already there).
In the old threads, the problem of GLib interfaces vs. Ruby was also
raised. However, I’d think there should be an easy solution for this.
Something like the following seems to be a good trade-off:
class MyRenderer < Gtk::CellRenderer
type_register
implements_interface(Gtk::foo)
implements_interface(Gtk::bar)
…
end
or, you could do something like
class MyRenderer < Gtk::CellRenderer
register the type (type_register) and all implemented GLib
inteterfaces
register_glib_type([… optional interfaces …])
…
end
As I said, not having done much with either GLib/GTK+ in C or Ruby
extensions, I’m not sure how to actually make this happen, but it seems
like there ought to be a way to do it since you can already add custom
signals, properties and register the type. Even if it was via closures
(which, based on the names used, is how it seems to be implemented in
Python), it’d still be better than what exists today: if you don’t have
a signal you can override, you’re SOL.
Surely there’s some way to automatically add these redirects to the
existing bindings. Unfortunately, I’m not sure where to begin, and I’m
also under time pressure to get something working with my application.
I guess this means defining my custom GLib classes in C and then
wrapping them back to Ruby.
Thanks in advance for any ideas/assistance.
Cheers,
ast
P.S. Some other references (I’m sure you’ve seen most of these already):
GObject – 2.0
http://live.gnome.org/PyGTK/WhatsNew28
http://www.sicem.biz/personal/lgs/docs/gobject-python/gobject-tutorial.html
Andrew S. Townley [email protected]
http://atownley.org