On Thu, 2003-07-10 at 00:27, Martin Klaffenboeck wrote:
> How do I have to use the gtk.TreeModel?
> 
> There is no example in the tutorial, and the reference manual doesn't 
> tell me much.  I know how to use the TreeModel in c.
I can give you an example of how to create a list, if that helps.  See
attached file.  I find that my code generally connects to the
"row_activated" signal of the gtk.TreeView and the "changed" signal of
the gtk.TreeSelection.

Hope this helps, 
   Michael
-- 
Michael JasonSmith      http://www.cosc.canterbury.ac.nz/~mpj17/
import pygtk ; pygtk.require('2.0')
import gtk
assert gtk.pygtk_version >= (1,99,12), 'pygtk version too old'

class GUI(gtk.Window):
    def __init__(self):
        gtk.Window.__init__(self)

        self.connect('delete_event', self.close_cb)

        # Create the data structure to hold the contents of the list.
        #   It is a four column list; all the columns are strings.
        store = gtk.ListStore(str, str, str, str)
        # Add data to the list.  First add a new row to the data
        #   structure and then add the data to the new row.
        iter = store.append()
        store.set(iter,
                  0, 'Michael',
                  1, 'Patrick',
                  2, 'JasonSmith.',
                  3, 'blue')
        # Add another row
        iter = store.append()
        store.set(iter,
                  0, 'Tim',
                  1, 'Nichol',
                  2, 'Wright',
                  3, 'green')

        # Create a new list widget that displays the data structure
        #   created above.
        view = gtk.TreeView(store)
        # Create two columns and add them to the list.  Note that
        #   there does not need to be a 1:1 mapping between the
        #   contents of the list and the way it is displayed.
        # The renderer is the object responsible for displaying the
        #   text within the column.  We would use
        #   "GtkCellRendererPixbuf" or "GtkCellRendererToggle" if we
        #   were displaying images or boolean values.
        rendertext = gtk.CellRendererText()
        # Create the first column "Surname".  The "text" attribute of
        #   the renderer is set using column 2 of the "store" data
        #   structure, while the background colour is set using the
        #   fourth column.
        surnameCol = gtk.TreeViewColumn('Surname', rendertext, text=2,
                                        background=3)
        view.append_column(surnameCol)
        # Create the "First Name" column.
        firstnameCol = gtk.TreeViewColumn('First Name', rendertext, text=0)
        view.append_column(firstnameCol)
        
        self.add(view)

        self.show_all()

    def close_cb(self, *args):
        gtk.main_quit()
        
if __name__ == "__main__":
    app = GUI()
    gtk.main()
_______________________________________________
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