TreeView 重排序后,从 .get_model() 和 .get_path() 获取原始行号

发布于 2024-09-24 04:21:13 字数 617 浏览 8 评论 0原文

所以我有这个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

提笔书几行 2024-10-01 04:21:13

恭喜,您已经进入了 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文