]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_log.i
Tweaks for demos on MacOSX
[wxWidgets.git] / wxPython / src / _log.i
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: _log.i
3 // Purpose: SWIG interface stuff for wxLog
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
20 typedef unsigned long wxTraceMask;
21 typedef unsigned long wxLogLevel;
22
23
24 enum
25 {
26 wxLOG_FatalError, // program can't continue, abort immediately
27 wxLOG_Error, // a serious error, user must be informed about it
28 wxLOG_Warning, // user is normally informed about it but may be ignored
29 wxLOG_Message, // normal message (i.e. normal output of a non GUI app)
30 wxLOG_Status, // informational: might go to the status line of GUI app
31 wxLOG_Info, // informational message (a.k.a. 'Verbose')
32 wxLOG_Debug, // never shown to the user, disabled in release mode
33 wxLOG_Trace, // trace messages are also only enabled in debug mode
34 wxLOG_Progress, // used for progress indicator (not yet)
35 wxLOG_User = 100, // user defined levels start here
36 wxLOG_Max = 10000
37 };
38
39 #define wxTRACE_MemAlloc "memalloc" // trace memory allocation (new/delete)
40 #define wxTRACE_Messages "messages" // trace window messages/X callbacks
41 #define wxTRACE_ResAlloc "resalloc" // trace GDI resource allocation
42 #define wxTRACE_RefCount "refcount" // trace various ref counting operations
43 #define wxTRACE_OleCalls "ole" // OLE interface calls
44
45 #define wxTraceMemAlloc 0x0001 // trace memory allocation (new/delete)
46 #define wxTraceMessages 0x0002 // trace window messages/X callbacks
47 #define wxTraceResAlloc 0x0004 // trace GDI resource allocation
48 #define wxTraceRefCount 0x0008 // trace various ref counting operations
49 #define wxTraceOleCalls 0x0100 // OLE interface calls
50
51 //---------------------------------------------------------------------------
52
53 class wxLog
54 {
55 public:
56 wxLog();
57 ~wxLog();
58
59 // these functions allow to completely disable all log messages
60 // is logging disabled now?
61 static bool IsEnabled();
62
63 // change the flag state, return the previous one
64 static bool EnableLogging(bool doIt = true);
65
66 // static sink function
67 static void OnLog(wxLogLevel level, const wxChar *szString, time_t t);
68
69 // message buffering
70 // flush shows all messages if they're not logged immediately (FILE
71 // and iostream logs don't need it, but wxGuiLog does to avoid showing
72 // 17 modal dialogs one after another)
73 virtual void Flush();
74
75 // flush the active target if any
76 static void FlushActive();
77
78 // only one sink is active at each moment
79 // get current log target, will call wxApp::CreateLogTarget() to
80 // create one if none exists
81 static wxLog *GetActiveTarget();
82
83 %disownarg( wxLog* pLogger );
84 %newobject SetActiveTarget;
85 // change log target, pLogger may be NULL
86 static wxLog *SetActiveTarget(wxLog *pLogger);
87 %cleardisown( wxLog* pLogger );
88
89 // suspend the message flushing of the main target until the next call
90 // to Resume() - this is mainly for internal use (to prevent wxYield()
91 // from flashing the messages)
92 static void Suspend();
93
94 // must be called for each Suspend()!
95 static void Resume();
96
97
98 // verbose mode is activated by standard command-line '-verbose'
99 // option
100 static void SetVerbose(bool bVerbose = true);
101
102 // Set log level. Log messages with level > logLevel will not be logged.
103 static void SetLogLevel(wxLogLevel logLevel);
104
105 // should GetActiveTarget() try to create a new log object if the
106 // current is NULL?
107 static void DontCreateOnDemand();
108
109 // trace mask (see wxTraceXXX constants for details)
110 static void SetTraceMask(wxTraceMask ulMask);
111
112 // add string trace mask
113 static void AddTraceMask(const wxString& str);
114
115 // remove string trace mask
116 static void RemoveTraceMask(const wxString& str);
117
118 // remove all string trace masks
119 static void ClearTraceMasks();
120
121 // get string trace masks
122 static const wxArrayString &GetTraceMasks();
123
124 // sets the timestamp string: this is used as strftime() format string
125 // for the log targets which add time stamps to the messages - set it
126 // to NULL to disable time stamping completely.
127 static void SetTimestamp(const wxChar *ts);
128
129
130 // gets the verbose status
131 static bool GetVerbose();
132
133 // get trace mask
134 static wxTraceMask GetTraceMask();
135
136 // is this trace mask in the list?
137 static bool IsAllowedTraceMask(const wxChar *mask);
138
139 // return the current loglevel limit
140 static wxLogLevel GetLogLevel();
141
142
143 // get the current timestamp format string (may be NULL)
144 static const wxChar *GetTimestamp();
145
146
147 %extend {
148 static wxString TimeStamp() {
149 wxString msg;
150 wxLog::TimeStamp(&msg);
151 return msg;
152 }
153 }
154
155 %pythonAppend Destroy "args[0].thisown = 0";
156 %extend { void Destroy() { delete self; } }
157 };
158
159
160 //---------------------------------------------------------------------------
161
162
163 class wxLogStderr : public wxLog
164 {
165 public:
166 wxLogStderr(/* TODO: FILE *fp = (FILE *) NULL*/);
167 };
168
169
170 class wxLogTextCtrl : public wxLog
171 {
172 public:
173 wxLogTextCtrl(wxTextCtrl *pTextCtrl);
174 };
175
176
177 class wxLogGui : public wxLog
178 {
179 public:
180 wxLogGui();
181 };
182
183 class wxLogWindow : public wxLog
184 {
185 public:
186 wxLogWindow(wxFrame *pParent, // the parent frame (can be NULL)
187 const wxString& szTitle, // the title of the frame
188 bool bShow = true, // show window immediately?
189 bool bPassToOld = true); // pass log messages to the old target?
190
191 void Show(bool bShow = true);
192 wxFrame *GetFrame() const;
193 wxLog *GetOldLog() const;
194 bool IsPassingMessages() const;
195 void PassMessages(bool bDoPass);
196 };
197
198
199 class wxLogChain : public wxLog
200 {
201 public:
202 wxLogChain(wxLog *logger);
203 void SetLog(wxLog *logger);
204 void PassMessages(bool bDoPass);
205 bool IsPassingMessages();
206 wxLog *GetOldLog();
207 };
208
209 // log everything to a buffer
210 class wxLogBuffer : public wxLog
211 {
212 public:
213 wxLogBuffer();
214
215 // get the string contents with all messages logged
216 const wxString& GetBuffer() const { return m_str; }
217
218 // show the buffer contents to the user in the best possible way (this uses
219 // wxMessageOutputMessageBox) and clear it
220 virtual void Flush();
221 };
222
223
224 //---------------------------------------------------------------------------
225
226 unsigned long wxSysErrorCode();
227 const wxString wxSysErrorMsg(unsigned long nErrCode = 0);
228
229 %{// Make some wrappers that double any % signs so they are 'escaped'
230 void wxPyLogFatalError(const wxString& msg)
231 {
232 wxString m(msg);
233 m.Replace(wxT("%"), wxT("%%"));
234 wxLogFatalError(m);
235 }
236
237 void wxPyLogError(const wxString& msg)
238 {
239 wxString m(msg);
240 m.Replace(wxT("%"), wxT("%%"));
241 wxLogError(m);
242 }
243
244 void wxPyLogWarning(const wxString& msg)
245 {
246 wxString m(msg);
247 m.Replace(wxT("%"), wxT("%%"));
248 wxLogWarning(m);
249 }
250
251 void wxPyLogMessage(const wxString& msg)
252 {
253 wxString m(msg);
254 m.Replace(wxT("%"), wxT("%%"));
255 wxLogMessage(m);
256 }
257
258 void wxPyLogInfo(const wxString& msg)
259 {
260 wxString m(msg);
261 m.Replace(wxT("%"), wxT("%%"));
262 wxLogInfo(m);
263 }
264
265 void wxPyLogDebug(const wxString& msg)
266 {
267 wxString m(msg);
268 m.Replace(wxT("%"), wxT("%%"));
269 wxLogDebug(m);
270 }
271
272 void wxPyLogVerbose(const wxString& msg)
273 {
274 wxString m(msg);
275 m.Replace(wxT("%"), wxT("%%"));
276 wxLogVerbose(m);
277 }
278
279 void wxPyLogStatus(const wxString& msg)
280 {
281 wxString m(msg);
282 m.Replace(wxT("%"), wxT("%%"));
283 wxLogStatus(m);
284 }
285
286 void wxPyLogStatusFrame(wxFrame *pFrame, const wxString& msg)
287 {
288 wxString m(msg);
289 m.Replace(wxT("%"), wxT("%%"));
290 wxLogStatus(pFrame, m);
291 }
292
293 void wxPyLogSysError(const wxString& msg)
294 {
295 wxString m(msg);
296 m.Replace(wxT("%"), wxT("%%"));
297 wxLogSysError(m);
298 }
299
300 void wxPyLogGeneric(unsigned long level, const wxString& msg)
301 {
302 wxString m(msg);
303 m.Replace(wxT("%"), wxT("%%"));
304 wxLogGeneric(level, m);
305 }
306
307 void wxPyLogTrace(unsigned long mask, const wxString& msg)
308 {
309 wxString m(msg);
310 m.Replace(wxT("%"), wxT("%%"));
311 wxLogTrace(mask, m);
312 }
313
314 void wxPyLogTrace(const wxString& mask, const wxString& msg)
315 {
316 wxString m(msg);
317 m.Replace(wxT("%"), wxT("%%"));
318 wxLogTrace(mask, m);
319 }
320
321 %}
322
323 %Rename(LogFatalError, void, wxPyLogFatalError(const wxString& msg));
324 %Rename(LogError, void, wxPyLogError(const wxString& msg));
325 %Rename(LogWarning, void, wxPyLogWarning(const wxString& msg));
326 %Rename(LogMessage, void, wxPyLogMessage(const wxString& msg));
327 %Rename(LogInfo, void, wxPyLogInfo(const wxString& msg));
328 %Rename(LogDebug, void, wxPyLogDebug(const wxString& msg));
329 %Rename(LogVerbose, void, wxPyLogVerbose(const wxString& msg));
330 %Rename(LogStatus, void, wxPyLogStatus(const wxString& msg));
331 %Rename(LogStatusFrame, void, wxPyLogStatusFrame(wxFrame *pFrame, const wxString& msg));
332 %Rename(LogSysError, void, wxPyLogSysError(const wxString& msg));
333
334 %Rename(LogGeneric, void, wxPyLogGeneric(unsigned long level, const wxString& msg));
335
336 %nokwargs wxPyLogTrace;
337 %Rename(LogTrace, void, wxPyLogTrace(unsigned long mask, const wxString& msg));
338 %Rename(LogTrace, void, wxPyLogTrace(const wxString& mask, const wxString& msg));
339
340
341 // wxLogFatalError helper: show the (fatal) error to the user in a safe way,
342 // i.e. without using wxMessageBox() for example because it could crash
343 void wxSafeShowMessage(const wxString& title, const wxString& text);
344
345
346
347 // Suspress logging while an instance of this class exists
348 class wxLogNull
349 {
350 public:
351 wxLogNull();
352 ~wxLogNull();
353 };
354
355
356
357 //---------------------------------------------------------------------------
358
359 %{
360 // A wxLog class that can be derived from in wxPython
361 class wxPyLog : public wxLog {
362 public:
363 wxPyLog() : wxLog() {}
364
365 virtual void DoLog(wxLogLevel level, const wxChar *szString, time_t t) {
366 bool found;
367 wxPyBlock_t blocked = wxPyBeginBlockThreads();
368 if ((found = wxPyCBH_findCallback(m_myInst, "DoLog"))) {
369 PyObject* s = wx2PyString(szString);
370 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iOi)", level, s, t));
371 Py_DECREF(s);
372 }
373 wxPyEndBlockThreads(blocked);
374 if (! found)
375 wxLog::DoLog(level, szString, t);
376 }
377
378 virtual void DoLogString(const wxChar *szString, time_t t) {
379 bool found;
380 wxPyBlock_t blocked = wxPyBeginBlockThreads();
381 if ((found = wxPyCBH_findCallback(m_myInst, "DoLogString"))) {
382 PyObject* s = wx2PyString(szString);
383 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oi)", s, t));
384 Py_DECREF(s);
385 }
386 wxPyEndBlockThreads(blocked);
387 if (! found)
388 wxLog::DoLogString(szString, t);
389 }
390
391 DEC_PYCALLBACK_VOID_(Flush);
392 PYPRIVATE;
393 };
394 IMP_PYCALLBACK_VOID_(wxPyLog, wxLog, Flush);
395 %}
396
397 // Now tell SWIG about it
398 class wxPyLog : public wxLog {
399 public:
400 %pythonAppend wxPyLog "self._setCallbackInfo(self, PyLog)"
401
402 wxPyLog();
403
404 void _setCallbackInfo(PyObject* self, PyObject* _class);
405 };
406
407 //---------------------------------------------------------------------------