On Sun, 2010-11-28 at 00:48 -0600, alex goretoy wrote:
> This is essential what I am looking to do, but it doesn't work. I
> appreciate your response.
import gtk
ts = gtk.ListStore(object)
ts.append((["a","b"],))
ts.append((["c","d"],))
tv = gtk.TreeView(ts)
r = gtk.CellRendererText()
c = gtk.TreeViewColumn("0", r)
c.set_cell_data_func(r,
lambda col, cell, model, iter_: cell.set_property("text",
model.get_value(iter_, 0)[0])
)
tv.append_column(c)
r = gtk.CellRendererText()
c = gtk.TreeViewColumn("1", r)
c.set_cell_data_func(r,
lambda col, cell, model, iter_: cell.set_property("text",
model.get_value(iter_, 0)[1])
)
tv.append_column(c)
w = gtk.Window()
w.add(tv)
w.show_all()
gtk.main()
The lambdas are a bit ugly, I was in a hurry.
John
>
>
> >>> gtk.TreeStore( str * 5 )
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> TypeError: unsupported operand type(s) for *: 'type' and 'int'
> >>> gtk.TreeStore( [str] * 5 )
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> TypeError: could not get typecode from object
> >>> a = [str] * 5
> >>> a
> [<type 'str'>, <type 'str'>, <type 'str'>, <type 'str'>, <type 'str'>]
> >>> gtk.TreeStore( a )
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> TypeError: could not get typecode from object
>
>
> Thank you,
> -Alex Goretoy
> http://launchpad.net/~a1g
>
>
> On Sat, Nov 27, 2010 at 10:39 PM, John Stowers
> <[email protected]> wrote:
> On Sat, 2010-11-27 at 20:40 -0600, alex goretoy wrote:
> > Currently I am having to do this in my application to create
> dynamic
> > treestore; is the a better way to do this?
>
>
> You could do
>
> treestore = gtk.TreeStore(object)
>
> where obj contains the list of strings. However you would then
> have to
> write your own display functions [1] for the (presumed)
> treeview
> columns.
>
> John
>
> [1] see gtk.TreeViewColumn.set_cell_data_func
>
> >
> >
> > def get_treestore(n):
> > if n == 0:
> > treestore = gtk.TreeStore(str);
> > elif n == 1:
> > treestore = gtk.TreeStore(str);
> > elif n == 2:
> > treestore = gtk.TreeStore(str, str);
> > elif n == 3:
> > treestore = gtk.TreeStore(str, str, str);
> > elif n == 4:
> > treestore = gtk.TreeStore(str, str, str,
> str);
> > else:
> > treestore = gtk.TreeStore(str);
> >
> >
> > return treestore
> >
> >
> >
> >
> > Thank you in advance,
> > -Alex Goretoy
> >
>
> > _______________________________________________
> > pygtk mailing list [email protected]
> > http://www.daa.com.au/mailman/listinfo/pygtk
> > Read the PyGTK FAQ: http://faq.pygtk.org/
>
>
>
>
_______________________________________________
pygtk mailing list [email protected]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/