"Fossies" - the Fresh Open Source Software Archive

Member "Tk-804.036/Tk/After.pm" (15 Nov 2013, 1946 Bytes) of package /linux/misc/Tk-804.036.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "After.pm" see the Fossies "Dox" file reference documentation.

    1 # Copyright (c) 1995-2004 Nick Ing-Simmons. All rights reserved.
    2 # This program is free software; you can redistribute it and/or
    3 # modify it under the same terms as Perl itself.
    4 package Tk::After;
    5 use Carp;
    6 
    7 use vars qw($VERSION);
    8 $VERSION = '4.008'; # $Id: //depot/Tkutf8/Tk/After.pm#11 $
    9 
   10 sub _cancelAll
   11 {
   12  my $w = shift;
   13  my $h = delete $w->{_After_};
   14  foreach my $obj (values %$h)
   15   {
   16    # carp "Auto cancel ".$obj->[1]." for ".$obj->[0]->PathName;
   17    $obj->cancel;
   18    bless $obj,"Tk::After::Cancelled";
   19   }
   20 }
   21 
   22 sub Tk::After::Cancelled::once { }
   23 sub Tk::After::Cancelled::repeat { }
   24 sub Tk::After::Cancelled::cancel { }
   25 
   26 sub submit
   27 {
   28  my $obj     = shift;
   29  my $w       = $obj->[0];
   30  my $id      = $obj->[1];
   31  my $t       = $obj->[2];
   32  my $method  = $obj->[3];
   33  delete($w->{_After_}{$id}) if (defined $id);
   34  $id  = $w->Tk::after($t,[$method => $obj]);
   35  unless (exists $w->{_After_})
   36   {
   37    $w->{_After_} = {};
   38    $w->OnDestroy([\&_cancelAll, $w]);
   39   }
   40  $w->{_After_}{$id} = $obj;
   41  $obj->[1] = $id;
   42  return $obj;
   43 }
   44 
   45 sub DESTROY
   46 {
   47  my $obj = shift;
   48  $obj->cancel;
   49  undef $obj->[0];
   50  undef $obj->[4];
   51 }
   52 
   53 sub new
   54 {
   55  my ($class,$w,$t,$method,@cb) = @_;
   56  my $cb    = (@cb == 1) ? shift(@cb) : [@cb];
   57  my $obj   = bless [$w,undef,$t,$method,Tk::Callback->new($cb)],$class;
   58  return $obj->submit;
   59 }
   60 
   61 sub cancel
   62 {
   63  my $obj = shift;
   64  my $id  = $obj->[1];
   65  my $w   = $obj->[0];
   66  if ($id)
   67   {
   68    $w->Tk::after('cancel'=> $id) if Tk::Exists($w);
   69    delete $w->{_After_}{$id} if exists $w->{_After_};
   70    $obj->[1] = undef;
   71   }
   72  return $obj;
   73 }
   74 
   75 sub repeat
   76 {
   77  my $obj = shift;
   78  $obj->submit;
   79  local $Tk::widget = $obj->[0];
   80  $obj->[4]->Call;
   81 }
   82 
   83 sub once
   84 {
   85  my $obj = shift;
   86  my $w   = $obj->[0];
   87  my $id  = $obj->[1];
   88  delete $w->{_After_}{$id};
   89  local $Tk::widget = $w;
   90  $obj->[4]->Call;
   91 }
   92 
   93 sub time {
   94     my $obj = shift;
   95     my $delay = shift;
   96     if (defined $delay) {
   97     $obj->cancel if $delay == 0;
   98     $obj->[2] = $delay;
   99     }
  100     $obj->[2];
  101 }
  102 
  103 1;
  104 __END__
  105