You are not logged in.

#1 2008-04-09 21:30:16

icrave
Member
Registered: 2006-04-11
Posts: 193

(PyGTK) Multiple selected rows on TreeView

Hello, I'm coding a small burn application in pygtk with a TreeView in it on I list the files to burn.
I have activated SELECTION_MULTIPLE, and when I try get the paths, these are incorrect. This only happens with multiple rows, with one row works.

For example, if I select three rows, the path given was:

(0, ) (1, ) (0, )

But if i select the three rows separately, one after one...

(0, )
(1, )
(2, )

The small code of the function:

sorted_model, selected = self.treeselection.get_selected_rows()
for path in selected:
    iter = sorted_model.get_iter(path)
    # Delete from list
    sorted_model.remove(iter)

* The paths are on selected.

Someone may knows what I'm doing wrong?

Thanks.

Offline

#2 2008-04-10 00:33:21

stonecrest
Member
From: Boulder
Registered: 2005-01-22
Posts: 1,190

Re: (PyGTK) Multiple selected rows on TreeView

icrave wrote:
sorted_model, selected = self.treeselection.get_selected_rows()
for path in selected:
    iter = sorted_model.get_iter(path)
    # Delete from list
    sorted_model.remove(iter)

* The paths are on selected.

Someone may knows what I'm doing wrong?

I'm not sure you've provided enough information to precisely understand the question, but the above code has the potential to work incorrectly. As you remove an iter, all of the paths below it are going to decrement, so when you request the next iter based on a stored path, it could now be off.

I'd suggest either 1) getting all of the iters from the paths before removing any of them, or 2) ordering the paths and removing them from end to beginning. Suggestion 1 would look like:

sorted_model, selected = self.treeselection.get_selected_rows()
iters = []
for path in selected:
    iters.append(sorted_model.get_iter(path))
for iter in iters:
    # Delete from list
    sorted_model.remove(iter)

But if you want more help on your question, I need to see more code. For example, in what callback does this code live? Where are you printing the rows?

Last edited by stonecrest (2008-04-10 00:34:35)


I am a gated community.

Offline

#3 2008-04-10 09:36:06

icrave
Member
Registered: 2006-04-11
Posts: 193

Re: (PyGTK) Multiple selected rows on TreeView

Hi,

Yes, the first that I thought was the decrement error, so I tried the second option that you suggested. And it didn't worked. The paths given by get_selected_rows are symmetrically: for three (0,1,0), for four (0, 1, 1, 0), for five (0, 1, 2, 1, 0), etc. So, when I invert the list, the result are identically to the original.

The rows are printed after get_selected_rows and before the bucle. So, technically, there still weren't modified.

Now, I am not at home, but tonight I will prove your first suggestion and I will post more code for explain it.

Thank you.

------------------

Edit: Great! It works. Thanks stonecrest.

Last edited by icrave (2008-04-10 16:20:04)

Offline

Board footer

Powered by FluxBB