Gtk3 and drag'n'drop

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Gtk3 and drag'n'drop

Jeff
I've almost got drag'n'drop working in Gtk3, but I'm just missing the
final piece:

To finish a drag in Gtk2, you call finish() on the context, typically like:

 $context->finish(1, $delete, time);

If I do this in Gtk3, I get:

*** unhandled exception in callback:
***   Can't locate object method "finish" via package
"Glib::Object::_Unregistered::GdkX11DragContext" at ../gtk3_iconview.pl
line 251.
***  ignoring at /usr/share/perl5/Gtk3.pm line 546.

I can't find any docs or examples for dnd and Gtk3 in Perl, but the C
docs describes finish:

https://developer.gnome.org/gtk3/stable/gtk3-Drag-and-Drop.html#gtk-drag-finish

This python example doesn't finish the drag:

https://python-gtk-3-tutorial.readthedocs.io/en/latest/drag_and_drop.html

So - what is the Perl equivalent of gtk_drag_finish()?

Regards

Jeff

P.S. For those interested, I got most of the way through transcribing
the drag and drop tutorial here:

http://gtk2-perl.sourceforge.net/doc/gtk2-perl-study-guide/c5651.html

and have attached the results (which show the above problem).

_______________________________________________
gtk-perl-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-perl-list

gtk3_iconview.pl (9K) Download Attachment
signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Gtk3 and drag'n'drop

Emmanuele Bassi
On 24 February 2018 at 12:10, Jeff <[hidden email]> wrote:

> I've almost got drag'n'drop working in Gtk3, but I'm just missing the
> final piece:
>
> To finish a drag in Gtk2, you call finish() on the context, typically like:
>
>  $context->finish(1, $delete, time);
>
> If I do this in Gtk3, I get:
>
> *** unhandled exception in callback:
> ***   Can't locate object method "finish" via package
> "Glib::Object::_Unregistered::GdkX11DragContext" at ../gtk3_iconview.pl
> line 251.
> ***  ignoring at /usr/share/perl5/Gtk3.pm line 546.
>
> I can't find any docs or examples for dnd and Gtk3 in Perl, but the C
> docs describes finish:
>
> https://developer.gnome.org/gtk3/stable/gtk3-Drag-and-Drop.html#gtk-drag-finish
>
> This python example doesn't finish the drag:
>
> https://python-gtk-3-tutorial.readthedocs.io/en/latest/drag_and_drop.html
>
> So - what is the Perl equivalent of gtk_drag_finish()?

The issue is that the GTK drag and drop API lives in the GTK
namespace, but operates on a GdkDragContext object under the GDK
namespace. This is not allowed with introspection-based bindings,
because the method cannot be reconciled with the object.

Of course, this is perfectly valid at the C level, because there are
only functions. Which means that the gtk_drag_* API has to be treated
as functions, e.g.:

  Gtk3::drag_finish($context, $delete, time);

The old Gtk2 bindings would "cheat", and move the API under the
GdkDragContext namespace, hence the change.

Ciao,
 Emmanuele.
_______________________________________________
gtk-perl-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|

Re: Gtk3 and drag'n'drop

Jeff
On 24/02/18 13:16, Emmanuele Bassi wrote:

> The issue is that the GTK drag and drop API lives in the GTK
> namespace, but operates on a GdkDragContext object under the GDK
> namespace. This is not allowed with introspection-based bindings,
> because the method cannot be reconciled with the object.
>
> Of course, this is perfectly valid at the C level, because there are
> only functions. Which means that the gtk_drag_* API has to be treated
> as functions, e.g.:
>
>   Gtk3::drag_finish($context, $delete, time);
>
> The old Gtk2 bindings would "cheat", and move the API under the
> GdkDragContext namespace, hence the change.
Thanks for this. That seems to work. Now I am looking for the Gtk3
equivalent of $context->get_targets as per:

    $self->signal_connect(
        drag_drop => sub {
            my ( $tree, $context, $x, $y, $when ) = @_;
            if ( my $targ = $context->get_targets ) {
                $tree->drag_get_data( $context, $targ, $when );
                return TRUE;
            }
            return FALSE;
        }
    );

I've tried variations on Gtk3::drag_dest_get_target_list() but I can't
find the right one.

Any ideas?

Regards

Jeff


_______________________________________________
gtk-perl-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-perl-list

signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Gtk3 and drag'n'drop

Jeff
On 24/02/18 13:30, Jeff wrote:
> Thanks for this. That seems to work. Now I am looking for the Gtk3
> equivalent of $context->get_targets as per:

This seems at least to run:

    # Callback for dropped signal.
    $self->signal_connect(
        drag_drop => sub {
            my ( $tree, $context, $x, $y, $when ) = @_;
            my $targets = $tree->drag_dest_get_target_list;
            if ( my $target = $tree->drag_dest_find_target($context,
$targets)){
                $tree->drag_get_data( $context, $target, $when );
                return TRUE;
            }
            return FALSE;
        }
    );

Still not quite there, though.

Regards

Jeff


_______________________________________________
gtk-perl-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-perl-list

signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Gtk3 and drag'n'drop

oldtechaa
For documentation for Gtk3 in Perl, you can use the "perli11ndoc" tool included with Glib::Object::Introspection. If you're using Debian or a derived distro, you'll need to install libxml-libxml-perl and libgtk-3-dev also, but the docs for drag look like they're in there. I see drag_finish() and GestureDrag. This might help.

oldtechaa


_______________________________________________
gtk-perl-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|

Re: Gtk3 and drag'n'drop

Jeff
On 24/02/18 20:10, oldtechaa wrote:
> For documentation for Gtk3 in Perl, you can use the "perli11ndoc" tool
> included with Glib::Object::Introspection. If you're using Debian or a
> derived distro, you'll need to install libxml-libxml-perl and
> libgtk-3-dev also, but the docs for drag look like they're in there. I
> see drag_finish() and GestureDrag. This might help.

That's a really good tip. Thanks.

It could do with a search function.

Regards

Jeff


_______________________________________________
gtk-perl-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-perl-list

signature.asc (849 bytes) Download Attachment