[Gllug] pygtk treeview selection bug?

Troy Jendra troybie at gmail.com
Sun Aug 20 11:04:06 UTC 2006


Hi

I'm getting wierd results with treeview multiple selections in pygtk.
I'm pretty new to pygtk, so can anyone let me know if I'm doing
something wrong, or if it's a bug?  I've tried it with python-gtk2
2.8.6(in dapper) and 2.9.6(in edgy).  Here's the most minimalist
example I could muster(50 lines).  Do attachments work on this list?

Cheers
Troy

=-=-=-=-=-



#!/usr/bin/python
"""treeselectionbug.py - test case to identify a bug in multiple selection"""
import gtk


def Selections(treeView):
  """handle selections"""

  treeSelection = treeView.get_selection()
  rows = treeSelection.count_selected_rows()
  print 'Handling selection - rows selected:', rows
  if rows > 0:
    treeModel, paths =  treeSelection.get_selected_rows()
    for path in paths:
      print treeModel[path][0]
  print


# create window
window = gtk.Window()
window.connect('destroy', lambda w: gtk.main_quit())

# tree view with list store data
listStore = gtk.ListStore(str)
listStore.append(('row0 - Try multi selecting',))
listStore.append(('row1 - using shift and/or ctrl.',))
listStore.append(('row2 - I get some wierd results',))
listStore.append(('row3 - with pygtk 2.8.6 and 2.9.6.',))
listStore.append(('row4 - Seems like the results are lagging one click
behind.',))
treeView = gtk.TreeView(listStore)

# treeview column
renderer = gtk.CellRendererText()
column = gtk.TreeViewColumn('column0')
column.pack_start(renderer)
column.add_attribute(renderer, 'text', 0)
treeView.append_column(column)
window.add(treeView)

# allow multiple selections
treeView.get_selection().set_mode(gtk.SELECTION_MULTIPLE)

# handle selections
treeView.connect('cursor-changed', Selections)

# display our application
window.show_all()

gtk.main()


=-=-=-=-=-
-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list