dave <[EMAIL PROTECTED]> writes: > So I just finished going through the treeview documentation and > tutorials, and I'm a little confused (not uncommon for me). My goal is > to do two things: > 1. Have each line in the treeview connected to an object and let the > object tell the treeview what to display, and when it needs to update > the display. > 2. Optionally also somehow have some of the lines have icons as well > as text. (The texts make references to "HBOX-like capabilities" - but > I don't see any way of packing arbitrary widgets into the cell render > (i.e. a text widget and a icon).) > > Does anyone have a quick hint?
Maybe someone else will be able to give you something quicker. The main references are the pygtk tutorial at http://www.pygtk.org/pygtk2tutorial/index.html and the pygtk FAQ at http://www.async.com.br/faq/pygtk/index.py?req=index. You've probably read those, but if you haven't, make sure you look through the treeview sections first. The first thing to say about the treeview is that it is hard to get started with it. It certainly confused me. I promise that if you try out the examples it will slowly make more sense. 1. One approach to using python objects as rows in a treeview is to create a custom treemodel. Now that I've mentioned custom treemodels forget about them for now and instead use treeview cell data functions because they're much simpler. There are two examples in the FAQ, entries 13.24 and 13.29. The pygtk tutorial has an even better example, filelisting.py, which is described in tutorial section 14.4.5. A good approach might be to try that program and modify it step by step to fit your needs. 2. Gtk+ doesn't allow packing arbitrary widgets into cells. For now we have only cell renderers for text, pixbufs and toggle buttons. (A cell renderer for comboboxes is on the way for gtk+ 2.6.) Fortunately all you need is text and pixbuf. John Finlay's tutorial filelisting.py example shows you what you need to do. The pygtk FAQ item 13.6 also shows an example of using CellRendererText and CellRendererPixbuf. You can pack multiple renderers into a single column or you can put each in a different column. I didn't actually give a complete answer to 1) because you want the treeview to update when an object in the model changes. The examples don't show that. To do this you need to emit the 'row-changed' signal after any change to an object that should cause the treeview to update. The call to use is model.row_changed(path,iter). If each model object knows where it is in the model (the path or the iter), this is easy. Unfortunately often model objects don't know their own path. This is basically the same issue as putting an object in a container such as a list. Generally the object won't know its position in the list (or even be aware that it's in a list) and in fact it could easily be in multiple lists at once. I don't have a recommendation for the best way to manage this. It probably depends on specifics of your application. Simple approaches include searching the model for the object to find its position (slow if the model is large) and storing the path in each object in the model (annoying updates required if rows are reordered or deleted or inserted anywhere but the end, and even harder to do if objects can be shared between multiple models). To avoid some of the annoyances of storing the path in each object you could instead store a gtk+ row proxy. Gtk+ tree row proxies observe the model and always know their own path. There are more general solutions using tree row proxies as well. This isn't easy to describe, so I hope someone else will have a brilliantly simple suggestion, or at least a better explanation. If you try the tutorial and FAQ examples out and can't figure out how to get from there to where you want to go, post another question and someone will probably be able to help you. On the bright side, you didn't ask (yet) about treeview drag and drop -- that's another can of worms. _______________________________________________ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
