Problems with drag and drop when moving from Gtk2 to Gtk3

I had an application that worked with pygtk, I’m trying to convert it to gtk3, but I’m having problems with drag and drop.
In the old version, I had:

TARGET_TYPE_PERSONA = 120
toPersona = [("datos/persona", 0, TARGET_TYPE_PERSONA)] 
...
a = Persona()
a.connect("drag_data_get", self.lanzardrag)
...
def lanzardrag(self, widget, drag_context, data, info, time):
        if info == TARGET_TYPE_PERSONA:
            ...
            data.set(data.target, 8, cad)
            ...

Now, with GTK3, I try:

TARGET_TYPE_PERSONA = 120
toPersona = [Gtk.TargetEntry.new("datos/persona", 0, TARGET_TYPE_PERSONA)] 
...
def lanzardrag(self, widget, drag_context, data, info, time):
            if info == TARGET_TYPE_PERSONA:
                ...
                data.set(data.get_target(), 8, cad)
                ...

But in this last line gives an error: TypeError: Item 0: Must be number, not str

the out of print(data.get_target()) is “datos/persona” (I don’t know if is a bug).

The gtk_selection_data_set() function takes a GdkAtom for the target. The old pygtk bindings automatically attempted to turn any Python objects into a GdkAtom, but the pygobject generic bindings don’t do that any more.

This should work—and it generally does, in other GTK3 applications written in Python. I suspect that you’re experiencing an issue located somewhere else, but there’s not enough context for an answer.

This is not a bug: Gtk.SelectionData.get_target() returns a Gdk.Atom, and Gdk.Atom has an override that implements the __str__ slot; print(atom) is the equivalent of print(str(atom)).

Can you give me any example with gtk_selection_data_set() (for custom widget)?
The python GTK tutorial (ch 21) have one example but it use set_text() and set_pixbuf()

Thanks in advance

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.