pyface.timer.i_timer module

Interfaces and base classes for cross-toolkit timers

This module defines interfaces for toolkit event-loop based timers. It also provides a base implementation that can be easily specialized for a particular back-end, and mixins that provide additional capabilities.

class pyface.timer.i_timer.ITimer(adaptee, default=<class 'traits.adaptation.adaptation_error.AdaptationError'>)[source]

Bases: Interface

Interface for timer classes.

This is a base interface which doesn’t specify any particular notification mechanism.

interval = Range(low=0.0)

The interval at which to call the callback in seconds.

repeat = Union(None, Int)

The number of times to repeat the callback, or None if no limit.

expire = Union(None, Float)

The maximum length of time to run in seconds, or None if no limit.

active = Bool()

Whether or not the timer is currently running.

classmethod timer(**traits)[source]

Convenience method that creates and starts a timer.

classmethod single_shot(**traits)[source]

Convenience method that creates and starts a single-shot timer.

start()[source]

Start the timer.

stop()[source]

Stop the timer.

perform()[source]

The method that will be called by the timer.

class pyface.timer.i_timer.IEventTimer(adaptee, default=<class 'traits.adaptation.adaptation_error.AdaptationError'>)[source]

Bases: ITimer

Interface for timers which fire a trait event periodically.

timeout = Event()

A traits Event to fire when the callback happens.

class pyface.timer.i_timer.ICallbackTimer(adaptee, default=<class 'traits.adaptation.adaptation_error.AdaptationError'>)[source]

Bases: ITimer

Interface for timers which call a callback periodically.

callback = Callable

The callback to make, or None if no callback.

args = Tuple()

Positional arguments to give the callback.

kwargs = Dict()

Keyword arguments to give the callback.

class pyface.timer.i_timer.BaseTimer[source]

Bases: ABCHasTraits

Base class for timer classes.

This class has a class variable which tracks active timers to prevent failures caused by garbage collection. A timer is added to this tracker when it is started if the repeat value is not None.

interval = Range(low=0.0, value=0.05)

The interval at which to call the callback in seconds.

repeat = Union(None, Int)

The number of times to repeat the callback, or None if no limit.

expire = Union(None, Float)

The maximum length of time to run in seconds, or None if no limit.

active = Property(Bool, observe="_active")

Property that controls the state of the timer.

classmethod timer(**traits)[source]

Convenience method that creates and starts a timer.

classmethod single_shot(**traits)[source]
start()[source]

Start the timer.

stop()[source]

Stop the timer.

perform()[source]

Perform the callback.

The timer will stop if repeats is not None and less than 1, or if the _perform method raises StopIteration.

class pyface.timer.i_timer.MEventTimer[source]

Bases: HasTraits

Mixin for event timer classes.

Other code can listen to the timeout event using standard traits listeners.

timeout = Event()

A traits Event to fire when the callback happens.

class pyface.timer.i_timer.MCallbackTimer[source]

Bases: HasTraits

Mixin for callback timer classes.

callback = Callable

The callback to make.

args = Tuple()

Positional arguments to give the callback.

kwargs = Dict()

Keyword arguments to give the callback.