编程语言
首页 > 编程语言> > python – 对GtkTreeView的拖放支持,其中模型被过滤和排序

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

作者:互联网

正如标题所示,我有一个gtk.TreeView,其模型被排序和过滤.根据documentation:“行的拖放重新排序仅适用于未分类的商店.”给出的唯一其他信息涉及使用外部源,在这种情况下我不需要.

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

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.

尽管如此,虽然我还没有实现它,但看起来我可以使它工作,因为它不会崩溃.尽管如此,这是一个我宁愿没有的警告.

那么,是否存在与g_signal_stop_emission_by_name等效的python,或者我是否以错误的方式进行此操作?

解决方法:

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

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 docs,* emit_stop_by_name *和* stop_emission *是相同的.

标签:python,pygtk,gtktreeview
来源: https://codeday.me/bug/20190621/1258150.html