Re: Subclassing a Gtk2::TreeStore



Thanks Torsten and Scott. I've looked at it some more and I suspect I
have two separate problems in addition to my initial lack of
understanding :(

Torsten Schoenfeld wrote:
I haven't tested it in a complete application, but this seems to work:

  package MyTreeStore;

  use Glib qw(TRUE FALSE);
  use Gtk2;

  use Glib::Object::Subclass
    'Gtk2::TreeStore',
  ;

  sub drag_data_received
  {
      my ($self, $dest_path, $selection_data) = @_;
      return $self->SUPER::drag_data_received ($dest_path, $selection_data);
  }

  1;

  package main;

  my $store = MyTreeStore->new (qw/Glib::String/);
  $store->drag_data_received (undef, undef);

Note how drag_data_received is overridden simply how you'd override any
other method in normal Perl code, and how the parent's
drag_data_received is invoked.

That code compiles and starts to run for me too. Unfortunately, it's too
simple in two ways.


Firstly, my tree has more than one column and as soon as I change the
call to MyTreeStore->new to have more than one column, I get the error
again e.g.:

  my $tree_store   = MyTreeStore->new(qw/Glib::String Glib::Int/);

  type MyTreeStore does not support property 'Glib::String'

At least I now know that the error is caused by multiple args. Any idea
on how to make the constructor work for trees with multiple columns?
I'll keep experimenting.


Secondly, and potentially more serious, is related to Scott's comments:

muppet wrote:
To be a little more explicit, this works because where you need it to
be overridden is in your own code, where perl's method lookup can
work normally.

I don't think my code is where I need it to be overridden. I don't have
any plans to call drag_data_received. It's called automatically by gtk+
as part of the treeview drag'n'drop mechanism. What I do want to do is
influence what it does. From what you say, I suspect I can't to this.

So before I waste more of everybody's time chasing something that's not
possible, I'd better explain the big picture and you can hopefully
suggest a better way to achieve my goal.

My application is a tree editor. All the branches are the same height
and nodes are typed according to their height (family, species etc).
Only rearrangements that keep nodes at the same height should be
permitted - you can't turn a species into a family, for example.

The treeview drag'n'drop does pretty much everything I need. In my
current code, I just call enable_model_drag_source and
enable_model_drag_dest and gtk+ does the rest. But that allows a node to
be dropped anywhere, so I need to find a hook somewhere that allows me
to either prevent the node being dropped or force the drop destination
to be the nearest node of the correct type. I favoured the latter
option, given the well-known pixel sensitivity of the interface, and
that's why I'm trying to override drag_data_received. But any other
solutions are more than welcome.


Trying to override drag_data_received as a signal won't work, because
it's not a signal.

Yes, that's why I was very surprised to see the suggestion in the
section 'OVERRIDING BASE METHODS' on the page
<http://gtk2-perl.sourceforge.net/doc/pod/Glib/Object/Subclass.html>. I
think it could use rewording but I'm not sure exactly what it's trying
to say. Is the section wrongly titled? Should it be something like
'OVERRIDING SIGNAL IMPLEMENTATIONS IN BASE CLASSES'?

Cheers, Dave



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]