]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/_timer.i
the window takes ownership of the caret
[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
313feadc 37IMPLEMENT_ABSTRACT_CLASS(wxPyTimer, wxTimer);
94fd5e4d
RD
38
39wxPyTimer::wxPyTimer(wxEvtHandler *owner, int id)
40 : wxTimer(owner, id)
41{
42 if (owner == NULL) SetOwner(this);
43}
44
45
66065839
RD
46void wxPyTimer::Notify() {
47 bool found;
da32eb53 48 bool blocked = wxPyBeginBlockThreads();
66065839
RD
49 if ((found = wxPyCBH_findCallback(m_myInst, "Notify")))
50 wxPyCBH_callCallback(m_myInst, Py_BuildValue("()"));
da32eb53 51 wxPyEndBlockThreads(blocked);
66065839
RD
52 if (! found)
53 wxTimer::Notify();
54}
55void wxPyTimer::base_Notify() {
56 wxTimer::Notify();
57}
58
d14a1e28
RD
59%}
60
61
62
ab1f7d2a
RD
63MustHaveApp(wxPyTimer);
64
1b8c7ba6
RD
65%rename(Timer) wxPyTimer;
66class wxPyTimer : public wxEvtHandler
d14a1e28
RD
67{
68public:
94fd5e4d
RD
69 // Don't let the OOR or callback info hold references to the object so
70 // there won't be a reference cycle and it can clean itself up via normal
71 // Python refcounting
72 %pythonAppend wxPyTimer
73 "self._setCallbackInfo(self, Timer, 0); self._setOORInfo(self, 0)"
66065839 74
d14a1e28
RD
75
76 // if you don't call SetOwner() or provide an owner in the contstructor
77 // then you must override Notify() inorder to receive the timer
78 // notification. If the owner is set then it will get the timer
79 // notifications which can be handled with EVT_TIMER.
80 wxPyTimer(wxEvtHandler *owner=NULL, int id = -1);
94fd5e4d
RD
81
82 // Destructor.
d14a1e28
RD
83 virtual ~wxPyTimer();
84
66065839 85 void _setCallbackInfo(PyObject* self, PyObject* _class, int incref=1);
7722248d 86
d14a1e28
RD
87 // Set the owner instance that will receive the EVT_TIMER events using the
88 // given id.
89 void SetOwner(wxEvtHandler *owner, int id = -1);
313feadc 90 wxEvtHandler* GetOwner();
d14a1e28
RD
91
92 // start the timer: if milliseconds == -1, use the same value as for the
93 // last Start()
94 //
95 // it is now valid to call Start() multiple times: this just restarts the
96 // timer if it is already running
a72f4631 97 virtual bool Start(int milliseconds = -1, bool oneShot = false);
d14a1e28
RD
98
99 // stop the timer
100 virtual void Stop();
101
102 // override this in your wxTimer-derived class if you want to process timer
103 // messages in it, use non default ctor or SetOwner() otherwise
7722248d 104 //virtual void Notify();
d14a1e28 105
dd9f7fea 106 // return True if the timer is running
d14a1e28
RD
107 virtual bool IsRunning() const;
108
109 // get the (last) timer interval in the milliseconds
110 int GetInterval() const;
111
dd9f7fea 112 // return True if the timer is one shot
d14a1e28 113 bool IsOneShot() const;
0bdc5dd6
RD
114
115 // return the timer ID
116 int GetId() const;
66065839 117
94fd5e4d
RD
118 %pythoncode {
119 def Destroy():
120 """NO-OP: Timers must be destroyed by normal refrence counting"""
121 pass
122 }
d14a1e28
RD
123};
124
125
66065839 126%pythoncode {
d14a1e28
RD
127%# For backwards compatibility with 2.4
128class PyTimer(Timer):
129 def __init__(self, notify):
130 Timer.__init__(self)
131 self.notify = notify
132
133 def Notify(self):
134 if self.notify:
135 self.notify()
136
137
138EVT_TIMER = wx.PyEventBinder( wxEVT_TIMER, 1 )
66065839 139
d14a1e28
RD
140};
141
142
143
144class wxTimerEvent : public wxEvent
145{
146public:
147 wxTimerEvent(int timerid = 0, int interval = 0);
148 int GetInterval() const;
149};
150
151
152
153// wxTimerRunner: starts the timer in its ctor, stops in the dtor
ab1f7d2a 154MustHaveApp(wxTimerRunner);
d14a1e28
RD
155class wxTimerRunner
156{
157public:
158 %nokwargs wxTimerRunner;
159 wxTimerRunner(wxTimer& timer);
a72f4631 160 wxTimerRunner(wxTimer& timer, int milli, bool oneShot = false);
d14a1e28
RD
161 ~wxTimerRunner();
162
a72f4631 163 void Start(int milli, bool oneShot = false);
d14a1e28
RD
164};
165
166
167//---------------------------------------------------------------------------
313feadc
RD
168%init %{
169 wxPyPtrTypeMap_Add("wxTimer", "wxPyTimer");
170%}
171//---------------------------------------------------------------------------