On 16/06/2015 at 03:29, xxxxxxxx wrote:
Hi conner,
indeed, this was a bit tricky. I guess, that's why Drag&Drop for Python is not documented, yet.
Here's what I did to make it work:
Basically I implemented Message() only for the GeDialog and have a custom MyDragMessage() function on the GeUserArea.
Note: I used the MemoryViewer example from the Python SDK examples. In there I duplicated the mem_info user area and added a static text in between in order to have some "dialog" area.
In my GeUserArea:
def MyDragMessage(self, msg, draginfo, result) :
# Don't discard here, if lost drag or if it has been escaped. Already done in parent dialog.
# Check drop area and discard if not on the user area
if not self.CheckDropArea(msg, True, True) :
self.SetDragDestination(c4d.MOUSE_FORBIDDEN)
return False
# Here: Mouse hovers over user area
# Check if drag is finished (=drop)
if msg.GetInt32(c4d.BFM_DRAG_FINISHED)==1:
print "Dropped on UserArea %s" % self.uaIdx
return True
# Return current mouse cursor for valid drag operation
self.SetDragDestination(c4d.MOUSE_MOVE)
return True
In my GeDialog:
def Message(self, msg, result) :
if msg.GetId()==c4d.BFM_DRAGRECEIVE:
# Get drag object type and data
draginfo = self.GetDragObject(msg)
# Discard if lost drag or if it has been escaped
if msg.GetInt32(c4d.BFM_DRAG_LOST) or msg.GetInt32(c4d.BFM_DRAG_ESC) :
# Not sure, why we need to test the UserArea here as well
if self.mem_info.MyDragMessage(msg, draginfo, result)==True:
return True
if self.mem_info_2.MyDragMessage(msg, draginfo, result)==True:
return True
return self.SetDragDestination(c4d.MOUSE_FORBIDDEN)
# if we are here, mouse hovers over dialog
if self.mem_info.MyDragMessage(msg, draginfo, result)==True:
return True
if self.mem_info_2.MyDragMessage(msg, draginfo, result)==True:
return True
# Check if drag is finished (=drop)
if msg.GetInt32(c4d.BFM_DRAG_FINISHED)==1:
print "Dropped on Dialog"
return True
# Return current mouse cursor for valid drag operation
return self.SetDragDestination(c4d.MOUSE_MOVE)
# Call GeDialog.Message() implementation so that it can handle all the other messages
return gui.GeDialog.Message(self, msg, result)