Re: widget subclassing problem



On Thu, 26 Jan 2006 12:45:02 -0500 (EST)
"muppet" <scott asofyet org> wrote:

Two problems here:  first, $my_text is not defined (i presume you have a
global in your copy), and second, the properties have not yet been set in
INIT_INSTANCE.  Instantiation is basically a sequence of INSTANCE_INIT and a
bunch of SET_PROPERTYs.  You'll have to create the Label with no string, and
then provide a property setter or SET_PROPERTY that puts the text into the
label with set_text().

I know this is a hack, but what do you think of just building the widgets in
the SET_PROPERTY, once the options are known?

sub INIT_INSTANCE {
    my $self = shift;
}

sub SET_PROPERTY {
    my ($self, $pspec, $val) = @_;
#    print Dumper([ _]),"\n"; 
    print "$self\n";
    print  $pspec->get_name,"\n";
    print "$val\n";

    if ($pspec->get_name eq 'my_text') {
        $self->{my_text} = $val;
     }

    my $label = Gtk2::Label->new ( $self->{my_text} );
    $label->set_alignment (0.0, 0.5); # set left horizontal alignment and middle
    $label->set_text ( $self->{my_text} );
    my $entry = Gtk2::Entry->new();
    $self->pack_start($label, FALSE, FALSE, 2);
    $self->pack_start($entry, FALSE, FALSE, 2);
    $label->show();
    $enrty->show();
    $self->{label} = $label;
    $self->{entry} = $entry;
}


-- 
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html



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