>>>>> "John" == John Hunter <[EMAIL PROTECTED]> writes:
John> Where is the magic pixie dust that I am missing?
OK, I knew I was making this too hard. It just took a few hours of
poring over the documentation and examples to figure *the right way*
to do it. Here is a demo script which does the multiselection using
ListStore and TreeView for the next hapless soul who passes this way
import gobject
import gtk
COLUMN_TEXT=0
# initialize the ListStore. Fom more complicated lists, see pygtk src example
# pygtk-demo/demos/list_store.py
mydata = ['John', 'Miriam', 'Rahel', 'Ava', 'Baerbel']
model = gtk.ListStore(gobject.TYPE_STRING)
for item in mydata:
iter = model.append()
model.set(iter, COLUMN_TEXT, item)
# set up the treeview to do multiple selection
treeview = gtk.TreeView(model)
treeview.set_rules_hint(gtk.TRUE)
column = gtk.TreeViewColumn('Name', gtk.CellRendererText(),
text=COLUMN_TEXT)
treeview.append_column(column)
treeview.get_selection().set_mode(gtk.SELECTION_MULTIPLE)
# when you click ok, call this function for each selected item
def foreach(model, path, iter, selected):
selected.append(model.get_value(iter, COLUMN_TEXT))
def ok_clicked(event):
selected = []
treeview.get_selection().selected_foreach(foreach, selected)
print 'And the winners are...', selected
gtk.main_quit()
# the rest is just window boilerplate
win = gtk.Window()
win.connect('destroy', lambda win: gtk.main_quit())
win.set_title('GtkListStore demo')
win.set_border_width(8)
vbox = gtk.VBox(gtk.FALSE, 8)
win.add(vbox)
label = gtk.Label('Select your firends and family')
vbox.pack_start(label, gtk.FALSE, gtk.FALSE)
sw = gtk.ScrolledWindow()
sw.set_shadow_type(gtk.SHADOW_ETCHED_IN)
sw.set_policy(gtk.POLICY_NEVER,
gtk.POLICY_AUTOMATIC)
vbox.pack_start(sw)
sw.add(treeview)
win.set_default_size(280, 250)
button = gtk.Button('OK')
button.show()
button.connect("clicked", ok_clicked )
vbox.pack_end(button,gtk.FALSE)
win.show_all()
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/