On Wed, 7 Apr 2010 10:44:08 +0200 Jeffrey Ratcliffe <jeffrey ratcliffe gmail com> wrote:
Please keep the group in the loop. 2010/4/7 Xi Yang <jiandingzhe msn com>:package My::Class; our @isa = qw/Gnome2::Canvas::Group/; sub myMethod {} # is that available to use GObject as hash ref directly? # as I would store something in object sub myDataAccessor { my ($self,$value) = @_; $self->{myKey} = $value; }I've never used Gnome::Canvas. Perhaps someone else can answer.
Hi, I used to dabble in that, so here are examples of what Emannule Bassi was saying. Below are old mails discussing this, and attached is a working example ########################################################## 1. Subclassing Gnome2::Canvas (James Muir) 2. Re: Subclassing Gnome2::Canvas (muppet) I am able to subclass the aliased canvas and instantiate it while passing a parameter, but I cannot do the same with the anti-aliased canvas :-( . I would have expected to be able to do this with both canvases. Is this a bug or, as usual, am I missing something? Here's a simple example: package can; use strict; use Gtk2; use Gnome2::Canvas; use Glib::Object::Subclass Gnome2::Canvas::, properties => [ Glib::ParamSpec->scalar('melon', 'melon', 'pass in a melon', 'writable'), ] ; sub INIT_INSTANCE { my $self = shift(@_); print "INIT_INSTANCE\n"; } package main; use strict; use Gtk2 '-init'; use Gnome2::Canvas; my $window = Gtk2::Window->new(); my $scroller = Gtk2::ScrolledWindow->new(); my $canvas = can->new_aa(melon=>'x'); # my $canvas = can->new(melon=>'x'); $scroller->add($canvas); $window->add($scroller); my $root = $canvas->root(); my $ellipse = Gnome2::Canvas::Item->new($root,'Gnome2::Canvas::Ellipse',x1=>10,y1=>10,x2=>40,y2=>40,fill_color=>'red'); $window->signal_connect('destroy'=>sub { Gtk2->main_quit(); } ); $window->show_all(); Gtk2->main(); 1; Thanks for your help. -James ------------------------------ Message: 2 Date: Tue, 8 Nov 2005 14:11:54 -0500 (EST) From: "muppet" <scott asofyet org> Subject: Re: Subclassing Gnome2::Canvas To: gtk-perl-list gnome org Message-ID: <58099 192 146 101 26 1131477114 squirrel webmail asofyet org> Content-Type: text/plain;charset=iso-8859-1 James Muir said:
I am able to subclass the aliased canvas and instantiate it while passing a parameter, but I cannot do the same with the anti-aliased canvas :-( . I would have expected to be able to do this with both canvases. Is this a bug or, as usual, am I missing something?
You're missing something. :-)
Here's a simple example:
...
my $canvas = can->new_aa(melon=>'x'); # my $canvas = can->new(melon=>'x');
You have two different things going on here. Glib::Object::Subclass aliases yourpackage::new() to Glib::Object::new(), so the second, commented line actually resolves to Glib::Object::new ('can', 'melon', 'x'); On the other hand, nothing special happens with new_aa(), so that is inherited normally, and evaluates to this: Gnome2::Canvas::new_aa ('can', 'melon', 'x'); However, GNome2::Canvas::new_aa() is an xsub which binds to a non-virtual class-static method, which takes only one parameter -- the ignored class. Even if you take off the extra parameters and just call it as 'can->new_aa()', it will create a 'Gnome2::Canvas', not a 'can', because it is hardcoded to do so. In other words, This Is Not How You Do It. Either: a) create your own new_aa() method in your custom package and set it up correctly, or b) use the 'aa' property to set up your object, like this: $canvas = can->new (aa => TRUE, melon => 'x'); Hint: if you choose a), it will be implemented as b). -- muppet <scott at asofyet dot org>
Attachment:
canvas-object
Description: Binary data