开发者

PyGTK TreeView showing blank rows from ListStore

I'm trying to show several rows from database in a TreeView but all I am getting are some dummy rows as you can see in the image below.

PyGTK TreeView showing blank rows from ListStore

class SettingsDialog(gtk.Dialog):
    def __init__(self):
        gtk.Dialog.__init__(self, "Server Settings", self, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT)

        # Instantiate ServerManager
        self.server_manager = ServerManager()

        # Create TreeStore for Server list
        self.liststore = gtk.ListStore(str, str)
        self.treeview = gtk.TreeView(self.liststore)

        # Create TreeViewColumns to display data
        cell = gtk.CellRendererText()
        col = gtk.TreeViewColumn("Name")
        col.pack_start(cell, True)
        self.treeview.append_column(col)

        cell = gtk.CellRendererText()
        col = gtk.TreeViewColumn("URL")
        col.pack_start(cell, True)
        self.treeview.append_column(col)

        self.vbox.pack_start(self.treeview)

        self.resize(500,350)
        self.set_position(gtk.WIN_POS_CENTER)
        self.show_all()

        self.load_server_list()


    def load_server_list(self):
        self.liststore.clear()
 开发者_如何学C       servers = self.server_manager.list()
        for name, url in servers.iteritems():
                self.liststore.append([name, url])
        self.show_all()

Data returned from self.server_manager.list() is valid an added to the list store perfectly. There seems to be something wrong with the CellRenderers but I wasn't able to find the error.


You have to set an attribute mapping on the column. For example, the cellrenderer's text attribute value will be displayed in the treeview cell. It is taken from the values on the data model (self.liststore). The column number on the model where the value is taken from is specified in the attribute mapping.

## Take value for *text* attribute of the cell renderer from the model's 3rd column
col = gtk.TreeViewColumn(title, cellrenderer, text=2)
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜