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