Home > Archive > PerlTk > September 2007 > derived widget: order of ConfigSpecs args?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
derived widget: order of ConfigSpecs args?
|
|
| Jerome Quelin 2007-08-31, 7:53 pm |
| hi,
i'm trying to create a derived widget of Tk::Canvas. it works well - except
that some of the 'PASSIVE' config options aren't taken into account during
creation.
$ cat t.pl
#!/usr/bin/perl
use Tk;
use Tk::RRGauge;
my $mw = Tk::MainWindow->new;
my $c = $mw->RRGauge(
-width => 200,
-height => 30,
)->pack(-expand=>1,-fill=>'both');
MainLoop;
$ cat Tk/RRGauge.pm
package Tk::RRGauge;
use strict;
use warnings;
use Tk;
use Tk::widgets qw/ Canvas /;
use base qw/ Tk::Derived Tk::Canvas /;
Construct Tk::Widget 'RRGauge';
sub Populate {
my( $self, $args ) = @_;
$self->SUPER::Populate( $args );
$self->ConfigSpecs(
-from => [ 'PASSIVE', undef, undef, 0 ],
-visible => [ 'PASSIVE', undef, undef, 20 ],
-to => [ 'PASSIVE', undef, undef, 100 ],
-value => [ 'METHOD', undef, undef, 50 ],
);
}
sub value {
my ($self, $value) = @_;
my $w = $self->cget('-width');
my $h = $self->cget('-height');
my $v = $self->cget('-visible');
my $f = $self->cget('-from');
my $t = $self->cget('-to');
warn "$value ($f - $t / $v)\n";
}
1;
but when i run t.pl, i get the mainwindow and the derived canvas... but in
the 'value' method called during creation, $t and $v are not set.
but if i later call $c->value with an argument, then everything is set...
==> maybe the order of ConfigSpecs as Tk uses it is not the one that i
want... but changing the order of the array, as well as trying to call
multiple times ConfigSpecs (instead of one with multiple options) does not
change the result.
can you help me finding the problem / a solution?
thx,
jérôme
--
jquelin@gmail.com
| |
| Ch Lamprecht 2007-09-01, 8:42 am |
| Jerome Quelin wrote:
> hi,
>
> i'm trying to create a derived widget of Tk::Canvas. it works well - except
> that some of the 'PASSIVE' config options aren't taken into account during
> creation.
>
>
> $ cat t.pl
> #!/usr/bin/perl
> use Tk;
> use Tk::RRGauge;
> my $mw = Tk::MainWindow->new;
> my $c = $mw->RRGauge(
> -width => 200,
> -height => 30,
> )->pack(-expand=>1,-fill=>'both');
> MainLoop;
>
> $ cat Tk/RRGauge.pm
> package Tk::RRGauge;
> use strict;
> use warnings;
> use Tk;
> use Tk::widgets qw/ Canvas /;
> use base qw/ Tk::Derived Tk::Canvas /;
> Construct Tk::Widget 'RRGauge';
> sub Populate {
> my( $self, $args ) = @_;
>
> $self->SUPER::Populate( $args );
> $self->ConfigSpecs(
> -from => [ 'PASSIVE', undef, undef, 0 ],
> -visible => [ 'PASSIVE', undef, undef, 20 ],
> -to => [ 'PASSIVE', undef, undef, 100 ],
> -value => [ 'METHOD', undef, undef, 50 ],
> );
> }
> sub value {
> my ($self, $value) = @_;
> my $w = $self->cget('-width');
> my $h = $self->cget('-height');
> my $v = $self->cget('-visible');
> my $f = $self->cget('-from');
> my $t = $self->cget('-to');
> warn "$value ($f - $t / $v)\n";
> }
> 1;
>
> but when i run t.pl, i get the mainwindow and the derived canvas... but in
> the 'value' method called during creation, $t and $v are not set.
>
>
> but if i later call $c->value with an argument, then everything is set...
>
> ==> maybe the order of ConfigSpecs as Tk uses it is not the one that i
> want... but changing the order of the array, as well as trying to call
> multiple times ConfigSpecs (instead of one with multiple options) does not
> change the result.
>
> can you help me finding the problem / a solution?
>
>
> thx,
> jérôme
sub Populate {
my( $self, $args ) = @_;
$self->SUPER::Populate( $args );
$self->ConfigSpecs(
-from => [ 'PASSIVE', undef, undef, 0 ],
-visible => [ 'PASSIVE', undef, undef, 20 ],
-to => [ 'PASSIVE', undef, undef, 100 ],
-value => [ 'METHOD', undef, undef, undef ],
);
my $val = exists $args->{-value} ? delete $args->{-value} : 50 ;
$self -> afterIdle(sub{$self->configure(-value => $val)});
}
HTH, Christoph
--
use Tk;use Tk::GraphItems;$c=tkinit->Canvas->pack;push@i,Tk::GraphItems->
TextBox(text=>$_,canvas=>$c,x=>$x+=70,y=>100)for(Just=>another=>Perl=>Hacker);
Tk::GraphItems->Connector(source=>$i[$_],target=>$i[$_+1])for(0..2);
$c->repeat(30,sub{$_->move(0,4*cos($d+=3.16))for(@i)});MainLoop
| |
| Jerome Quelin 2007-09-02, 4:05 am |
| Ch Lamprecht wrote:
> sub Populate {
> my( $self, $args ) = @_;
>
> $self->SUPER::Populate( $args );
> $self->ConfigSpecs(
> -from => [ 'PASSIVE', undef, undef, 0 ],
> -visible => [ 'PASSIVE', undef, undef, 20 ],
> -to => [ 'PASSIVE', undef, undef, 100 ],
> -value => [ 'METHOD', undef, undef, undef ],
> );
> my $val = exists $args->{-value} ? delete $args->{-value} : 50 ;
> $self -> afterIdle(sub{$self->configure(-value => $val)});
> }
of course, it seems logical.
thks a lot,
jérôme
--
jquelin@gmail.com
|
|
|
|
|