On Sat, Nov 01, 2003 at 12:52:56PM -0500, Hans Deragon wrote:

>   Newbie here.  I tried to figure out how to remove a row from a 
> GTK.ListStore  on the web (documentation and mailing list archives), but I 
> could not figure it out.  The documentation is pretty poor.
> 
>   What I want to figure out is how can I get the iter required by 
> GTK.ListStore.remove()?  I have a GTK.TreeView with at GTK.ListStore as a 
> Model.  I want to remove the row that has been selected by the user.  How 
> do I proceed?  How do I obtain the iter that points to the currently 
> selected item? It must be easy, but I cannot find the function that would 
>  return the iter.

TreeView contains a selection object that manages user selections.  You need
to get the selection object, then query it for the selected path with the
get_selected() method.  For single selection mode:

selection = treeview.get_selection()
result = selection.get_selected()
if result: #result could be None
   model, iter = result
model.remove(iter)

For multiple selection mode you need to use a little hack to get the
selected paths until get_selected_rows() is implemented (2.2 API):

rows = []
selection.selected_foreach(lambda model, path, iter: rows.append(path))

rows will then be a list of selected paths, and you can use
model.get_iter(path) to get the iters.  Note that this "hack" will work with
either selection mode, so I use it everywhere instead of get_selected().

Dave Cook
_______________________________________________
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