Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

TK Mega Widget and User Edit

by PerlingTheUK (Hermit)
on Jun 29, 2005 at 21:36 UTC ( [id://471177]=perlquestion: print w/replies, xml ) Need Help??

PerlingTheUK has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

I am curretly developing a Mega-Widget that gets some additional configuration parameter. (Files from which data is parsed). The user can defined some lists of data he wants to edit with this data. When the user finished editing the data, He can click "Ok" and another routine is supposed to manipulate the data based on the user input.

To call the function for this processing outside the dialog, I need to get the settings out. However I am not sure which is the right way. I describe a couple of ways that came to mind and would like to get your comments.

The parameter way

This would be something like:
sub Populate{ ... $self->ConfigSpecs( -infile => [ qw/METHOD infile INFILE]); $self->{ _configX } = []; ... }
The Data would be accesst as:
process( $dlg->{ _configX } );
This way seems to be a bit cumbersome to me.

The PASSIVE Way

This would be something like:
sub Populate{ ... $self->ConfigSpecs( -infile => [ qw/METHOD infile INFILE], -configx => [ qw/PASSIVE configx CONFIGX] ); ... }
The Data would be accesst as:
$config = []; $dlg->configure( -configx => $config ); process( $dlg->cget( "-configx" ) );
This is slightly more "Tk"-Like to me but it fails if the user does not pass a -configx argument.

The METHOD Way

This would be something like:
sub Populate{ ... $self->ConfigSpecs( -infile => [ qw/METHOD infile INFILE], -configx => [ qw/METHOD configx CONFIGX] ); $self->{ _configX } = []; ... } sub configx { # get configX on configure; # return configX on cget; }
The Data would be accesst as:
$config = []; $dlg->configure( -configx => $config ); process( $dlg->cget( "-configx" ) );
This overcomes the problem of setting the variable, but the user never ever really needs to set configX it just comes out it should always start being empty. I am really looking for a way to get data out of a dialog but not at any point in there.

I appreciate all comments on the above listings. People that point me to good widgets I could use as a read for now or other suggestions.


Cheers,
PerlingTheUK

Replies are listed 'Best First'.
Re: TK Mega Widget and User Edit
by zentara (Archbishop) on Jun 30, 2005 at 12:14 UTC
    Here is a snippet I use as an example, posted long ago by some Tk programmer better than me at mega-widgets :-) I also would look at the pod for Tk::Derived for insight into mega-widgets and passing params. The big problem is how to get around the super widget rejecting params it dosn't handle. And check out Custom Widgets by Steven Lidie
    #!/usr/bin/perl use warnings; use strict; package Tk::MyMega; use base qw/Tk::Frame/; use strict; Construct Tk::Widget 'MyMega'; sub Populate { my($self, $args) = @_; $self->SUPER::Populate($args); $self->{entry1} = $self->Entry->pack; $self->{entry2} = $self->Entry->pack; $self->ConfigSpecs( -variable1 => [qw/PASSIVE variable1 Variable1/, undef ], -variable2 => [qw/PASSIVE variable2 Variable2/, undef ], ); } # end Populate # an alternative #sub Populate { # my($self, $args) = @_; # # $self->SUPER::Populate($args); # # my $e1 = $self->Component(Entry => 'entry1')->pack; # my $e2 = $self->Component(Entry => 'entry2')->pack; # # $self->ConfigSpecs( # -variable1 => [{-textvariable => $e1}, qw/variable1 Variable1/], # -variable2 => [{-textvariable => $e2}, qw/variable2 Variable2/] #); #} sub ConfigChanged { my( $self, $args ) = @_; foreach my $k (keys %$args) { if( my( $n ) = $k =~ /^-variable(\d+)$/ ) { $self->{"entry${n}"}->configure( -textvariable => $args->{$k} ); } } } # end ConfigChanged package main; use Tk; #use Tk::MyMega; use strict; my $mw = MainWindow->new; my $frog = 1; my $toad = 2; my $mm = $mw->MyMega( -background => 'white', -foreground => 'blue', -variable1 => \$frog, -variable2 => \$toad, )->pack; $mw->update; $mw->after( 2000, sub{ $frog++; $toad++ } ); MainLoop;

    I'm not really a human, but I play one on earth. flash japh

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://471177]
Approved by Tanktalus
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-19 14:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found