Implicit {loca; $Tk::widget = ... } for Tk 
Author Message
 Implicit {loca; $Tk::widget = ... } for Tk

To work round poor interaction with user-level $SIG{__DIE__} I have
been looking at localizing from Tk's C code.

So it is now possible to do :

#!/usr/local/bin/perl -w
use Tk qw(MainLoop *widget);
use Carp;

my $mw = MainWindow->new;

$mw->Button(-text => 'Button_1', -command => \&callback)->pack;
$mw->Button(-text => 'Button_2', -command => \&callback)->pack;

MainLoop;

sub callback
{
 print "Callback for ",$widget->cget('-text'),"\n";

Quote:
}

__END__

That is a $Tk::widget (which may be imported as a glob as above) will
magically apear set to "current widget", i.e. it is localized in C code
when (e.g.) an X Event occurs.

Questions:

1. (For pTk and porters) - is this a good idea ?

2. (For pTk) how about a $event to go with it with value
   to $widget->XEvent ?

3. (Porters only) - I was surpised to have to import the glob (i.e. *widget),
   but if I don't then I only see 'global' Tk::widget in main::widget,
   not the localized version - have I done something wrong?

==========================================================================
This message was posted through the Stanford campus mailing list
server.  If you wish to unsubscribe from this mailing list, send the

--




Fri, 14 May 1999 03:00:00 GMT  
 Implicit {loca; $Tk::widget = ... } for Tk

Quote:
> That is a $Tk::widget (which may be imported as a glob as above) will
> magically apear set to "current widget", i.e. it is localized in C code
> when (e.g.) an X Event occurs.

> Questions:

> 1. (For pTk and porters) - is this a good idea ?

I like the idea of having $widget available to the called-back subroutine.

Quote:
> 2. (For pTk) how about a $event to go with it with value
>    to $widget->XEvent ?

I haven't used events much, so can't comment.


=    Software Developer       (Engineer except where prohibited by Law) =  =  =
===  Product Engineering Tools                                           = = =
=    Texas Instruments        (972)480-4251   FAX:(972)480-4146           = =



Fri, 14 May 1999 03:00:00 GMT  
 Implicit {loca; $Tk::widget = ... } for Tk

Quote:
> sub callback
> {
>  print "Callback for ",$widget->cget('-text'),"\n";
> }

> That is a $Tk::widget (which may be imported as a glob as above) will
> magically apear set to "current widget", i.e. it is localized in C code
> when (e.g.) an X Event occurs.

> Questions:

> 1. (For pTk and porters) - is this a good idea ?

Seems to be, since it simplifies things and there will be no name conflicts.
How about efficiency - faster too?

Quote:
> 2. (For pTk) how about a $event to go with it with value
>    to $widget->XEvent ?

Something like this:

        $x = $Tk::event->X;

As opposed to this?

        $x = shift->XEvent->X;

I think I like it (;  This sounds similar to a p5p discussion a while back
on a magical $self for object methods...



Fri, 14 May 1999 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. RFQ: Tk::Wizard - a wizard style widget for Perl/Tk

2. BETA TEST: Tk::Tie::MenuHash - Ties a Tk::Menubutton widget to a hash, kinda

3. BETA TEST: Tk::Tie::MenuHash - Ties a Tk::Menubutton widget to a hash, kinda

4. RFQ: Tk::Wizard - a wizard style widget for Perl/Tk

5. Can Tk Widget and Xt Widget work together?

6. Is there a Tree widget in perlTk that resembles the Tree widget in Tk

7. what Tk Tk/perl Tkperl perl/Tk?

8. Perl5 Tk widget in canvas how?

9. Man pages or Man page for TK widgets

10. perl/tk text widget and encodings (utf8 / ucs2 etc)

11. Read Text Widget into Array (PERL TK)

 

 
Powered by phpBB® Forum Software