Re: How to implement custom interfaces in derived TreeModelSort ?
On 30.05.20 22:17, Gaëtan Frenoy wrote: I was doing: my $model_sort = MyTreeModelSort->new_with_model($model); while you created your own constructor ! After I changed the above line with: my $model_sort = MyTreeModelSort->new(model => $model); all suddenly worked as expected... (see attached for the complete code) They key difference is that the latter ends up in Glib::Object::new, which is responsible for setting up the magic that associates the underlying object with your class on the Perl and C level. If you call new_with_model, this won't happen. Also, simply reblessing in Perl is not sufficient either, because that doesn't do the C side of the association. -Torsten ___ gtk-perl-list mailing list [email protected] https://mail.gnome.org/mailman/listinfo/gtk-perl-list
Re: How to implement custom interfaces in derived TreeModelSort ?
Hi Torsten, > Maybe you forgot to call > enable_model_drag_source or enable_model_drag_dest? No, I was doing that [1]. > The following code, > adapting from an old thread on this list*, works for me: Thanks for this working example ! I was able to spot the difference with mine: how you create the "sorted model". I was doing: my $model_sort = MyTreeModelSort->new_with_model($model); while you created your own constructor ! After I changed the above line with: my $model_sort = MyTreeModelSort->new(model => $model); all suddenly worked as expected... (see attached for the complete code) Both lines are supposed to do the same, aren't they ? If I read Gtk3.pm correctly, "new_with_model" is calling "sort_new_with_model" in "TreeModel" ; is this still correct ? In any case, thanks a lot for your answer and your so valuable help ! Wish you a wonderful night. Gaëtan [1] See code attached to https://mail.gnome.org/archives/gtk-perl-list/2020-May/msg7.html test-dnd3.pl Description: Perl program ___ gtk-perl-list mailing list [email protected] https://mail.gnome.org/mailman/listinfo/gtk-perl-list
Re: How to implement custom interfaces in derived TreeModelSort ?
On 29.05.20 12:16, Gaëtan Frenoy wrote:
Inspired by what is described in Glib::Object::Subclass[1], I tried the
following:
---
package MyTreeModelSort;
use strict;
use Gtk3 -init;
use Glib::Object::Subclass
'Gtk3::TreeModelSort',
interfaces => [ 'Gtk3::TreeDragDest' ];
sub DRAG_DATA_RECEIVED {
my ($dest_path, $selection_data) = @_;
print("drag data received : $dest_path ; $selection_data ;\n");
return 1;
}
sub ROW_DROP_POSSIBLE {
my ($dest_path, $selection_data) = @_;
print("row drop possible : $dest_path ; $selection_data ;\n");
return 1;
}
---
But my custom methods are never called so there's something I do not do
right ; for sure. Any tip or suggestion will be warmly welcome.
Yes, that's the right approach. Maybe you forgot to call
enable_model_drag_source or enable_model_drag_dest? The following code,
adapting from an old thread on this list*, works for me:
---
#!/usr/bin/perl
use strict;
use warnings;
use Gtk3 -init;
my $window = Gtk3::Window->new('toplevel');
{
package MyTreeModelSort;
use Glib::Object::Subclass
Gtk3::TreeModelSort::,
interfaces => [ Gtk3::TreeDragDest:: ],
;
sub new
{
my ($proto, $childModel) = @_;
my $class = ref($proto) || $proto;
return Glib::Object::new($class, model => $childModel);
}
sub DRAG_DATA_RECEIVED
{
print "DRAG_DATA_RECEIVED\n";
}
sub ROW_DROP_POSSIBLE
{
print "ROW_DROP_POSSIBLE\n";
}
}
my $model = Gtk3::TreeStore->new('Glib::String');
my $sorter = MyTreeModelSort->new($model);
my $list = Gtk3::TreeView->new_with_model($sorter);
my $column = Gtk3::TreeViewColumn->new_with_attributes(
'Title', Gtk3::CellRendererText->new, 'text' => 0);
$list->append_column($column);
foreach ('a'..'z')
{
my $iter = $model->append(undef);
$model->set($iter, 0 => 'line'.$_);
}
my $targets = [Gtk3::TargetEntry->new('GTK_TREE_MODEL_ROW',
['same-widget'], 0)];
$list->enable_model_drag_source('button1-mask', $targets, 'move');
$list->enable_model_drag_dest($targets, 'move');
$window->add($list);
$window->signal_connect(destroy => sub { Gtk3->main_quit; });
$window->show_all;
Gtk3->main;
---
-Torsten
*
___
gtk-perl-list mailing list
[email protected]
https://mail.gnome.org/mailman/listinfo/gtk-perl-list
