On Tuesday 30 September 2003 01:05 pm, Theodore A. Roth wrote: > Hi, > > I have built up an app using glade-2 and it loads and runs fine using > gtk.glade. One of my widgets is a TreeView using a ListStore and I'm > having a bit of trouble figuring out how to make all the columns > # the model and the BOOLEAN in column 1. > col = gtk.TreeViewColumn (hdrs[i], renderers[i], > text=i+2, editable=1) .... > # This is obviously wrong. > col.pack_start (renderers[i], expand=gtk.TRUE)
You are inserting the renderer and several properties into the column using
the column constructor. Later you are using pack_start to reinsert the same
renderer into the column. The pack_start method is to be used to insert
multiple renderers into the same column, for instance, if you want to insert
an icon and some text into the same cell.
The following works as a replacment for what you are trying to do
col = gtk.TreeViewColumn (hdrs[i])
col.pack_start (r, expand=gtk.FALSE)
col.add_attribute(r, 'text', i)
renderers[i].set_property ('editable', 1)
The attached example is a works.
import gtk, gtk.glade, gobject
class ListView:
def __init__ (self, view, model, hdrs, renderers, sel_cb):
self.view = view
view.set_model (model)
view.set_headers_visible (gtk.TRUE)
for i in xrange (len (hdrs)):
# Set text to i+2 to skip over the PYOBJECT in column 0 of
# the model and the BOOLEAN in column 1.
col = gtk.TreeViewColumn (hdrs[i],)# renderers[i],text=i)
#text=i+2, editable=1)
col.set_resizable (gtk.TRUE)
col.set_alignment (0.50)
view.append_column (col)
# This is obviously wrong.
r = renderers[i]
col.pack_start (r, expand=gtk.FALSE)
col.add_attribute(r, 'text', i)
renderers[i].set_property ('editable', 1)
renderers[i].set_property ('xalign', 0.50)
# renderers[i].set_property ('font-desc', font_fixed)
view.show()
sel = view.get_selection ()
sel.set_mode ('single')
sel.connect ('changed', sel_cb)
types = [ gobject.TYPE_STRING ] * 10
renderers = [ gtk.CellRendererText () ] * 10
hdrs = [ 'Address', 'Name',
'Bit 7', 'Bit 6', 'Bit 5', 'Bit 4',
'Bit 3', 'Bit 2', 'Bit 1', 'Bit 0' ]
class App:
def __init__(self):
self.gui = gtk.glade.XML("project8.glade")
dic = {"on_treeview1_select_cursor_row":
self.on_treeview1_select_cursor_row
}
self.gui.signal_autoconnect(dic)
def setup_treeview (self, widget_name, types, hdrs, renderers, sel_cb):
self.model = model = gtk.ListStore (*types)
view2 = self.gui.get_widget (widget_name)
view = ListView (view2, model, hdrs, renderers, sel_cb)
return view
def insert_row (self, data):
"""Also adds the python object, 'data' to the store in the first
column. Set the value of the boolean to TRUE so we can edit the
cells later.
"""
iter = self.model.append()
self.model.set(iter,0,'a',1,'b',2,'c')
## args = [0, data, 1, gtk.TRUE]
## for i in range (len (data)):
## args.extend ([i+2, data[i]])
## print "args", args
## self.model.set (iter, *args)
def on_treeview1_select_cursor_row(self, *obj):
print "selected", obj
a = App()
print a.setup_treeview('treeview1',types,hdrs,renderers,
a.on_treeview1_select_cursor_row)
a.insert_row(['a','b','c'])
a.insert_row(['a','b','c'])
gtk.main()
project8.glade
Description: application/glade
_______________________________________________ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
