wx.Timer

Inheritance diagram for wx.Timer:



Description

The wx.Timer class allows you to execute code at specified intervals. Its precision is platform-dependent, but in general will not be better than 1 ms nor worse than 1 s.

There are three different ways to use this class:

  1. You may derive a new class from wx.Timer and override the Notify member to perform the required action.
  2. Or you may redirect the notifications to any wx.EvtHandler derived object by using the non-default constructor or SetOwner . Then use the wx.EVT_TIMER event to connect it to the event handler which will receive wx.TimerEvent notifications.
  3. Or you may use a derived class and the wx.EVT_TIMER event to connect it to an event handler defined in the derived class. If the default constructor is used, the timer object will be its own owner object, since it is derived from wx.EvtHandler.

In any case, you must start the timer with Start after constructing it before it actually starts sending notifications. It can be stopped later with Stop.

Note

A timer can only be used from the main thread.

Derived From

Known Subclasses

wx.PyTimer

Properties Summary

Class API

Methods

__init__(owner=None, id=wx.ID_ANY)

Creates a timer and associates it with owner. Please see SetOwner for the description of parameters.

Parameters:


Returns:

wx.Timer


GetId()
No docstrings found for this method.

GetInterval()

Returns the current interval for the timer (in milliseconds).

Returns:

int


GetOwner()
No docstrings found for this method.

IsOneShot()

Returns True if the timer is one shot, i.e. if it will stop after firing the first notification automatically.

Returns:

bool


IsRunning()

Returns True if the timer is running, False if it is stopped.

Returns:

bool


Notify()

This member should be overridden by the user if the default constructor was used and SetOwner wasn’t called.

Perform whatever action which is to be taken periodically here.


SetOwner(owner, id=-1)

Associates the timer with the given owner object. When the timer is running, the owner will receive timer events with id equal to id specified here.

Parameters:


Start(milliseconds=-1, oneShot=False)

(Re)starts the timer.

If milliseconds parameter is -1 (value by default), the previous value is used.

If oneShot is False (the default), the Notify function will be called repeatedly until the timer is stopped. If True, it will be called only once and the timer will stop automatically. To make your code more readable you may also use the following symbolic constants for the oneShot parameter:

Parameter Flag Description
wx.TIMER_CONTINUOUS Start a normal, continuously running, timer
wx.TIMER_ONE_SHOT Start a one shot timer

If the timer was already running, it will be stopped by this method before restarting it.

Returns False if the timer could not be started, True otherwise (in MS Windows timers are a limited resource).

Parameters:

  • milliseconds (int)
  • oneShot (bool)

Returns:

bool


Stop()
Stops the timer.

Properties

Id
See GetId
Interval
See GetInterval
Owner
See GetOwner and SetOwner