Help with TreeCtrl + DND and debugging.

The DND example in TreeControls DOES work (at least on Windows), but you
have to understand what it's trying to do. It doesn't actually move tree
nodes, as that's not what my application does. Watch your stdout window
when you drag nodes from one branch to the other, and you will see text that
describes what you did. In my application, dragging between nodes applies
data behind the scenes that does not change the tree structure.

Example output:

A node called Series 2 is being dragged
Dropped on Collection 3.
Drop Data = 'SourceText = 'Series 2'' dropped onto Collection 3
OnData Result indicated successful move
Result indicated successful move

A node called Collection 2 is being dragged
Dropped on Series 1.
Drop Data = 'SourceText = 'Collection 2'' dropped onto Series 1
OnData Result indicated successful copy
Result indicated successful copy

David Woods

ยทยทยท

-----Original Message-----
From: news [mailto:news@sea.gmane.org]On Behalf Of Chris Green
Sent: Wednesday, March 03, 2004 11:45 AM
To: wxpython-users@lists.wxwindows.org
Subject: [wxPython-users] Help with TreeCtrl + DND and debugging.

There are 2 examples in the wiki:

http://wiki.wxpython.org/index.cgi/TreeControls and
http://wiki.wxpython.org/index.cgi/TreeCtrlDnD

TreeCtrlDND is nice because it's only dedicated to the single topic.
TreeControls doesn't work at all [1].

but it has an odd comment regarding

def OnBeginDrag(self, event):
        item = event.GetItem()
        tree = event.GetEventObject()

        if item != tree.GetRootItem(): # prevent dragging root item
            def DoDragDrop():
                [....]
              wxCallAfter(DoDragDrop) # can't call dropSource.DoDragDrop
here..

Why can't it call it there? Is that historical? The other one was..
When I emulated the call after behavior with

    def _onBeginDragHelper(self):
        """ Helper function for _onBeginDrag that is set to be called
        after the drag and drop operation is complete"""
        item = self._currentDndItem
        dataObj = TreeControlData(item)
        dropSource = wx.DropSource(self)
        dropSource.SetData(dataObj)
        result = dropSource.DoDragDrop(wx.Drag_DefaultMove)
        DebugMessage("drag finished with res: %s" % str(result))
        # self._currentDndItem = None

    def _onBeginDrag(self, event):
        """ Callback for when a drag and drop event starts """
        self._currentDndItem = None

        item = event.GetItem()
        if item != self.GetRootItem():
            # make sure that they don't drag the prject around
            self._currentDndItem = item
            DebugMessage("starting to drag %s" % self.GetItemText(item))
            wx.CallAfter(self._onBeginDragHelper)

I get

TreeControl._OnBeginDrag()
TreeControlDropTarget.OnDragOver() multiple times
TreeControlDropTarget.OnDrop()
   returns True......
~5 minutes go by
TreeControl_onBeginDragHelper() - drag finished with XXXX

I never get a TreeControlDropTarget.OnData() called which I think
should be called immediately after OnDrop(). I think I'm definately
doing something (callafter?) to screw up the event loop since all
other TreeControlbuttons in my application then become disabled.

Footnotes:
[1] Error from http://wiki.wxpython.org/index.cgi/TreeControls

File "/home/cmg/a.py", line 104, in OnBeginDrag
    self.tree.SelectItem(sel_item)
  File "/usr/lib/python2.3/site-packages/wxPython/controls2.py", line 1131,
in SelectItem
    val = controls2c.wxTreeCtrl_SelectItem(self, *_args, **_kwargs)
wxPython.wxc.wxPyAssertionError: C++ assertion "wxAssertFailure" failed in
/usr/src/redhat/BUILD/wxPythonSrc-2.4.2.4/src/generic/treectlg.cpp(1740):
invalid tree item

I've saw a reference to treecontrols needing a image list for DND to
work and this one doesn't. When assigning one to it however, I Didn't
get it to work.
--
Chris Green <cmg@dok.org>
"Not everyone holds these truths to be self-evident, so we've worked
                  up a proof of them as Appendix A." -- Paul Prescod

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org