Austin Henry wrote:

Ok, this could be a weird one (or maybe not, I haven't been reading this
list long enough to know what's weird around here ;)

I am trying to implement a custom TreeCellRenderer which displays text,
and when edited brings up a combo box subclass that I've written in
Python.  This combo box does auto-completion from a set of values pulled
from a database & stored in a gtk.ListStore.

Now, I have the cell renderer working happily (editing supplied by a
gtk.Entry), and the DBCombo working happily too.  The problem seems to
be convincing the TreeView widget that it would like to use the DBCombo
as the editing widget.  Buried deep in the Gtk code
(gtktreeviewcolumn.c, line 2606) is the following bit of code
        g_return_val_if_fail (GTK_IS_CELL_EDITABLE (*editable_widget), FALSE);
which is on the code path that is followed when you ask to edit a
TreeView's Cell.

That code basically means that I can't just implement the interface in
python, and have the calls be made with no one the wiser. I tried to declare my DBCombo like this:
class DBCombo(gtk.Combo, gtk.CellEditable)
but python complains:
Traceback (most recent call last):
File "widgets.py", line 11, in ?
class DBCombo(gtk.Combo, gtk.CellEditable):
TypeError: multiple bases have instance lay-out conflict


So, I went and read the C code for GtkEntry to see how "officially"
adding the interface CellEditable to a GType is done.  Turns out that
the call is:
        g_type_add_interface_static(...)
There's unfortunately no corresponding function in PyGtk.

I'm at a loss.  How should I go about adding the CellEditable interface
to my little widget? I suppose I could write some C code that does the
correct magic, then wrap that C code myself, but...  It's not like I
don't already have C code to compile in my project (BTW, I have a very
primitive GtkHTML 3 wrapper if anyone should want it).

Anyway, I'm rambling now. I'll stop. I've attached the code in question
to this message. Astute readers of the list archives may recognise the
origination of the MyCellRenderer code that I copied (and mangled) from
http://www.mail-archive.com/[EMAIL PROTECTED]/msg05242.html


GObject interfaces are not very language binding friendly on the implementation side as things are at the moment (at least, I haven't worked out a better way of handling things). There is no way of introspecting information about the interface, so it is impossible to do a generic interface wrapper (interfaces are essentially additional structures tacked onto the class that usually contain C function pointers).

In the past, the support for interfaces has involved creating special purpose classes that implement the interface as a skeleton that calls methods of a related Python object. This doesn't give you the ability to add interfaces to random widgets, which is really what you want for things like GtkCellEditable :(

Maybe I'll review things a bit after a pygtk-2.0 release (it is probably possible to do better than we are right now).

James.

--
Email: [EMAIL PROTECTED]
WWW:   http://www.daa.com.au/~james/



_______________________________________________
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

Reply via email to