[PREV] [NEXT] [PREV Thread] [NEXT Thread] [Index]


lusol@Turkey.CC.Lehigh.EDU (Stephen O. Lidie)
Re: LabEntry

Re: LabEntry

30 Mar 1996 16:06:07 GMT
Newsgroups:
comp.lang.perl.tk
References:
<315BCC5C.A0A78F0@pac.soton.ac.uk>

James_Kingdon (jbk@pac.soton.ac.uk) wrote:
: Silly question time...

: When I was trying to implement a composite widget, the documentation
: lead me to LabEntry as an example. When I looked at the source it
: seemed to be a composite widget containing only an entry widget,
: which was a bit mystifying at the time.

: Now I could actually use a labelled entry widget and was wondering
: whether the provided one is really as defective as it seems.

: Am I missing something?

Yes, you're forgetting just how crafty Nick is (;  Essentially, the
Label is created iff you use -label, either when creating the widget
or in a later configure() call:

# Class LabeledEntry

package Tk::LabEntry;
require Tk::Frame;
@ISA = qw(Tk::Frame);

Tk::Widget->Construct('LabEntry');

sub Populate 
{
 require Tk::Entry;
 # LabeledEntry constructor.
 #
 my($cw, $args) = @_;
 $cw->SUPER::Populate($args);
      ^^^^^^^^^^^^^^^
 # Advertised subwidgets:  entry.
 my $e = $cw->Entry();
 $e->pack('-expand' => 1, '-fill' => 'both');
 $cw->Advertise('entry' => $e );
 $cw->ConfigSpecs(DEFAULT => [$e]);
 $cw->Delegates(DEFAULT => $e);
 $cw->AddScrollbars($e) if (exists $args->{-scrollbars});
} 

1;

Thus -label ConfigSpecs are created in the Populate found
in Frame.pm, the LabEntry widget's superclass:


sub Populate
{
 my ($cw,$args) = @_;
 $cw->ConfigSpecs('-labelPack'     => [ METHOD, undef, undef, undef]);
 $cw->ConfigSpecs('-labelVariable' => [ METHOD, undef, undef, undef]);
 $cw->ConfigSpecs('-label'         => [ METHOD, undef, undef, undef]);
}

These METHOD specifications say "call the method by the same name as
the -option", and if you examine Frame.pm you'll see where the Label
is auto-created.

Moral of the story:  when creating derived or composite widgets always
call SUPER::Populate().

[PREV] [NEXT] [PREV Thread] [NEXT Thread] [Index]