From 934500197a49166187dc57cbd29fec7524334d79 Mon Sep 17 00:00:00 2001 From: marion Date: Thu, 10 Jun 2010 14:43:04 +0000 Subject: nouvelle compression des évènements move de xinput-ivy --- src/MTools/MTimer.pm | 98 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 56 insertions(+), 42 deletions(-) (limited to 'src/MTools/MTimer.pm') diff --git a/src/MTools/MTimer.pm b/src/MTools/MTimer.pm index 9377706..ff74c72 100644 --- a/src/MTools/MTimer.pm +++ b/src/MTools/MTimer.pm @@ -51,53 +51,67 @@ use Tk; sub new { - my ($class, $timeout, $repeat, $callback, %options) = @_; - my $self = new MTools::MObjet (); - bless $self, $class; - - $repeat = 0 if !defined $repeat; - $repeat = 0 if !defined $callback; - - $self -> recordEvent ('TIME_OUT'); - $self -> recordEvent ('TIMER_STOPPED'); - $self -> recordProperty ('timeout', $timeout); - $self -> recordProperty ('repeat', $repeat); - $self -> recordProperty ('callback', $callback); - $self -> recordProperty ('-visible', 0); - $self -> plisten ('-visible', sub { - my ($src, $key, $val) = @_; - if ($val == 0) - { - $self -> stop (); - } - else - { - $self -> start (); - } - }); - $self -> mconfigure (%options); - - return $self; + my ($class, $timeout, $repeat, $callback, %options) = @_; + my $self = new MTools::MObjet (); + bless $self, $class; + + $repeat = 0 if !defined $repeat; + $repeat = 0 if !defined $callback; + + $self -> recordEvent ('TIME_OUT'); + $self -> recordEvent ('TIMER_STOPPED'); + $self -> recordProperty ('timeout', $timeout); + $self -> recordProperty ('repeat', $repeat); + $self -> recordProperty ('callback', $callback); + $self -> recordProperty ('-visible', 0); + $self-> {__timer} = undef; + $self -> plisten ('-visible', + sub { + my ($src, $key, $val) = @_; + if ($val == 0) + { + $self -> stop (); + } + else + { + $self -> start (); + } + }); + $self -> mconfigure (%options); + return $self; } sub start { - my ($self) = @_; - my $repeat = $self -> mget ('repeat'); - my $timeout = $self -> mget ('timeout'); - my $callback = $self -> mget ('callback'); - my $function = $repeat ? 'repeat' : 'after'; - $self -> {__timer} = $zinc -> $function ($timeout, sub { - $self -> notify ('TIME_OUT'); - if ($callback) - { - executer ($callback); - } - }); + my ($self) = @_; + my $repeat = $self -> mget ('repeat'); + my $timeout = $self -> mget ('timeout'); + my $callback = $self -> mget ('callback'); + my $function = $repeat ? 'repeat' : 'after'; + $self -> {__timer} = $zinc -> $function ($timeout, + sub { + $self -> notify ('TIME_OUT'); + if ($callback) + { + executer ($callback); + } + $self -> {__timer} = undef unless $repeat; + }); } sub stop { - my ($self) = @_; - $zinc -> afterCancel ($self -> {__timer}); - $self -> notify ('TIMER_STOPPED'); + my ($self) = @_; + return unless defined $self -> {__timer}; + $zinc -> afterCancel ($self -> {__timer}); + $self -> {__timer} = undef; + $self -> notify ('TIMER_STOPPED'); +} + +sub is_running { + my ($self) = @_; + return (defined $self -> {__timer} ? 1 : 0); } + 1; + + + -- cgit v1.1