The following steps are involved in setting up a drag-and-drop enabled application −
Step 1 − Setting up a source widget.
Step 2 − The drag_source_set() method specifies the target types for a drag operation −
widget.drag_source_set(start_button_mask, targets, info)Step 3 − The start_button_mask argument specifies a bitmask of buttons that starts the drag operation.
Step 4 − The target argument is a list of tuples of this structure −
(target, flags, info)The target argument is a string representing drag type, for example, text/plain or image/x-xpixmap.
Step 6 − The following flags are predefined −
- gtk.TARGET_SAME_APP
- gtk.TARGET_SAME_WIDGET
If the widget is not required to act as source, it can be unset −
widget.drag_source_unset()The source signal emits signals. The following table lists the signals and their callbacks.
| drag_begin | def drag_begin_cb(widget, drag_context, data): |
| drag_data_get | def drag_data_get_cb(widget, drag_context, selection_data, info, time, data): |
| drag_data_delete | def drag_data_delete_cb(widget, drag_context, data): |
| drag_end | def drag_end_cb(widget, drag_context, data): |
Setting up a Destination Widget
The drag_dest_set() method specifies which widget can receive dragged data.widget.drag_dest_set(flags, targets, action)The flags parameter can take one of the following constants −
| gtk.DEST_DEFAULT_MOTION | This checks if the drag matches this widget's list of possible targets and actions, then calls the drag_status() as appropriate. |
| gtk.DEST_DEFAULT_HIGHLIGHT | This draws a highlight on this widget as long as a drag is over this widget |
| gtk.DEST_DEFAULT_DROP | When a drop occurs, if the drag matches this widget's list of possible targets and actions call drag_get_data() on behalf of the widget. Whether or not the drop is successful, call drag_finish(). If the action was a move and the drag was successful, then TRUE will be passed for the delete parameter to drag_finish(). |
| gtk.DEST_DEFAULT_ALL | If set, specifies that all default actions should be taken. |
- gtk.gdk.ACTION_DEFAULT
- gtk.gdk.ACTION_COPY
- gtk.gdk.ACTION_MOVE
- gtk.gdk.ACTION_LINK
- gtk.gdk.ACTION_PRIVATE
- gtk.gdk.ACTION_ASK
The "drag-drop" handler must determine the matching target using the drag_dest_find_target() method and then ask for the drag data using the drag_get_data() method. The data will be available in the "drag-data-received" handler.
No comments:
Post a Comment