views:

71

answers:

1

So I have this TreeView/TreeStore, which I fill with data from a list. My application uses only said list as reference data. The TreeStore is just constructed for display. And the TreeView can be resorted by tipping the column headers. Because .set_sort_column_id() was used for initialization of each column.

Problem is, following code always returns the clicked row number in the display:

# convert ListStore iter to row number
def rowno(self):
     (model, iter) = self.MY_LIST_STORE.get_selection().get_selected()
     return model.get_path(iter)[0]

It's supposed to do that. This works fine for me as long as the original unsorted list is displayed. Once the TreeView (and TreeStore?) is resorted, the displayed row numbers (.get_path) no longer correspond to the row numbers in my original data store.

How can I map this? Or how can I find out which selected path number corresponds to which entry in the originally passed TreeView list?

(Of course, I could insert a faux column into the TreeStore to keep my original row number. But there must be some kind of native way to achieve it?)

+2  A: 

Congratulations, you have entered just about the most nightmarish thing that PyGTK has to offer. I don't expect any bounty for this, but my solution revolves around wrapping your Model in a Sortable model and also in a Filterable one. This way, you can get the various paths and iters for the 3 nested models depending on what you want. The code is far too extreme for here, but we have generalised it in PyGTKHelpers to use without pain, or to copy for your own implementation. Here is the module.

Ali A
Well, a solution is a solution. I've already concluded the goal can only be reached by tricking PyGTK, and your approach sounds plausible and something that could work. Somewhat stuck on my treeviewcolumn helper code, but I'll try PyGTKHelpers, especially since I've seen it recommended before. And using a native python object as data store would be really cool.
mario
The pygtkehlpers.ui.ObjectList has covered every case we have tried so far. If you want more real time chat, come to #pida on freenode, irc.
Ali A