Hi,
I'm doing my own CellRenderer (derived from GenericCellRenderer)
following the decorator design pattern, to use an existing renderer and
add some extra graphics to it, and modify the original renderer
behaviour in some cases. It's working pretty well with CellRendererText
and CellRendererToggle as the decorated item, but it fails with
CellRendererCombo because of something that seems a bug to me:
This is the object that the original renderer start_editing method gives:
Object: <gtk.ComboBoxEntry object (GtkComboBoxEntry) at 0xb7c3ccd4>
These are the interfaces supported by this object:
Interfaces: [<GType AtkImplementorIface (159548008)>, <GType
GtkCellLayout (159763248)>, <GType GtkCellEditable (159768856)>]
This is what happens when I return this object on my custom
on_start_editing method:
** (test.py:23800): WARNING **: return of start_editing() was not a
GtkCellEditable
I attach the python file where I'm testing these ideas. Is there
something wrong with my decorator or is this a bug of pyGTK 2.8?
The test file is not adding extra behaviour to the original renderer,
and it even doesn't show any column data. It's just a proof of concept.
If you change the decorator with the decorated in the column, the combo
selector works well.
Thanks in advance.
#!/usr/bin/env python
# example treeviewcolumn.py
import pygtk
pygtk.require('2.0')
import gtk
import gobject
class DecoratorRenderer(gtk.GenericCellRenderer):
def __init__(self, renderer1):
self.__gobject_init__()
self._renderer1 = renderer1
self.set_property("mode", renderer1.get_property("mode"))
def on_get_size(self, widget, cell_area=None):
print "GetSize"
return self._renderer1.get_size(widget, cell_area)
#return 0,0,100,50
def on_render(self, window, widget, background_area, cell_area, expose_area, flags):
print "Render"
return self._renderer1.render(window, widget, background_area, cell_area, expose_area, flags)
def on_activate(self, event, widget, path, background_area, cell_area, flags):
print "Activate"
return self._renderer1.activate(event, widget, path, background_area, cell_area, flags)
def on_start_editing(self, event, widget, path, background_area, cell_area, flags):
editable = self._renderer1.start_editing(event, widget, path, background_area, cell_area, flags)
print "Object: "+str(editable)
print "Interfaces: "+str(gobject.type_interfaces(editable))
return editable
class TreeViewColumnExample:
# close the window and quit
def delete_event(self, widget, event, data=None):
gtk.main_quit()
return False
def __init__(self):
# Create a new window
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.window.set_title("TreeViewColumn Example")
#self.window.set_size_request(200, 200)
self.window.connect("delete_event", self.delete_event)
# create a liststore with one string column to use as the model
self.liststore = gtk.ListStore(str, str, str, 'gboolean')
# create the TreeView using liststore
self.treeview = gtk.TreeView(self.liststore)
combomodel = gtk.ListStore(str)
combomodel.append(['Uno'])
combomodel.append(['Dos'])
combomodel.append(['Tres'])
decorated = gtk.CellRendererCombo()
decorated.set_property('model', combomodel)
decorated.set_property('text-column', 0)
decorated.set_property('has-entry', True)
decorated.set_property('editable', True)
decorator = DecoratorRenderer(decorated)
# create the TreeViewColumns to display the data
self.tvcolumn = gtk.TreeViewColumn('Pixbuf and Text', gtk.CellRendererText(), text=0)
self.tvcolumn1 = gtk.TreeViewColumn('Text Only', decorator)
self.liststore.append(['Open', gtk.STOCK_OPEN, 'Open a File', True])
self.liststore.append(['New', gtk.STOCK_NEW, 'New File', True])
self.liststore.append(['Print', gtk.STOCK_PRINT, 'Print File', False])
# add columns to treeview
self.treeview.append_column(self.tvcolumn)
self.treeview.append_column(self.tvcolumn1)
self.window.add(self.treeview)
self.window.show_all()
def main():
gtk.main()
if __name__ == "__main__":
tvcexample = TreeViewColumnExample()
main()
_______________________________________________
pygtk mailing list [email protected]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/