OK, so you can probably just work with an unsorted list model and on those up and down arrow buttons, swap the current row with the one above or below. Then, when the user is done with reordering, get an iterator and work through the rows in order.
Hi r-senior,
the main issue that I am having is, that I can't get the items to "switch" the positions. I manage to get the selections that I made and so on, but I am not able to use the Gtk specific types to my advantage. Due to lack of information, I am trying to use the model like a list, which in some instances works and in others (like this one) doesn't. I attached a simplified example with no specific cases to explain the problem.
Code:
def on_upbutton_clicked(self, button):
"""
Moves each selection one position up.
"""
# get the selected rows as paths
sel_model, sel_rows = self.merge_view.get_selection().get_selected_rows()
# store the treeiters from paths
iters = []
for row in sel_rows:
iters.append(self.merge_model.get_iter(row))
for i in iters:
if i is not None:
# get the previous position, too
prev_iter = self.merge_model.iter_previous(i)
# Test that the items are both valid
print "1. " + self.merge_model[prev_iter][0]
print "2. " + self.merge_model[i][0]
# Try to swap like in a list
self.merge_model[prev_iter], self.merge_model[i] = self.merge_model[i], self.merge_model[prev_iter]
# This gives a Type Error as the type has changed to 'TreeModelRow'
print "1. " + self.merge_model[prev_iter][0]
print "2. " + self.merge_model[i][0]
What I am trying to show here is, that on "switching",I suddenly fall victim to a change in type, which I find very odd.
Using the selected rows from 'sel_model, sel_rows = self.merge_view.get_selection().get_selected_rows( )' also doesn't work as they are Gtk.TreePath types. Another type where I have no clue why it exists.
I am not sure if I made sense here, if I haven't please let me know and I try to be clearer. Thanks for your help.
As a side note, this has strayed quite far from the original topic that I am considering to change the title. Is that possible... or wise?
Bookmarks