wxPython and Drag and Drop

Robin Dunn robin at alldunn.com
Mon Sep 25 17:54:05 EDT 2000


"Christopher Paulicka" <cpaulicka at 8cs.com> wrote in comp.lang.python:
> I am using wxPython, and have created a PythonClassDataObject, allowing me
> to drag class objects between different list ctrls and tree ctrls that I
> have developed.
>
> The problem is that some of the ctrls support some classes, while others
> support other classes.
>
> There doesn't seem to be a way for the wxDropTarget to query any
information
> from the wxDropSource.  You can do this under Windows using IDropTarget,
and
> access the data directly through the IDataObject interface.
>
> If I could access the wxDropSource's PythonClassDataObject, I could check
> the class inside of wxDropTarget::OnEnter(), and display the appropriate
> symbol.  Right now, I cannot, so have to make the drop, figure out that
the
> class doesn't work, and then undo any damage.  This is not the right way
to
> do it.
>


wxWindows does this automatically for you based on the data format of the
data object in the drop target.  For example if your drop target has a
wxTextDataObject loaded into it and the drop source has provided a bitmap
data object, then the cursor is automatically changed to the
circle-with-bar.  You can accept multiple formats by using a
wxDataObjectComposite.

In your case you probably want to create different classes of data objects
based on the class (or set of classes) of the python object they will be
dragging around.  These data object classes could be identical to each other
except for the data format name given to wxCustomDataFormat.  Then for the
drop targets that only accept a certain data type, you just need to call
SetData with the appropriate wxDataObject-derived class that specifies that
type.  The rest is automatic.


>
> P.S.  On the same note, is there any way to query the key state for the
> wxDropTarget methods, such as OnEnter?  Again, this is provided with
> IDropTarget under Windows.
>

Not that I know of, but the drag result passed to OnEnter will tell you a
bit about the state of the keys.  It will be wxDragCopy or wxDragMove based
on the state of the Ctrl key, I think...

--
Robin Dunn
Software Craftsman
robin at AllDunn.com
http://wxPython.org     Java give you jitters?
http://wxPROs.com        Relax with wxPython!







More information about the Python-list mailing list