I want the source to be the destination too. I implemented the signals below but the drag-data-get signal fires twice. The second time the data variable(in on_drag_data_get) is being populated with the autoselected ListStore item.
class DragSource(Gtk.TreeView):
def __init__(self):
Gtk.TreeView.__init__(self)
model = Gtk.ListStore(str)
self.set_model(model)
self.add_item("Item 1")
self.add_item("Item 2")
self.add_item("Item 3")
renderer = Gtk.CellRendererText()
column = Gtk.TreeViewColumn("Backlog", renderer, text=0)
self.append_column(column)
self.enable_model_drag_source(
Gdk.ModifierType.BUTTON1_MASK, [], DRAG_ACTION)
self.drag_dest_set(Gtk.DestDefaults.ALL, [], DRAG_ACTION)
self.connect("drag-data-get", self.on_drag_data_get)
self.connect("drag-data-received", self.on_drag_data_received)
def on_drag_data_get(self, widget, drag_context, data, info, time):
print("fired")
model, iter = self.get_selection().get_selected()
text = model.get_value(iter, 0)
data.set_text(text, -1)
def on_drag_data_received(self, widget, drag_context, x, y, data, info, time):
text = data.get_text()
self.add_item(text)
print("Received text: %s" % text)
def add_item(self, text):
self.get_model().append([text])