I have been able to get drag and drop working from a Gtk.ToolPalette, but only when setting Gtk.ToolButton.set_use_drag_window(True)
. However when clicking on a ToolButton to drag and drop it, it does not result in the button actually being visually clicked. I understand this is because set_use_drag_window
causes all events (even button clicks) to be intercepted as a drag event.
The docs say that the easiest way to use drag and drop with Gtk.ToolPalette is to call Gtk.ToolPalette.add_drag_dest()
with the desired drag source palette and the desired drag target widget. This is kind of the opposite of what I need based on the complexity of the GUI app, since I need to setup the ToolPalette and then add a callback to the drag source after the DrawingArea is created.
I have inherited from the Gtk.TooPalette
, created a Gtk.ToolItemGroup
for each section of the palette, and then I am creating the buttons:
def toolbox_button(self, action_name, stock_id):
button = Gtk.ToolButton.new_from_stock(stock_id)
button.action_name = action_name
button.set_use_drag_window(True)
# Enable Drag and Drop
button.drag_source_set(
Gdk.ModifierType.BUTTON1_MASK,
self.DND_TARGETS,
Gdk.DragAction.COPY | Gdk.DragAction.LINK,
)
button.drag_source_set_icon_stock(stock_id)
button.connect("drag-data-get", self._button_drag_data_get)
return button
On the DrawingArea I am then making it a drag dest:
view.drag_dest_set(
Gtk.DestDefaults.MOTION,
DiagramPage.VIEW_DND_TARGETS,
Gdk.DragAction.MOVE | Gdk.DragAction.COPY | Gdk.DragAction.LINK,
)
Is there a way to get drag and drop to work with the ToolPalette while still allowing the buttons to work normally?