Implementing a -textvariable in a custom widget 
Author Message
 Implementing a -textvariable in a custom widget

Hello,

I'm trying to make my own custom widget, and would like it to update its
self when any of the varible pointers passed to it change. Are there any
examples on how to do this?

Thanks
Jason



Sat, 01 Oct 2005 02:43:08 GMT  
 Implementing a -textvariable in a custom widget

Quote:
> Hello,

> I'm trying to make my own custom widget, and would like it to update its
> self when any of the varible pointers passed to it change. Are there any
> examples on how to do this?

Not exactly an example for implementing -textvariable, but maybe
helpful: the Tk::Trace manpage.

Regards,
        Slaven

--

    tksm - Perl/Tk program for searching and replacing in multiple files
    http://ptktools.sourceforge.net/#tksm



Sat, 01 Oct 2005 03:11:46 GMT  
 Implementing a -textvariable in a custom widget

Subject: Re: Implementing a -textvariable in a custom widget
Newsgroups: comp.lang.perl.tk


 > Hello,
 >
 > I'm trying to make my own custom widget, and would like it to update
its
 > self when any of the varible pointers passed to it change. Are there
any
 > examples on how to do this?

For a Perl mega-widget, see Emu 350, 388-394, 665-670. In essence use
Tie::Watch.  Tk::LCD is the example, it has a set() method that the
watch/trace code calls:

$self->ConfigSpecs(
     -variable   => [qw/METHOD  variable   Variable/, undef ],
  );

sub variable {

     use Tie::Watch;


     my $st = [sub {

            my $argv= $watch->Args('-store');
            $argv->[0]->set($new_val);
            $watch->Store($new_val);
     }, $lcd];

     $lcd->{watch} = Tie::Watch->new(-variable => $vref, -store => $st);

     $lcd->OnDestroy( [sub {$_[0]->{watch}->Unwatch}, $lcd] );

Quote:
} # end variable

But Tk800.024 wraps Tie::Watch to emulate the Tcl/Tk traceVariable
command in the module Tk::Trace.  Here's the above subroutine converted
to the new mechanism:

sub variable {

     use Tk::Trace;


     my $st = [sub {

            return unless $op eq 'w';
            $lcd->set($new_val);
            $new_val;
     }, $lcd];

     $lcd->traceVariable($vref, 'w' => $st);
     $lcd->{watch} = $vref;

     $lcd->OnDestroy( [sub {$_[0]->traceVdelete($_[0]->{watch})}, $lcd]
);

Quote:
} # end variable

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



Sat, 01 Oct 2005 10:54:14 GMT  
 Implementing a -textvariable in a custom widget

Quote:

> But Tk800.024 wraps Tie::Watch to emulate the Tcl/Tk traceVariable
> command in the module Tk::Trace.  Here's the above subroutine converted
> to the new mechanism:

I meant to say Tk804.024 - but there's a patch for Tk800.024.


Sat, 01 Oct 2005 11:08:23 GMT  
 Implementing a -textvariable in a custom widget
Thanks! Works great!
Quote:


>>Hello,

>>I'm trying to make my own custom widget, and would like it to update its
>>self when any of the varible pointers passed to it change. Are there any
>>examples on how to do this?

> Not exactly an example for implementing -textvariable, but maybe
> helpful: the Tk::Trace manpage.

> Regards,
>    Slaven



Sun, 02 Oct 2005 01:59:33 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. change background color on a widget when the textvariable changes

2. Entry widget and -textvariable configuration option..

3. Entry widget -textvariable option

4. Label widget -textvariable option

5. Need help creating custom widget

6. Implementing instance variables for composite widgets

7. Implementing Menu based Cut/Paste on a composite widget

8. Bug with -textvariable in TkPerl5

9. use hash for -textvariable?

10. Anonomous Referents and -textvariable

11. -textvariable => \$obj->{key}

12. Tieed -textvariable

 

 
Powered by phpBB® Forum Software