views:

43

answers:

1

After following the official tutorial here: tutorial

I'm still having issues adding rows/creating a TreeIter object. Here's what my code looks like:

    builder = gtk.Builder()
    self.treeview = builder.get_object("treeview")
    self.treestore = gtk.TreeStore(str)

    self.treeview.set_model(self.treestore)

    self.id = gtk.TreeViewColumn('ID')
    self.type = gtk.TreeViewColumn("Type")
    self.readName = gtk.TreeViewColumn("Filename")
    self.set = gtk.TreeViewColumn("Set")

    self.treeview.append_column(self.id)
    self.treeview.append_column(self.readName)
    self.treeview.append_column(self.type)
    self.treeview.append_column(self.set)

    self.cell = gtk.CellRendererText()
    self.cell1 = gtk.CellRendererText()
    self.cell2 = gtk.CellRendererText()
    self.cell3 = gtk.CellRendererText()

    self.id.pack_start(self.cell, True)
    self.readName.pack_start(self.cell1, True)
    self.type.pack_start(self.cell2, True)
    self.set.pack_start(self.cell3, True)

    self.id.add_attribute(self.cell, 'text', 0)
    self.readName.add_attribute(self.cell1, 'text', 1)
    self.type.add_attribute(self.cell2, 'text', 2)
    self.set.add_attribute(self.cell3, 'text', 3)

    self.treeview.set_reorderable(True)

    self.readListVP.add(self.treeview)

    iter = self.treestore.get_iter(self.treestore.get_path(iter)) #here's where my problem lies
    self.treestore.set_value(None, 0, self.fileCountStr)
    self.treestore.set_value(None, 1, "paired-end")
    self.treestore.set_value(None, 2, self.file)
    self.treestore.set_value(None, 3, self.readSetStr)
A: 

Firstly, the problems with the question itself:

  1. You're not pasting the whole code. Any code pasted here should ideally work in a session of IDLE, but you're posting code from inside a class instance, and I can only guess which code you're pasting from the tutorial
  2. Say what the problem is
  3. Actually make it worth my while to answer so I can at least get some reputation for doing so. You're not showing up in three years doesn't help my attitude toward the question.

I spot a number of general problems with the code as well:

  1. You're creating too many CellRenderer's! Use just one for the whole table.
  2. Don't use the Builder()! It's just stupidly overcomplicating things.
  3. You're not adding columns the most efficent way.

Look into the question I've already asked.

new123456