[pygtk] Inserting into a TreeView
Steve McClure
smcclure at racemi.com
Thu Apr 23 20:56:57 WST 2009
On Apr 23, 2009, at 3:18 AM, Johannes Bauer wrote:
> Hello list,
>
> I'm equally stuck right now when back a few weeks ago as I tried to
> insert items into a ComboBox (which I got working, thanks to your
> help).
>
> This time, I'm trying to insert items into a TreeView and just can't
> get
> it to work. Basically I want something which looks like this:
> http://med.fsu.edu/library/Newsletter200503/Scrollbox_WOK.gif
>
> This appearently is done with the TreeView (there is a "List" and
> "ColumnList" in my glade-version, but they're marked as deprecated). I
> just want to insert a list of items and the users clicks on one, I
> get a
> signal and can query which ID it is.
>
> How can I do this easily?
Easy is a relative word.
Have you read the main tutorial on this topic?
http://www.pygtk.org/pygtk2tutorial/ch-TreeViewWidget.html
I'm pretty rusty on this now but basically something like this:
self.model = gtk.TreeStore(gobject.TYPE_STRING)
for name in resourceNames:
iter = self.model.append(None, name)
self.view = gtk.TreeView(self.model)
self.view.set_model(self.model)
# connect to the selection mechansism to enable/disable action buttons
self.selection = self.view.get_selection()
self.selection.connect('changed', self.enableButtons)
cell = gtk.CellRendererText()
col = gtk.TreeViewColumn('Resource', cell, text=1)
self.view.append_column(col)
def enableButtons(self, treeSelection):
model, iterator = treeSelection.get_selected()
> Kind regards,
> Johannes
> _______________________________________________
> pygtk mailing list pygtk at daa.com.au
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ: http://faq.pygtk.org/
>
--
Steve McClure
smcclure at racemi.com
More information about the pygtk
mailing list