]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_timer.i
pi --> math.pi
[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 void wxPyTimer::Notify() {
40 bool found;
41 bool blocked = wxPyBeginBlockThreads();
42 if ((found = wxPyCBH_findCallback(m_myInst, "Notify")))
43 wxPyCBH_callCallback(m_myInst, Py_BuildValue("()"));
44 wxPyEndBlockThreads(blocked);
45 if (! found)
46 wxTimer::Notify();
47 }
48 void wxPyTimer::base_Notify() {
49 wxTimer::Notify();
50 }
51
52 %}
53
54
55
56 MustHaveApp(wxPyTimer);
57
58 %name(Timer) class wxPyTimer : public wxEvtHandler
59 {
60 public:
61 %pythonAppend wxPyTimer "self._setCallbackInfo(self, Timer, 0); self._setOORInfo(self)"
62
63
64 // if you don't call SetOwner() or provide an owner in the contstructor
65 // then you must override Notify() inorder to receive the timer
66 // notification. If the owner is set then it will get the timer
67 // notifications which can be handled with EVT_TIMER.
68 wxPyTimer(wxEvtHandler *owner=NULL, int id = -1);
69 virtual ~wxPyTimer();
70
71 void _setCallbackInfo(PyObject* self, PyObject* _class, int incref=1);
72
73 // Set the owner instance that will receive the EVT_TIMER events using the
74 // given id.
75 void SetOwner(wxEvtHandler *owner, int id = -1);
76 wxEvtHandler* GetOwner();
77
78 // start the timer: if milliseconds == -1, use the same value as for the
79 // last Start()
80 //
81 // it is now valid to call Start() multiple times: this just restarts the
82 // timer if it is already running
83 virtual bool Start(int milliseconds = -1, bool oneShot = False);
84
85 // stop the timer
86 virtual void Stop();
87
88 // override this in your wxTimer-derived class if you want to process timer
89 // messages in it, use non default ctor or SetOwner() otherwise
90 //virtual void Notify();
91
92 // return True if the timer is running
93 virtual bool IsRunning() const;
94
95 // get the (last) timer interval in the milliseconds
96 int GetInterval() const;
97
98 // return True if the timer is one shot
99 bool IsOneShot() const;
100
101 // return the timer ID
102 int GetId() const;
103
104 };
105
106
107 %pythoncode {
108 %# For backwards compatibility with 2.4
109 class PyTimer(Timer):
110 def __init__(self, notify):
111 Timer.__init__(self)
112 self.notify = notify
113
114 def Notify(self):
115 if self.notify:
116 self.notify()
117
118
119 EVT_TIMER = wx.PyEventBinder( wxEVT_TIMER, 1 )
120
121 };
122
123
124
125 class wxTimerEvent : public wxEvent
126 {
127 public:
128 wxTimerEvent(int timerid = 0, int interval = 0);
129 int GetInterval() const;
130 };
131
132
133
134 // wxTimerRunner: starts the timer in its ctor, stops in the dtor
135 MustHaveApp(wxTimerRunner);
136 class wxTimerRunner
137 {
138 public:
139 %nokwargs wxTimerRunner;
140 wxTimerRunner(wxTimer& timer);
141 wxTimerRunner(wxTimer& timer, int milli, bool oneShot = False);
142 ~wxTimerRunner();
143
144 void Start(int milli, bool oneShot = False);
145 };
146
147
148 //---------------------------------------------------------------------------
149 %init %{
150 wxPyPtrTypeMap_Add("wxTimer", "wxPyTimer");
151 %}
152 //---------------------------------------------------------------------------