For Programmers: Free Programming Magazines  


Home > Archive > PerlTk > March 2007 > Communication between widgets









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 Communication between widgets
linqon@gmail.com

2007-03-01, 4:09 am

Hi

I'm developing a Perl Tk application and have some rather basic
questions regarding communication and handling of parameters between
two widgets.

Here's what I have:

I have one script (lets call it "TheScript.pl") that starts up the
application. It creates a MainWindow. It creates two Toplevel widgets,
each one of these consists of my own composite widgets. Basically all
the script consists of are input parameter handling, Tk-creation and
MainLoop.

The first one ("CfgWindow", inherits from Tk::Frame) asks the user to
enter some parameters. These parameters will then be used in the
second one.

Widget #2, ("MainGUI", inherits from Tk:Toplevel) will use the input
from "CfgWindow" and perform the main tasks.

It's not too complicated I think, but I'm still having trouble with
some issues:

I think it would be nice if the two widgets would be completly
independent. Meaning that the parameters from CfgWindow would have to
be passed to MainGUI by... Yes, how? If I want to avoid calling
MainGUI directly I guess MainWindow would have to handle this somehow.
I've been experimenting with OnDestroy(), but it feels conceptually
wrong... I shouldn't have to destroy a widget to communicate to
another widget :)

Thanks for all help,
Fredrik

zentara

2007-03-01, 8:04 am

On 1 Mar 2007 02:04:55 -0800, linqon@gmail.com wrote:

>I'm developing a Perl Tk application and have some rather basic
>questions regarding communication and handling of parameters between
>two widgets.
>
>Here's what I have:
>
>I have one script (lets call it "TheScript.pl") that starts up the
>application. It creates a MainWindow. It creates two Toplevel widgets,
>each one of these consists of my own composite widgets. Basically all
>the script consists of are input parameter handling, Tk-creation and
>MainLoop.
>
>The first one ("CfgWindow", inherits from Tk::Frame) asks the user to
>enter some parameters. These parameters will then be used in the
>second one.
>
>Widget #2, ("MainGUI", inherits from Tk:Toplevel) will use the input
>from "CfgWindow" and perform the main tasks.
>
>It's not too complicated I think, but I'm still having trouble with
>some issues:
>
>I think it would be nice if the two widgets would be completly
>independent. Meaning that the parameters from CfgWindow would have to
>be passed to MainGUI by... Yes, how?


I don't see why this all can't be done in a single script? First start
your script with the $mw withdrawn, then open a toplevel for gathering
the config parameters. Once the config parameters are stored in some
variables, destroy the toplevel, setup the packing on the $mw and
display it.

>If I want to avoid calling
>MainGUI directly I guess MainWindow would have to handle this somehow.
>I've been experimenting with OnDestroy(), but it feels conceptually
>wrong... I shouldn't have to destroy a widget to communicate to
>another widget :)
>Fredrik


#!/usr/bin/perl
use warnings;
use strict;
use Tk;

my $config;

my $mw = MainWindow->new(-title=>"Demo");
$mw->withdraw;

get_config($mw);
MainLoop;

sub setup_mw{
my $label = $mw->Label(-text=> $config)->pack();
$mw->deiconify;
$mw->raise;
}

sub get_config {
my $parent = shift;

#collect your config here
$config = 'hoohah';

my $win = $parent->Toplevel(-title=>'config window');
my $Bttn = $win->Button(
-text=>"I'm done configuring, so press me",
-command=> sub{
$win->destroy;
setup_mw();

}
)->pack( );
}
__END__


zentara

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

2007-03-01, 7:08 pm

linqon@gmail.com wrote:
> Hi
>
> I'm developing a Perl Tk application and have some rather basic
> questions regarding communication and handling of parameters between
> two widgets.
>
> Here's what I have:
>
> I have one script (lets call it "TheScript.pl") that starts up the
> application. It creates a MainWindow. It creates two Toplevel widgets,
> each one of these consists of my own composite widgets. Basically all
> the script consists of are input parameter handling, Tk-creation and
> MainLoop.
>
> The first one ("CfgWindow", inherits from Tk::Frame) asks the user to
> enter some parameters. These parameters will then be used in the
> second one.
>
> Widget #2, ("MainGUI", inherits from Tk:Toplevel) will use the input
> from "CfgWindow" and perform the main tasks.
>
> It's not too complicated I think, but I'm still having trouble with
> some issues:
>
> I think it would be nice if the two widgets would be completly
> independent. Meaning that the parameters from CfgWindow would have to
> be passed to MainGUI by... Yes, how?


Hi,

if you designed these widgets, you should know about their interface and how to
connect them...??
Tk provides easy to use mechanisms to make your derived/composite widgets behave
like 'core' widgets, allowing cget/configure calls to get/set the attributes you
defined or to invoke methods of your class (See perldoc Tk::ConfigSpecs).
CfgWindow looks like a Dialog...

Code examples are welcome.

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
Dadeslen64

2007-03-05, 10:02 pm

Hardcore anal action! Free video download!
http://I-Love-Anal.info/videos/medi...php?file=218571
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com