Heray-Was-Here
Server : Apache
System : Linux vps103298.mylogin.co 4.18.0-513.11.1.el8_9.x86_64 #1 SMP Wed Jan 17 02:00:40 EST 2024 x86_64
User : calvet ( 273824)
PHP Version : 7.4.33
Disable Function : NONE
Directory :  /proc/self/root/proc/self/root/usr/share/doc/perl-Tk/demos/widget_lib/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //proc/self/root/proc/self/root/usr/share/doc/perl-Tk/demos/widget_lib/trace1.pl
# trace1.pl

use Tk::widgets qw/  Trace /;
use vars qw/ $TOP /;
use strict;

sub trace1 {

    my( $demo ) = @_;

    $TOP = $MW->WidgetDemo(
        -name             => $demo,
        -text             => "This demonstration animates an analog display as you move the Scale's slider.",
        -title            => 'Move a meter tied to a variable',
        -iconname         => 'trace1',
    );

    my $mw = $TOP;
    my $v;			# variable to trace

    my $c = $mw->Canvas(qw/-width 200 -height 110 -bd 2 -relief sunken/)->grid;
    $c->createLine(qw/ 100 100 10 100  -tag meter -arrow last -width 5/);
    my $s = $mw->Scale(qw/-orient h -from 0 -to 100 -variable/ => \$v)->grid;
    $mw->Label(-text => 'Slide Me')->grid;

    # Trace $v when written.  The callback is supplied three explicit arguments:
    # the index if an array or hash, else undef, the proposed new value, and the
    # trace operation (rwu) for read, write, undef, respectively. Additionally,
    # we pass the Canvas and Scale widget references.

    $mw->traceVariable(\$v, 'w' => [\&trace1_update_meter, $c, $s]);

} # end trace1

sub trace1_update_meter {

    my( $index, $value, $op, $c, $s ) = @_;

    return if $op eq 'u';

    my($min, $max) = ($s->cget(-from), $s->cget(-to));
    my $pos = $value / abs($max - $min);
    my $pi = 3.1415926;
    my $x = 100.0 - 90.0 * (cos( $pos * $pi ));
    my $y = 100.0 - 90.0 * (sin( $pos * $pi ));
    $c->coords(qw/meter 100 100/, $x, $y);
    return $value;

 } # end trace1_update_meter

Hry