Package library :: Package pyjamas :: Module Timer :: Class Timer
[hide private]
[frames] | no frames]

Class Timer

source code

object --+
         |
        Timer

Timer() a re-implementation of GWT's Timer class. This class has the same interface as GWT's with two minor enhancements in the constructor which changes what gets fired when the timer goes off.

Nested Classes [hide private]
  __WindowCloseListener
Instance Methods [hide private]
 
__init__(self, delayMillis=0, notify=None)
Called with no arguments, create a timer that will call its run() method when it is scheduled and fired.
source code
 
__impl_init_hook(self) source code
 
cancel(self)
Cancel the timer.
source code
 
run(self)
The method that gets fired when the timer goes off.
source code
 
schedule(self, delayMillis)
Schedule this timer to fire in delayMillis milliseconds.
source code
 
scheduleRepeating(self, periodMillis)
Schedule this timer to fire forever (or until cancelled) every periodMillis milliseconds.
source code
 
__fire(self, *args, **kwds) source code
 
__setTimeout(self, delayMillis) source code
 
__clearTimeout(self, tid) source code
 
__setInterval(self, periodMillis) source code
 
__clearInterval(self, tid) source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Variables [hide private]
  __timers = set()
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, delayMillis=0, notify=None)
(Constructor)

source code 

Called with no arguments, create a timer that will call its run() method when it is scheduled and fired. This usage requires subclassing to implement the run() method. This is GWT's interface and behaviour.

There are two enhancements to pyjamas' implementation when specified with special keyword arguments, one of which obviates the need for subclassing:

   timer = Timer(delayMillis=ms)

is identical to:

   timer = Timer()
   timer.schedule(ms)

and:

   timer = Timer(notify=object_or_func)

is the same as:

   timer = Timer()
   run = getattr(object_or_func, 'onTimer', object_or_func)
   if not callable(run): raise ValueError, msg

i.e., the value passed to notify is checked to see if it has an onTimer attribute; if so, it is used as the callable, if not, the object itself is used as the callable.

NOTE: when notify is specified, the function or method will be called with one argument: the instance of the timer. So, this would be proper usage:

   def timer_cb(timer):
      ...

   timer = Timer(notify=timer_cb)

or:

   class myclass:

       def __init__(self):
           ...
           self.timer = Timer(notify=self)

       def onTimer(self, timer):
           ...
Overrides: object.__init__

run(self)

source code 

The method that gets fired when the timer goes off. The base class raises a NotImplementedError if it is not overridden by a subclass or if Timer isn't instantiated with the notify keyword arguement.

schedule(self, delayMillis)

source code 

Schedule this timer to fire in delayMillis milliseconds. Calling this method cancels (for this instance only) any previously scheduled timer.

scheduleRepeating(self, periodMillis)

source code 

Schedule this timer to fire forever (or until cancelled) every periodMillis milliseconds. Calling this method cancels (for this instance only) any previously scheduled timer.