Get original row number from .get_model() and .get_path() after TreeView was resorted
So I have this TreeView/TreeStore, which I fill with dat开发者_StackOverflow中文版a 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?)
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.
精彩评论