phoenix_title wx.GenericDragImage

This class is used when you wish to drag an object on the screen, and a simple cursor is not enough.

On Windows, the Win32 API is used to achieve smooth dragging. On other platforms, GenericDragImage is used. Applications may also prefer to use GenericDragImage on Windows, too.

To use this class, when you wish to start dragging an image, create a wx.DragImage object and store it somewhere you can access it as the drag progresses. Call BeginDrag to start, and EndDrag to stop the drag. To move the image, initially call Show and then Move. If you wish to update the screen contents during the drag (for example, highlight an item as in the dragimag sample), first call Hide, update the screen, call Move, and then call Show.

You can drag within one window, or you can use full-screen dragging either across the whole screen, or just restricted to one area of the screen to save resources. If you want the user to drag between two windows, then you will need to use full-screen dragging.

If you wish to draw the image yourself, use GenericDragImage and override DoDrawImage and GetImageRect.

See also

Drag Image Sample


class_hierarchy Class Hierarchy

Inheritance diagram for class GenericDragImage:

method_summary Methods Summary

__init__

Default constructor.

BeginDrag

Start dragging the image, in a window or full screen.

DoDrawImage

Draws the image on the device context with top-left corner at the given position.

EndDrag

Call this when the drag has finished.

GetImageRect

Returns the rectangle enclosing the image, assuming that the image is drawn with its top-left corner at the given point.

Hide

Hides the image.

Move

Call this to move the image to a new position.

Show

Shows the image.

UpdateBackingFromWindow

Override this if you wish to draw the window contents to the backing bitmap yourself.


api Class API

class wx.GenericDragImage(Object)

Possible constructors:

GenericDragImage()

GenericDragImage(image, cursor=NullCursor)

GenericDragImage(image, cursor=NullCursor)

GenericDragImage(text, cursor=NullCursor)

GenericDragImage(treeCtrl, id)

GenericDragImage(listCtrl, id)

This class is used when you wish to drag an object on the screen, and a simple cursor is not enough.


Methods

__init__(self, *args, **kw)

overload Overloaded Implementations:



__init__ (self)

Default constructor.



__init__ (self, image, cursor=NullCursor)

Constructs a drag image from a bitmap and optional cursor.

Parameters
  • image (wx.Bitmap) – Bitmap to be used as the drag image. The bitmap can have a mask.

  • cursor (wx.Cursor) – Optional cursor to combine with the image.



__init__ (self, image, cursor=NullCursor)

Constructs a drag image from an icon and optional cursor.

Parameters
  • image (wx.Icon) – Icon to be used as the drag image.

  • cursor (wx.Cursor) – Optional cursor to combine with the image.



__init__ (self, text, cursor=NullCursor)

Constructs a drag image from a text string and optional cursor.

Parameters
  • text (string) – Text used to construct a drag image.

  • cursor (wx.Cursor) – Optional cursor to combine with the image.



__init__ (self, treeCtrl, id)

Constructs a drag image from the text in the given tree control item, and optional cursor.

Parameters
  • treeCtrl (wx.TreeCtrl) – Tree control for constructing a tree drag image.

  • id (wx.TreeItemId) – Tree control item id.



__init__ (self, listCtrl, id)

Constructs a drag image from the text in the given list control item, and optional cursor.

Parameters
  • listCtrl (wx.ListCtrl) – List control for constructing a list drag image.

  • id (long) – List control item id.





BeginDrag(self, *args, **kw)

overload Overloaded Implementations:



BeginDrag (self, hotspot, window, fullScreen=False, rect=None)

Start dragging the image, in a window or full screen.

You need to then call Show and Move to show the image on the screen. Call EndDrag when the drag has finished.

Note that this call automatically calls CaptureMouse().

Parameters
  • hotspot (wx.Point) – The location of the drag position relative to the upper-left corner of the image.

  • window (wx.Window) – The window that captures the mouse, and within which the dragging is limited unless fullScreen is True.

  • fullScreen (bool) – If True, specifies that the drag will be visible over the full screen, or over as much of the screen as is specified by rect. Note that the mouse will still be captured in window.

  • rect (wx.Rect) – If not None, specifies the rectangle (in screen coordinates) that bounds the dragging operation. Specifying this can make the operation more efficient by cutting down on the area under consideration, and it can also make a visual difference since the drag is clipped to this area.

Return type

bool



BeginDrag (self, hotspot, window, boundingWindow)

Start dragging the image, using the first window to capture the mouse and the second to specify the bounding area.

This form is equivalent to using the first form, but more convenient than working out the bounding rectangle explicitly.

You need to then call Show and Move to show the image on the screen. Call EndDrag when the drag has finished.

Note that this call automatically calls CaptureMouse().

Parameters
  • hotspot (wx.Point) – The location of the drag position relative to the upper-left corner of the image.

  • window (wx.Window) – The window that captures the mouse, and within which the dragging is limited.

  • boundingWindow (wx.Window) – Specifies the area within which the drag occurs.

Return type

bool





DoDrawImage(self, dc, pos)

Draws the image on the device context with top-left corner at the given position.

This function is only available with GenericDragImage, to allow applications to draw their own image instead of using an actual bitmap. If you override this function, you must also override GetImageRect .

Parameters
Return type

bool



EndDrag(self)

Call this when the drag has finished.

Return type

bool

Note

This function automatically releases mouse capture.



GetImageRect(self, pos)

Returns the rectangle enclosing the image, assuming that the image is drawn with its top-left corner at the given point.

This function is available in GenericDragImage only, and may be overridden (together with DoDrawImage ) to provide a virtual drawing capability.

Parameters

pos (wx.Point) –

Return type

wx.Rect



Hide(self)

Hides the image.

You may wish to call this before updating the window contents (perhaps highlighting an item). Then call Move and Show .

Return type

bool



Move(self, pt)

Call this to move the image to a new position.

The image will only be shown if Show has been called previously (for example at the start of the drag).

Parameters

pt (wx.Point) – The position in client coordinates (relative to the window specified in BeginDrag ).

Return type

bool



Show(self)

Shows the image.

Call this at least once when dragging.

Return type

bool



UpdateBackingFromWindow(self, windowDC, destDC, sourceRect, destRect)

Override this if you wish to draw the window contents to the backing bitmap yourself.

This can be desirable if you wish to avoid flicker by not having to redraw the updated window itself just before dragging, which can cause a flicker just as the drag starts. Instead, paint the drag image’s backing bitmap to show the appropriate graphic minus the objects to be dragged, and leave the window itself to be updated by the drag image. This can provide eerily smooth, flicker-free drag behaviour.

The default implementation copies the window contents to the backing bitmap. A new implementation will normally copy information from another source, such as from its own backing bitmap if it has one, or directly from internal data structures.

This function is available in GenericDragImage only.

Parameters
Return type

bool