开发者

PyGTK - Adding Rows to gtk.TreeStore

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)


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜