- PyGTK - Drag and Drop
- PyGTK - Timeout
- PyGTK - Ruler Class
- PyGTK - Clipboard Class
- PyGTK - Calendar Class
- PyGTK - SpinButton Class
- PyGTK - DrawingArea Class
- PyGTK - Image Class
- PyGTK - Arrow Class
- PyGTK - Scrolledwindow Class
- PyGTK - Viewport Class
- PyGTK - ProgressBar Class
- PyGTK - Statusbar Class
- PyGTK - Paned Class
- PyGTK - TreeView Class
- PyGTK - AspectFrame Class
- PyGTK - Frame Class
- PyGTK - Notebook Class
- PyGTK - File Chooser Dialog
- PyGTK - Color Selection Dialog
- PyGTK - Font Selection Dialog
- PyGTK - AboutDialog Class
- PyGTK - MessageDialog Class
- PyGTK - Dialog Class
- PyGTK - Scrollbar Class
- PyGTK - Scale Class
- PyGTK - Range Class
- PyGTK - Adjustment Class
- PyGTK - Toolbar Class
- PyGTK - MenuBar, Menu & MenuItem
- PyGTK - RadioButton Class
- PyGTK - CheckButton Class
- PyGTK - ToggleButton Class
- PyGTK - ComboBox Class
- PyGTK - Layout Class
- PyGTK - EventBox Class
- PyGTK - Alignment Class
- PyGTK - ButtonBox Class
- PyGTK - Box Class
- PyGTK - Containers
- PyGTK - Event Handling
- PyGTK - Signal Handling
- PyGTK - Entry Class
- PyGTK - Label CLass
- PyGTK - Button Class
- PyGTK - Window Class
- PyGTK - Important Classes
- PyGTK - Hello World
- PyGTK - Environment
- PyGTK - Introduction
- PyGTK - Home
PyGTK Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
PyGTK - Drag and Drop
Widgets having associated X Window are capable of drag and drop. In the program, a widget as a source and/or destination for drag-and-drop must first be designated. The widget defined as source can send out the dragged data. The destination widget accepts it when dragged data is dropped on it.
The following steps are involved in setting up a drag-and-drop enabled apppcation −
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 pst 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
Step 7 − There will be no pmitation as the flag is set to 0.
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 psts 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 pst of possible targets and actions, then calls the drag_status() as appropriate. |
gtk.DEST_DEFAULT_HIGHLIGHT | This draws a highpght 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 pst 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. |
The target is a pst of tuples containing target information. The actions argument is a bitmask of or a combination of one or more of the following values −
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-motion" handler must determine if the drag data is appropriate by matching the destination targets with the gtk.gdk.DragContext targets and optionally by examining the drag data by calpng the drag_get_data() method. The gtk.gdk.DragContext. drag_status() method must be called to update the drag_context status.
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.
Advertisements