对 GtkTreeView 的拖放支持,其中模型被过滤和排序

发布于 2024-09-06 16:11:18 字数 728 浏览 14 评论 0原文

正如标题所示,我有一个 gtk.TreeView ,其模型已排序和过滤。根据 文档:“拖放行重新排序仅适用于未排序的情况商店”。给出的唯一其他信息与使用外部资源有关,在本例中我不需要。

无论如何,我尝试实现它,为收到的拖放信号和拖放信号提供处理程序,但仍然出现以下错误:

GtkWarning:当使用不支持 GtkTreeDragDest 接口并启用拖放功能的模型时,您必须覆盖 GtkTreeView 上默认的“drag_data_received”处理程序。最简单的方法是连接到“drag_data_received”并在信号处理程序中调用 g_signal_stop_emission_by_name() 以防止默认处理程序运行。查看 gtktreeview.c 中默认处理程序的源代码,了解您的处理程序应该做什么。 (gtktreeview.c 位于 GTK 源代码中。)如果您使用 C 以外的语言的 GTK,可能有更自然的方法来覆盖默认处理程序,例如通过派生。

尽管如此,虽然我还没有实现它,但看起来我可以让它工作,因为它不会崩溃。尽管如此,这是我不想收到的警告。

那么,是否有相当于 g_signal_stop_emission_by_name 的Python,或者我是否以错误的方式处理这个问题?

As the title suggests, I have a gtk.TreeView whose model is sorted and filtered. According to the documentation: "Drag and drop reordering of rows only works with unsorted stores.". The only other information given relates to using external sources, which in this case I don't need.

I tried implementing it anyway, providing handlers to the drag-dest received and drag-drop signals, but still get the following error:

GtkWarning: You must override the default 'drag_data_received' handler on GtkTreeView when using models that don't support the GtkTreeDragDest interface and enabling drag-and-drop. The simplest way to do this is to connect to 'drag_data_received' and call g_signal_stop_emission_by_name() in your signal handler to prevent the default handler from running. Look at the source code for the default handler in gtktreeview.c to get an idea what your handler should do. (gtktreeview.c is in the GTK source code.) If you're using GTK from a language other than C, there may be a more natural way to override default handlers, e.g. via derivation.

Despite this, although I haven't implemented it yet, it looks like I could make it work, since it doesn't crash. Nevertheless, this is a warning I'd rather not have.

So, Is there a python equivalent of g_signal_stop_emission_by_name, or am I going about this the wrong way?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

西瑶 2024-09-13 16:11:18

我有点困惑,因为我已经有了一个“拖放”处理程序,但在实现以下内容后进行了排序:

def __init__(self):
    self.treeview.connect("drag_data_received", self.on_drag_data_received)

def on_drag_data_received(self, widget, drag_context, x, y, selection_data, info, timestamp):
    widget.stop_emission('drag_data_received')

只是添加,根据 pygtk 文档,*emit_stop_by_name* 和 *stop_emission* 是相同的。

I got a bit confused as I already had a "drag-drop" handler but was sorted once I implemented the following:

def __init__(self):
    self.treeview.connect("drag_data_received", self.on_drag_data_received)

def on_drag_data_received(self, widget, drag_context, x, y, selection_data, info, timestamp):
    widget.stop_emission('drag_data_received')

Just to add, according to pygtk docs, *emit_stop_by_name* and *stop_emission* are identical.

最美不过初阳 2024-09-13 16:11:18

它是gobject.GObject.emit_stop_by_name()。我不知道你所做的是否会成功,但我想不出“标准”的方法。

您可以尝试使用 Py-gtktree 来代替自己实现:请参阅名为 drag_ Between_tree_and_list.py 的示例。您可以对右侧的树进行排序,并且仍然能够将拖入的项目自动放置在“正确”的位置,并将其拖入其中。它不允许拖动到树中的任何位置,但出于不同的原因:示例明确要求这样做。

It is gobject.GObject.emit_stop_by_name(). I don't know if what you are doing will succeed, but there is no "standard" way I can think of.

Instead of implementing yourself, you could try using Py-gtktree: see example called drag_between_tree_and_list.py. You can sort the tree on the right and still be able to drag into it with items dragged in automatically placed in the "correct" position. It doesn't allow draggin anywhere into the tree, but for a different reason: example explicitly requests this.

别忘他 2024-09-13 16:11:18

我通过在我自己的拖放接收信号处理程序中使用 treeview.stop_emission('drag-drop-received') 摆脱了警告。也许 doublep 的方法也可以工作,尽管我还没有尝试过。

I got rid of the warning by using treeview.stop_emission('drag-drop-received') in my own drag-drop-received signal handler. Perhaps the method by doublep will also work, although I haven't tried it.

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