Python GTK拖放验证X11光标锁定在拖放获取数据中
我无法在pygtk中进行拖放验证。我没有主意了,想听听别人的意见 我的目标是只允许删除包含.jpg的文件 具体来说,每当我在拖动动作回调中调用widget.drag\u get\u data时,X11光标就会锁定。由于我必须杀死X11并重新启动所有程序,因此调试变得单调乏味 这是我的源代码,我认为问题具体在于drag\u motion\u cb和drag\u data\u received\u cb方法。我遗漏了以前尝试过的已注释掉的部分 使用Google代码搜索搜索drag\u get\u数据不会显示其他人正在进行高级验证。所以我猜其他人也失败了 我已经没有主意了,如果我不能弄清楚这一点,我将在我的linux端口中只使用简单的DnD,而不进行适当的验证 提前谢谢 drop\u data\u ready=False drop\u出现=False drop_highlight=False 删除数据=无 def drag_data_received_cbself、小部件、上下文、x、y、数据、信息、时间戳: 打印拖拽数据\u已接收\u cbPython GTK拖放验证X11光标锁定在拖放获取数据中,python,linux,drag-and-drop,gtk,pygtk,Python,Linux,Drag And Drop,Gtk,Pygtk,我无法在pygtk中进行拖放验证。我没有主意了,想听听别人的意见 我的目标是只允许删除包含.jpg的文件 具体来说,每当我在拖动动作回调中调用widget.drag\u get\u data时,X11光标就会锁定。由于我必须杀死X11并重新启动所有程序,因此调试变得单调乏味 这是我的源代码,我认为问题具体在于drag\u motion\u cb和drag\u data\u received\u cb方法。我遗漏了以前尝试过的已注释掉的部分 使用Google代码搜索搜索drag\u get\u数据
# Is it something we can handle?
if target == gtk.gdk.atom_intern("text/uri-list", False):
# Tell data recieved handler (do_drag_data_received) we can actually handle the drop.
self.drop_occurred = True
widget.drag_get_data(context,target,timestamp)
# We can handle this data type.
return True
else:
# We cannot handle the drop.
return False
pass
def drag_drop_cbself,小部件,上下文,x,y,时间戳:
target=widget.drag\u dest\u find\u targetcontext,widget.drag\u dest\u get\u target\u list
if not self.drop_data_ready:
widget.drag_get_data(context, gtk.gdk.atom_intern("text/uri-list",False), timestamp)
return False
"""
target = widget.drag_dest_find_target(context, widget.drag_dest_get_target_list())
if target == gtk.gdk.atom_intern("text/uri-list", False):
if True == self.drop_data_ready:
pass
else:
#widget.drag_get_data(context, target, timestamp)
pass
"""
context.drag_status(gtk.gdk.ACTION_COPY, timestamp)
"""
if target == gtk.gdk.atom_intern("text/uri-list", False):
if True == self.drop_data_ready:
if repr(drop_data).find(".jpg") != -1:
# Tell Gdk we can handle this.
context.drag_status(gtk.gdk.ACTION_COPY, timestamp)
# Draw drop highlight (but only once).
if False == self.drop_highlight:
widget.drag_highlight()
self.drop_highlight = True
# Return here, don't fall through.
return True
else:
# Request drag data from the source.
widget.drag_get_data(context, target, timestamp)
# Fall-through to not allowing.
"""
# not something we can handle
#context.drag_status(0, timestamp) # Don't allow drop.
return True
pass
def drag_motion_cbself,小部件,上下文,x,y,时间戳:
# Un-draw the highlight.
if True == self.drop_highlight:
widget.drag_unhighlight()
self.drop_highlight = False
pass
def drag_leave_cbself、小部件、上下文、时间戳:
清理拖动数据。
如果True==self.drop\u data\u ready:
self.drop_data=None
self.drop\u data\u ready=False
def drag_data_received_cb(self, obj, context, x, y, selection, target_id, etime):
try:
dtype = selection.get_data_type()
except AttributeError:## Old PyGTK
dtype = selection.type
if dtype=='image/jpeg':
image_data = selection.data
## do somthing with image_data
return True
return False
gobject.type_registerTestApp
def主:
car=TestApp
gtk.main
如果名称=='main':
主要
我认为你必须在drag_data_received_cb中执行类似操作
# Is it something we can handle?
if target == gtk.gdk.atom_intern("text/uri-list", False):
# Tell data recieved handler (do_drag_data_received) we can actually handle the drop.
self.drop_occurred = True
widget.drag_get_data(context,target,timestamp)
# We can handle this data type.
return True
else:
# We cannot handle the drop.
return False
pass
将这些大代码粘贴到pastebin.com之类的地方,因为它可能无法正确显示在滚动条中的滚动条和混合缩进
def drag_data_received_cb(self, obj, context, x, y, selection, target_id, etime):
try:
dtype = selection.get_data_type()
except AttributeError:## Old PyGTK
dtype = selection.type
if dtype=='image/jpeg':
image_data = selection.data
## do somthing with image_data
return True
return False