]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/_timer.i
Fixed wx.Timer to not need to hold an extra reference to itself, so it
[wxWidgets.git] / wxPython / src / _timer.i
CommitLineData
d14a1e28
RD
1/////////////////////////////////////////////////////////////////////////////
2// Name: _timer.i
3// Purpose: SWIG interface definitions wxTimer
4//
5// Author: Robin Dunn
6//
7// Created: 18-June-1999
8// RCS-ID: $Id$
9// Copyright: (c) 2003 by Total Control Software
10// Licence: wxWindows license
11/////////////////////////////////////////////////////////////////////////////
12
13// Not a %module
14
15
16//---------------------------------------------------------------------------
17%newgroup
18
19enum {
20 // generate notifications periodically until the timer is stopped (default)
21 wxTIMER_CONTINUOUS,
22
23 // only send the notification once and then stop the timer
24 wxTIMER_ONE_SHOT,
25};
26
27// Timer event type
28%constant wxEventType wxEVT_TIMER;
66065839 29
d14a1e28
RD
30
31//---------------------------------------------------------------------------
32
33
34%{
66065839
RD
35//IMP_PYCALLBACK__(wxPyTimer, wxTimer, Notify);
36
37void wxPyTimer::Notify() {
38 bool found;
39 wxPyBeginBlockThreads();
40 if ((found = wxPyCBH_findCallback(m_myInst, "Notify")))
41 wxPyCBH_callCallback(m_myInst, Py_BuildValue("()"));
42 wxPyEndBlockThreads();
43 if (! found)
44 wxTimer::Notify();
45}
46void wxPyTimer::base_Notify() {
47 wxTimer::Notify();
48}
49
d14a1e28
RD
50%}
51
52
53
54%name(Timer) class wxPyTimer : public wxEvtHandler
55{
56public:
66065839
RD
57 %pythonAppend wxPyTimer "self._setCallbackInfo(self, Timer, 0)"
58
59// %pythonAppend wxTimer
60// "if hasattr(self, 'Notify'):
61// print 'bound EVT_TIMER to self.Notify'
62// self.Bind(EVT_TIMER, self.Notify)
63// self.SetOwner(self)";
d14a1e28
RD
64
65 // if you don't call SetOwner() or provide an owner in the contstructor
66 // then you must override Notify() inorder to receive the timer
67 // notification. If the owner is set then it will get the timer
68 // notifications which can be handled with EVT_TIMER.
69 wxPyTimer(wxEvtHandler *owner=NULL, int id = -1);
70 virtual ~wxPyTimer();
71
66065839 72 void _setCallbackInfo(PyObject* self, PyObject* _class, int incref=1);
7722248d 73
d14a1e28
RD
74 // Set the owner instance that will receive the EVT_TIMER events using the
75 // given id.
76 void SetOwner(wxEvtHandler *owner, int id = -1);
77
78
79 // start the timer: if milliseconds == -1, use the same value as for the
80 // last Start()
81 //
82 // it is now valid to call Start() multiple times: this just restarts the
83 // timer if it is already running
dd9f7fea 84 virtual bool Start(int milliseconds = -1, bool oneShot = False);
d14a1e28
RD
85
86 // stop the timer
87 virtual void Stop();
88
89 // override this in your wxTimer-derived class if you want to process timer
90 // messages in it, use non default ctor or SetOwner() otherwise
7722248d 91 //virtual void Notify();
d14a1e28 92
dd9f7fea 93 // return True if the timer is running
d14a1e28
RD
94 virtual bool IsRunning() const;
95
96 // get the (last) timer interval in the milliseconds
97 int GetInterval() const;
98
dd9f7fea 99 // return True if the timer is one shot
d14a1e28 100 bool IsOneShot() const;
0bdc5dd6
RD
101
102 // return the timer ID
103 int GetId() const;
66065839 104
d14a1e28
RD
105};
106
107
66065839 108%pythoncode {
d14a1e28
RD
109%# For backwards compatibility with 2.4
110class PyTimer(Timer):
111 def __init__(self, notify):
112 Timer.__init__(self)
113 self.notify = notify
114
115 def Notify(self):
116 if self.notify:
117 self.notify()
118
119
120EVT_TIMER = wx.PyEventBinder( wxEVT_TIMER, 1 )
66065839 121
d14a1e28
RD
122};
123
124
125
126class wxTimerEvent : public wxEvent
127{
128public:
129 wxTimerEvent(int timerid = 0, int interval = 0);
130 int GetInterval() const;
131};
132
133
134
135// wxTimerRunner: starts the timer in its ctor, stops in the dtor
136class wxTimerRunner
137{
138public:
139 %nokwargs wxTimerRunner;
140 wxTimerRunner(wxTimer& timer);
dd9f7fea 141 wxTimerRunner(wxTimer& timer, int milli, bool oneShot = False);
d14a1e28
RD
142 ~wxTimerRunner();
143
dd9f7fea 144 void Start(int milli, bool oneShot = False);
d14a1e28
RD
145};
146
147
148//---------------------------------------------------------------------------