【发布时间】:2021-08-21 09:09:48
【问题描述】:
我正在尝试使用 Python 在 Gtk3 中实现 DND,但到目前为止,我只设法捕获了 drag-begin 信号。代码如下:
class MyWidget(Gtk.EventBox):
def __init__(self):
super(TrackBox, self).__init__()
self.drag_source_set(Gdk.ModifierType.BUTTON1_MASK, [], Gdk.DragAction.MOVE)
self.connect('drag-begin', self._sig_drag_begin)
self.connect('drag-data-get', self._sig_drag_data_get)
self.drag_dest_set(Gtk.DestDefaults.HIGHLIGHT | Gtk.DestDefaults.DROP | Gtk.DestDefaults.MOTION, [Gtk.TargetEntry.new('GTK_MYWIDGET', Gtk.TargetFlags.SAME_APP, 0)], Gdk.DragAction.MOVE)
self.connect('drag-drop', self._sig_drag_drop)
self.connect('drag-data-received', self._sig_drag_data_received)
def _sig_drag_begin(self, widget, context):
print("drag begin")
print(self, widget, context)
def _sig_drag_data_get(self, widget, context, selection, info, timestamp):
print("drag data get")
print(self, widget, context, selection, info, timestamp)
def _sig_drag_drop(self, widget, context, x, y, timestamp):
print('drag-drop')
print(self, widget, context, x, y, timestamp)
def _sig_drag_data_received(self, widget, context, x, y, selection, info, timestamp):
print('drag-data-received')
print(self, widget, context, x, y, selection, info, timestamp)
我从_sig_drag_begin 得到了输出,但没有别的。目标是能够在Gtk.Box 中重新排序这些Gtk.EventBox-es,最终结果与我们可以通过可重新排序的Gtk.TreeView 得到的结果有些相似。
【问题讨论】:
标签: python-3.x drag-and-drop gtk gtk3 pygobject