TreeView 重排序后,从 .get_model() 和 .get_path() 获取原始行号
所以我有这个 TreeView/TreeStore,我用列表中的数据填充它。我的应用程序仅使用所述列表作为参考数据。 TreeStore 只是为了显示而构建的。并且可以通过倾斜列标题来重新排列 TreeView。因为.set_sort_column_id()用于每列的初始化。
问题是,以下代码始终返回显示中单击的行号:
# 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]
它应该这样做。只要显示原始未排序列表,这对我来说就很好。一旦重新排列 TreeView(和 TreeStore?),显示的行号 (.get_path
) 不再对应于原始数据存储中的行号。
我怎样才能映射这个?或者我如何找出哪个选定的路径号对应于最初传递的 TreeView 列表中的哪个条目?
(当然,我可以在 TreeStore 中插入一个人造列以保留原始行号。但必须有某种本机方法来实现它?)
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?)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
恭喜,您已经进入了 PyGTK 所提供的最噩梦般的东西。我不期望为此获得任何赏金,但我的解决方案围绕将模型包装在可排序模型和可过滤模型中。这样,您就可以根据需要获取 3 个嵌套模型的各种路径和迭代器。此处的代码过于极端,但我们已将其概括为 PyGTKHelpers 以便轻松使用,或复制以供您自己实施。 这是该模块。
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.