wxTree Drag n Drop

I agree, drag and drop seems to be a tricky thing. However, if you
veto the event, isn't that the same as ignoring the event. Then,
I think you should be able to do whatever ui operation you need in the
EVT_TREE_BEGIN_DRAG handler. Otherwise, it is a bug, right?

def BeginDrag(self, event):
       '''
       EVT_TREE_BEGIN_DRAG handler.
       '''
         
       self.dragItem = event.GetItem()
       event.Veto()
       message = wxMessageDialog(self, 'Error', 'Error')
       message.Show()

···

On Thu, 25 Mar 2004, David Woods wrote:

In my experience, Drag and Drop is a rather tricky beast in any language.

I would try to avoid using a wxMessageDialog in the middle of a Drag, which
could be quite disruptive to the Drag and drop process. For example, you
have to click on a button in the wxMessageDialog, and to be able to do so,
you've by definition let go of the mouse button, which has terminated your
Drag.

Try using the GiveFeedback method in the wxDropSource to alter your cursor,
and if you need to tell your user why a particular Drag failed, you can pop
up a wxMessageDialog after the Drop is attempted. You might be able to use
a Status Bar or something like that if you need to provide additional
information during a Drag, but don't try to use a wxMessageDialog.

Also, I've had much better luck with Drag and Drop within a wxTreeCtrl on
Windows than on other platforms. If you are writing something
cross-platform, and you get something reasonable to work on Mac or *nix,
please share your code with me or put it on the Wiki, as it will help me
solve a big problem I will need to tackle in about a month.

Hope this helps some.

David Woods
Wisconsin Center for Education Research
University of Wisconsin, Madison

-----Original Message-----
From: Susanne Lefvert [mailto:lefvert@mcs.anl.gov]
Sent: Thursday, March 25, 2004 2:28 PM
To: wxPython-users@lists.wxwidgets.org
Subject: Re: [wxPython-users] wxTree Drag n Drop

This also causes the message dialog to hang.

def BeginDrag(self, event):
  '''
  EVT_TREE_BEGIN_DRAG handler.
  '''
        self.dragItem = event.GetItem()
        message = wxMessageDialog(self, 'Error', 'Error')
  message.Show()

On Tue, 23 Mar 2004, Robin Dunn wrote:

> Susanne Lefvert wrote:
> > Hello,
> >
> > I am having a problem with wxTreeCtrl and DnD. Following code causes the
> > wxMessageDialog to be unresponsive when opened in the EndDrag callback
> > method.
>
> When the tree item is being dragged the treectrl has the mouse captured,
> and so when you show the dialog it is not able to receive any mouse
> events. If you want to prevent items from being moved in the tree then
> do your check in the EVT_TREE_BEGIN_DRAG handler and just don't call
> event.Allow.
>
> --
> Robin Dunn
> Software Craftsman
> http://wxPython.org Java give you jitters? Relax with wxPython!
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
> For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org
>
>

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

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

While I don't disagree with your logic, I don't know if that works. It may
be (though I'll be the first to admit I could be wrong) that the Drag and
Drop event processing needs to be totally complete before you move on to
other things such as calling the wxMessageDialog.

I know that if you try to use exceptions during Drag and Drop, things don't
always work as you might expect. Robin responded to a post of mine at some
point and explained that the code jumps back and forth between Python and C
a number of times during the whole drag and drop process, and that the
exception wasn't making it all the way back to where I was trying to trap
it. You may just not be back to a wxMessageDialog-friendly place while
you're still in the BEGIN_DRAG event handler.

What works for me is handling error messages after the whole drag process is
complete, something along the lines of this:

  dragResult = myDropSource.DoDragDrop(True)

  if dragResult == wx.wxDragCopy:
      print "_DBTreeCtrl OnBeginDrag Result indicated successful copy"
  elif dragResult == wx.wxDragMove:
     print "_DBTreeCtrl OnBeginDrag Result indicated successful move"
  else:
     print "_DBTreeCtrl OnBeginDrag Result indicated failed drop"

Because the drag-drop event sequence is over by the time you hit the "if"
statement, you should have no problems with a wxMessageDialog there. That
should give you the same results as what you are trying to do.

David

···

-----Original Message-----
From: Susanne Lefvert [mailto:lefvert@mcs.anl.gov]
Sent: Friday, March 26, 2004 2:24 PM
To: wxPython-users@lists.wxwidgets.org
Subject: RE: [wxPython-users] wxTree Drag n Drop

I agree, drag and drop seems to be a tricky thing. However, if you
veto the event, isn't that the same as ignoring the event. Then,
I think you should be able to do whatever ui operation you need in the
EVT_TREE_BEGIN_DRAG handler. Otherwise, it is a bug, right?

def BeginDrag(self, event):
       '''
       EVT_TREE_BEGIN_DRAG handler.
       '''

       self.dragItem = event.GetItem()
       event.Veto()
       message = wxMessageDialog(self, 'Error', 'Error')
       message.Show()

On Thu, 25 Mar 2004, David Woods wrote:

In my experience, Drag and Drop is a rather tricky beast in any language.

I would try to avoid using a wxMessageDialog in the middle of a Drag,

which

could be quite disruptive to the Drag and drop process. For example, you
have to click on a button in the wxMessageDialog, and to be able to do so,
you've by definition let go of the mouse button, which has terminated your
Drag.

Try using the GiveFeedback method in the wxDropSource to alter your

cursor,

and if you need to tell your user why a particular Drag failed, you can

pop

up a wxMessageDialog after the Drop is attempted. You might be able to

use

a Status Bar or something like that if you need to provide additional
information during a Drag, but don't try to use a wxMessageDialog.

Also, I've had much better luck with Drag and Drop within a wxTreeCtrl on
Windows than on other platforms. If you are writing something
cross-platform, and you get something reasonable to work on Mac or *nix,
please share your code with me or put it on the Wiki, as it will help me
solve a big problem I will need to tackle in about a month.

Hope this helps some.

David Woods
Wisconsin Center for Education Research
University of Wisconsin, Madison

-----Original Message-----
From: Susanne Lefvert [mailto:lefvert@mcs.anl.gov]
Sent: Thursday, March 25, 2004 2:28 PM
To: wxPython-users@lists.wxwidgets.org
Subject: Re: [wxPython-users] wxTree Drag n Drop

This also causes the message dialog to hang.

def BeginDrag(self, event):
  '''
  EVT_TREE_BEGIN_DRAG handler.
  '''
        self.dragItem = event.GetItem()
        message = wxMessageDialog(self, 'Error', 'Error')
  message.Show()

On Tue, 23 Mar 2004, Robin Dunn wrote:

> Susanne Lefvert wrote:
> > Hello,
> >
> > I am having a problem with wxTreeCtrl and DnD. Following code causes

the

> > wxMessageDialog to be unresponsive when opened in the EndDrag callback
> > method.
>
> When the tree item is being dragged the treectrl has the mouse captured,
> and so when you show the dialog it is not able to receive any mouse
> events. If you want to prevent items from being moved in the tree then
> do your check in the EVT_TREE_BEGIN_DRAG handler and just don't call
> event.Allow.
>
> --
> Robin Dunn
> Software Craftsman
> http://wxPython.org Java give you jitters? Relax with wxPython!
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
> For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org
>
>

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

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

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