Hi All ,
test case: trying dragging a node onto to another node
I get a failed drop on windows . which is correct. I return false always on the on drop methos.
I get successfull move on mac…
can anyone help me out here…
cheers
Thomas
import wx
import cPickle;
ID_ROOTNODE=1
wxID_FRAME2TREECTRL1=100
class TestDropSource(wx.DropSource):
“”" This is a custom DropSource object designed to provide feedback to the user during the drag “”"
def init(self, frame,tree):
wx.DropSource.init(self,frame)
self.tree = tree
def SetData(self, obj, originalData):
# Set the prepared object as the wxDropSource Data
wx.DropSource.SetData(self, obj)
# hold onto the original data for later use
self.data = originalData
class TestDropTarget(wx.PyDropTarget):
def init(self, treeCtrl,frame):
wx.PyDropTarget.init(self)
self.treeCtrl = treeCtrl
self.frame = frame
self.df = wx.CustomDataFormat(‘TransanaData’)
self.cdo =wx.CustomDataObject(self.df)
self.SetDataObject(self.cdo)
def OnDragOver(self, x, y, d):
# provide visual feedback by selecting the item the mouse is over
item, flags = self.treeCtrl.HitTest((x,y))
selections = self.treeCtrl.GetSelections()
if item:
if selections != [item]:
self.treeCtrl.UnselectAll()
self.treeCtrl.SelectItem(item)
elif selections:
self.treeCtrl.UnselectAll()
return d
def OnEnter(self, x, y, d):
return d
def OnLeave(self):
pass
def OnDrop(self, x, y):
return(False)
def OnData(self, x, y, d):
if self.GetData():
print self.GetData()
if d == wx.DragCopy:
print "OnData Result indicated successful copy"
elif d == wx.DragMove:
print "OnData Result indicated successful move"
else:
print "OnData Result indicated failed drop"
return d
class MainWindow(wx.Frame):
def init(self,parent,id,title):
wx.Frame.init(self,parent,wx.ID_ANY, title, size = ( 800,600),
style=wx.DEFAULT_FRAME_STYLE|wx.NO_FULL_REPAINT_ON_RESIZE)
self.treeMap={}
self.buildTree()
self.Show(True);self.Hide();self.Show(True)
def buildTree(self):
self.treeView = wx.TreeCtrl(id=wxID_FRAME2TREECTRL1, name='treeCtrl1',
parent=self, pos=wx.Point(72, 56), size=wx.Size(272, 144),
style=wx.TR_MULTIPLE | wx.TR_HAS_BUTTONS |wx.TR_HIDE_ROOT)
self.treeView.Bind(wx.EVT_TREE_BEGIN_DRAG,
self.OnTreeCtrl1TreeBeginDrag, id=wxID_FRAME2TREECTRL1)
self.buildTreeList();
def buildTreeList(self):
#treeList = [[2, ‘Demo Site’], [6, ‘Demo Site : Company 1’], [244, ‘Demo Site : eforms’]]
_treeList = [
[2,‘Demo Site’,None,‘OFFICE’],
[6,‘Company 1’,2,‘OFFICE’],
[601,‘Images’,6,‘CATEGORY’],
[244,‘eforms’,2,‘OFFICE’],
[101,‘Images’,2,‘CATEGORY’],
[102,‘Logos’,2,‘CATEGORY’]
]
rootNode=self.treeView.AddRoot(“Upload/Download”,image = -1, data = None)
for item in _treeList:
temp=wx.TreeItemData();
temp.SetData(item)
if self.treeMap.has_key(item[2]):
parentNode=self.treeMap[item[2]]
child=self.treeView.AppendItem(parentNode,item[1],data=temp)
self.treeMap[item[0]]=child;
else:
child=self.treeView.AppendItem(rootNode,item[1],data=temp)
self.treeMap[item[0]]=child;
def OnTreeCtrl1TreeBeginDrag(self, event):
print “i was called”
#permission for moving is same as delete
if (1):
dt = TestDropTarget(self.treeView,self)
self.treeView.SetDropTarget(dt)
selNode = event.GetItem()
data=[“Thomas testing”]
pddd = cPickle.dumps(data, 1)
cdo = wx.CustomDataObject(wx.CustomDataFormat(‘TransanaData’))
cdo.SetData(pddd)
tds = TestDropSource(self,self.treeView)
tds.SetData(cdo, data)
dragResult = tds.DoDragDrop(True)
if dragResult == wx.DragCopy:
print “Result indicated successful copy”
elif dragResult == wx.DragMove:
print “Result indicated successful move”
self.treeView.Delete(selNode);
else:
print “Result indicated failed drop”
app = wx.App()
frame = MainWindow(None, -1, “DocBox Client”)
app.MainLoop()
···
Thomas Thomas
phone +64 7 855 8478
fax +64 7 855 8871