Search code examples
pygtk

Gtk.ListStore(*datatypes) string error


self.ip_liststore = Gtk.ListStore(*datatypes)

where

datatypes = [str,str,str]

I have also tried

datatypes = ['gchararray','gchararray']

And the interpreter replies with

Traceback (most recent call last):
  File "./gtktutorial.py", line 128, in <module>
    main()
File "./gtktutorial.py", line 119, in main
[str,str,str,str,str,str,str])
File "./gtktutorial.py", line 37, in __init__
self.ip_liststore = Gtk.ListStore(*datatypes)
File "/usr/lib/python2.7/dist-packages/gi/overrides/Gtk.py", line 943, in __init__
self.set_column_types(column_types)
TypeError: Item 0: Must be gobject.GType, not str

What happens after the list is unpacked? Are the contents converted to strings? Is there something I don't know about unpacking?


Solution

  • I believe there is just a little confusion, and I remember I had a wrong time searching for it.

    This is what I do :

    self.searchCols     = ["Object", "Index", "Date", "Program", "Person", "Mode"]
    sequence            = [str] * len(self.searchCols)
    self.resultStore    = gtk.ListStore( * sequence )
    self.resView        = gtk.TreeView(self.resultStore)
    self.resView.cell   = [None] * len(self.searchCols)
    rvcolumn            = [None] * len(self.searchCols)
    for colnum, col in enumerate ( self.searchCols ) :
        self.resView.cell[colnum] = gtk.CellRendererText()
        rvcolumn[colnum] = gtk.TreeViewColumn(col, self.resView.cell[colnum])
        rvcolumn[colnum].add_attribute(self.resView.cell[colnum], 'text', colnum)
        self.resView.append_column(rvcolumn[colnum])