TkPerl5: new module "Flasher.pm" 
Author Message
 TkPerl5: new module "Flasher.pm"

Ok, so this is kinda hokey, but it's pretty neat to see it working in
one place.  Plus it serves as a good way to show that when you try to
do OO programing with Events and such, you have to start getting away
from Global variables and into Objects that store the data you need.
It simplifies coding (in someways) and hides alot of the mess.

Anyway, I've included below Flasher.pm, the module that does the work
and flasher.pl which shows how you can use it in your programs.
Enjoy!

As usual, both of these scripts can also be gotten via anon ftp from:

        ftp.wpi.edu:/perl5/tkperl-scripts/

Please feel free to email me scripts you would like included in this
little library of stuff.

                        John

# Flasher.pm - flash a widget.
#
# Author: John Stoffel (based on Stephen Lidie's idea)
# Date:   11/23/1994
#
# usage:
#
# $W = Flasher::new($widget,$interval,$option,[ value1, value2 ... valueN ]);
# Flash($W); # toggles flashing on/off each call for widget $W.
#
# see flasher.pl for a working example
#

package Flasher;

use Tk;
use Exporter;


# constructor

sub new {

  local($orig) = ($w->configure($o))[3];

  return bless({ Widget   => $w,
                 Interval => $i,
                 Option   => $o,
                 Values   => $v,

                 Stop     => 0,
                 Status   => -1,
                 Original => $orig,
             });

Quote:
}

# public method

sub Flash {

  if ($W->{Stop}) {
    $W->{Status} = -1;
    $W->{Stop} = 0;
  }
  else {
    $W->{Status} = 0;
    $W->{Stop} = 1;
    flasher($W);
  }

Quote:
}

# private method

sub flasher {

  if ($W->{Status} == -1) {
    $W->{Widget}->configure($W->{Option} => $W->{Original});
    return;
  }

  $W->{Status} = $W->{Status} + 1;
  if ($W->{Status} > $W->{NumVal}) {
    $W->{Status} = 0;
  }
  $W->{Widget}->configure($W->{Option} => $W->{Values}[$W->{Status}]);
  after($W->{Interval},flasher,$W);

Quote:
}

1;

#!/usr/local/bin/perl
#
# flasher.pl - Flasher.pm example for flashing parts of a widget
#
# Author: John Stoffel
# Date:   11/23/1994

use Tk;
use Flasher;

$top = tkinit;

$l1 = Label::new($top,"-text" => "       Foo        ");
$L1 = Flasher::new($l1,500,"-background",["red","blue","yellow"]);

$b1 = Button::new($top,"-text" => " Flash Foo ",
                 "-method" => sub { Flash($L1)} );

$l2 = Label::new($top,"-text" => "       Bar        ");
$L2 = Flasher::new($l2,750,"-foreground",["red","blue","yellow","orange"]);

$b2 = Button::new($top,"-text" => " Flash Bar ",
                 "-method" => sub { Flash($L2)} );

$l3 = Label::new($top,"-text" => "       FooBar        ");
$L3 = Flasher::new($l3,750,"-font",["9x15","fixed","Helvetica12"]);

$b3 = Button::new($top,"-text" => " Flash FooBar ",
                 "-method" => sub { Flash($L3)} );

tkpack $l1,$l2, $l3, $b1, $b2, $b3;

tkmainloop;



Mon, 12 May 1997 03:58:33 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. New module/pragma "enum.pm" (was "fields.pm")

2. New module/pragma "enum.pm" (was "fields.pm")

3. TkPerl5 equivalent of Tcl "toplevel"?

4. ANNOUNCE: New module "Locations" (1.0)

5. question about "new" in a module

6. ANNOUNCE: New module "Locations" (1.0)

7. Comments wanted on new "Streams" module

8. New module "Date::DateCalc" Version 1.0

9. Trouble finding "vars.pm" module

10. module "Exporter.pm"

11. format for use "otherlib\\Module.pm";

12. "character class ""bug""

 

 
Powered by phpBB® Forum Software