******** wx.Timer ******** Inheritance diagram for `wx.Timer`: | .. inheritance-diagram:: 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 <#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 <#SetOwner>`_ . Then use the ``wx.EVT_TIMER`` event to connect it to the event handler which will receive `wx.TimerEvent <../Events/wx.TimerEvent.html>`_ 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 <#Start>`_ after constructing it before it actually starts sending notifications. It can be stopped later with `Stop <#Stop>`_. .. note:: A timer can only be used from the main thread. .. seealso:: `wx.StartTimer <../wxFunctions.html#StartTimer>`_ , `wx.GetElapsedTime <../wxFunctions.html#GetElapsedTime>`_ , `wx.StopWatch `_ Derived From ^^^^^^^^^^^^^ * `wx.EvtHandler `_ * `wx.Object `_ Known Subclasses ^^^^^^^^^^^^^^^^ `wx.PyTimer `_ Methods Summary ^^^^^^^^^^^^^^^ * `__init__ <#__init__>`_ * `GetId <#GetId>`_ * `GetInterval <#GetInterval>`_ * `GetOwner <#GetOwner>`_ * `IsOneShot <#IsOneShot>`_ * `IsRunning <#IsRunning>`_ * `Notify <#Notify>`_ * `SetOwner <#SetOwner>`_ * `Start <#Start>`_ * `Stop <#Stop>`_ Properties Summary ^^^^^^^^^^^^^^^^^^ * `Id <#Id>`_ * `Interval <#Interval>`_ * `Owner <#Owner>`_ Class API ========= Methods ^^^^^^^ .. method:: __init__(owner=None, id=wx.ID_ANY) Creates a timer and associates it with owner. Please see `SetOwner <#SetOwner>`_ for the description of parameters. **Parameters:** * `owner` (`wx.EvtHandler `_) * `id` (int) | **Returns:** `wx.Timer `_ -------- .. method:: GetId() `No docstrings found for this method.` -------- .. method:: GetInterval() Returns the current interval for the timer (in milliseconds). **Returns:** `int` -------- .. method:: GetOwner() `No docstrings found for this method.` -------- .. method:: IsOneShot() Returns ``True`` if the timer is one shot, i.e. if it will stop after firing the first notification automatically. **Returns:** `bool` -------- .. method:: IsRunning() Returns ``True`` if the timer is running, ``False`` if it is stopped. **Returns:** `bool` -------- .. method:: Notify() This member should be overridden by the user if the default constructor was used and `SetOwner <#SetOwner>`_ wasn't called. Perform whatever action which is to be taken periodically here. -------- .. method:: 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:** * `owner` (`wx.EvtHandler `_) * `id` (int) -------- .. method:: 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 <#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` -------- .. method:: Stop() Stops the timer. -------- Properties ^^^^^^^^^^ .. attribute:: Id See `GetId <#GetId>`_ .. attribute:: Interval See `GetInterval <#GetInterval>`_ .. attribute:: Owner See `GetOwner <#GetOwner>`_ and `SetOwner <#SetOwner>`_