widget subclassing problem



Hello
 
After reading the subclassing how-to i'm trying to get rid of my @isa inheritance.
So i'm trying to make a widget that contains an entry and label.
It looks basically like this:
 
-----------------------------------------------
package LabelEntry;
use Glib qw(TRUE FALSE);
use Gtk2;
 
use strict;
use warnings;
 
use Glib::Object::Subclass
    Gtk2::VBox::,
    signals => {
 # currently no signals defined
       },
    properties => [
          Glib::ParamSpec->string (
       'my_text', # name
       'my_text', # nickname
       'The text shown above the entry', #blurb
       "Default entry text", # default
       [qw/readable writable/] #flags
       ),
     ]
    ;

sub INIT_INSTANCE {
    my $self = shift;
 
    print "label_text = ". $my_text. "\n";
 
    my $label = Gtk2::Label->new ( $self{my_text} );
    $label->set_alignment (0.0, 0.5); # set left horizontal alignment and middle vertical alignment
 
#    $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);
    $self->show();
    $self->{label} = $label;
    $self->{entry} = $entry;
}
-----------------------------------------------------------------------
When i create a new instance of this widget with:
 
    my $labelentry = LabelEntry->new(my_text => "label text");
 
it basically works, but i only can see the entry. I can't see the label.
 
 
So i inserted the   
    print "label_text = ". $my_text. "\n";
line to see the content of  "my_text".
 
When i run the program again i get the message:
 
    "Use of uninitialized value in concatenation (.) or string at widgets/LabelEntry.pm line 41."
 
Can anybody see what i'm making wrong when accessing (reading writing) the property "my_text"?
Even if i don't set it there should be a default value. Or am i wrong here.
 
 
Thanks in advance !
 
 
Regards
Josef


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