Following is a scratch of code in one of my program, it only uses ListStore.
I hope it will be some help.

class Local():

    COL_ICON = 0
    COL_FILENAME = 1
    COL_FILESIZE = 2
    COL_FILETYPE = 3
    COL_FILEMTIME = 4
    COL_ISDIR = 5
    COL_SIZE_IN_BYTES = 6
    COL_MTIME = 7

    def __init__(self):
        # a lot of lines omitted here

        # file list
        # init a ListStore which implements TreeModel
        self.__model = ListStore(gtk.gdk.Pixbuf,
                                 gobject.TYPE_STRING,
                                 gobject.TYPE_STRING,
                                 gobject.TYPE_STRING,
                                 gobject.TYPE_STRING,
                                 gobject.TYPE_INT,
                                 gobject.TYPE_ULONG,
                                 gobject.TYPE_ULONG)
        self.__model.set_sort_func(self.COL_ICON, self.filelist_sort_by_name)
        self.__model.set_sort_func(self.COL_FILENAME,
                                   self.filelist_sort_by_name)
        self.__model.set_sort_func(self.COL_FILESIZE,
                                   self.filelist_sort_by_size)
        self.__model.set_sort_func(self.COL_FILETYPE,
                                   self.filelist_sort_by_type)
        self.__model.set_sort_func(self.COL_FILEMTIME,
                                   self.filelist_sort_by_mtime)

        # create a TreeView widget
        self.__list = TreeView()
        # connect the model with it
        self.__list.set_model(self.__model)
        self.__list.set_headers_visible(TRUE)
        self.__list.get_selection().set_mode(gtk.SELECTION_MULTIPLE)

        # add columns to TreeView and they maybe connect with fields in model
        column = TreeViewColumn("Name")
        renderer = CellRendererPixbuf()
        column.pack_start(renderer, expand=FALSE)
        column.add_attribute(renderer, 'pixbuf', self.COL_ICON)
        renderer = CellRendererText()
        column.pack_start(renderer, expand=TRUE)
        column.add_attribute(renderer, 'text', self.COL_FILENAME)
        column.set_sort_column_id(self.COL_FILENAME)
        column.set_resizable(TRUE)
        self.__list.append_column(column)

        renderer = CellRendererText()
        renderer.set_property('xalign', 1)
        column = TreeViewColumn("Size", renderer, text=self.COL_FILESIZE)
        column.set_resizable(TRUE)
        column.set_sort_column_id(self.COL_FILESIZE)
        self.__list.append_column(column)

        renderer = CellRendererText()
        column = TreeViewColumn("Type", renderer, text=self.COL_FILETYPE)
        column.set_resizable(TRUE)
        column.set_sort_column_id(self.COL_FILETYPE)
        self.__list.append_column(column)

        renderer = CellRendererText()
        column = TreeViewColumn("Modified", renderer, text=self.COL_FILEMTIME)
        column.set_sort_column_id(self.COL_FILEMTIME)
        column.set_resizable(TRUE)
        self.__list.append_column(column)

        # a lot of lines omitted here

* Thomas Moore <[EMAIL PROTECTED]> [2004-03-04 16:05:13 +0800]:

> Hi:
> 
> I've found tutorial Chapter 14, "Tree View Widget" is empty.
> Is there any example to demonstrate how to use this widget?
> 
> 
> 
> _______________________________________________
> pygtk mailing list   [EMAIL PROTECTED]
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
_______________________________________________
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

Reply via email to