Re: reordering GtkListStore items



David M. Cook wrote:
On Sat, Mar 20, 2004 at 01:03:08AM +0200, Paul Pogonyshev wrote:

Is there an easy way to swap a given list store item with
next/previous item?  I'm facing two problems: there appear
to be no reordering functions in GTK+ 2.0 (all marked as
"since 2.2") and there is gtk_tree_model_iter_next(), but
no gtk_tree_mode_iter_previous().

In Python:

path = store.get_path(iter)
i = path[-1] # last index of path
parent = store.iter_parent(iter)
if i > 0:
   previous = store.iter_nth_child(parent, i-1)
else:
   previous = None
   
Or even simpler (though I don't know how to do the path aritmetic in C)

path = store.get_path(iter)
if path[-1] > 0:
  previous = store.get_iter(path[:-1] + (path[-1]+1,))
else:
  previous = None

Thank you, this worked.  I solved the second problem (with lack of
reording functions in GTK+ 2.0) too: instead of swapping items I
just swap their data with gtk_list_store_set().

Paul



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]