]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/_log.i
reSWIGged
[wxWidgets.git] / wxPython / src / _log.i
CommitLineData
d14a1e28
RD
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
20typedef unsigned long wxTraceMask;
21typedef unsigned long wxLogLevel;
22
23
24enum
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
53class wxLog
54{
55public:
56 wxLog();
214c4fbe 57 ~wxLog();
d14a1e28
RD
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
a72f4631 64 static bool EnableLogging(bool doIt = true);
d14a1e28
RD
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
214c4fbe
RD
83 %disownarg( wxLog* pLogger );
84 %newobject SetActiveTarget;
d14a1e28
RD
85 // change log target, pLogger may be NULL
86 static wxLog *SetActiveTarget(wxLog *pLogger);
214c4fbe
RD
87 %cleardisown( wxLog* pLogger );
88
d14a1e28
RD
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
a72f4631 100 static void SetVerbose(bool bVerbose = true);
d14a1e28
RD
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
6aaca5ba
RD
109 // log the count of repeating messages instead of logging the messages
110 // multiple times
111 static void SetRepetitionCounting(bool bRepetCounting = true);
112
113 // gets duplicate counting status
114 static bool GetRepetitionCounting();
115
d14a1e28
RD
116 // trace mask (see wxTraceXXX constants for details)
117 static void SetTraceMask(wxTraceMask ulMask);
118
119 // add string trace mask
120 static void AddTraceMask(const wxString& str);
121
122 // remove string trace mask
123 static void RemoveTraceMask(const wxString& str);
124
125 // remove all string trace masks
126 static void ClearTraceMasks();
127
128 // get string trace masks
129 static const wxArrayString &GetTraceMasks();
130
131 // sets the timestamp string: this is used as strftime() format string
132 // for the log targets which add time stamps to the messages - set it
133 // to NULL to disable time stamping completely.
134 static void SetTimestamp(const wxChar *ts);
135
136
137 // gets the verbose status
138 static bool GetVerbose();
139
140 // get trace mask
141 static wxTraceMask GetTraceMask();
142
143 // is this trace mask in the list?
144 static bool IsAllowedTraceMask(const wxChar *mask);
145
146 // return the current loglevel limit
147 static wxLogLevel GetLogLevel();
148
149
150 // get the current timestamp format string (may be NULL)
151 static const wxChar *GetTimestamp();
152
153
154 %extend {
155 static wxString TimeStamp() {
156 wxString msg;
157 wxLog::TimeStamp(&msg);
158 return msg;
159 }
160 }
161
214c4fbe 162 %pythonAppend Destroy "args[0].thisown = 0";
d14a1e28
RD
163 %extend { void Destroy() { delete self; } }
164};
165
166
167//---------------------------------------------------------------------------
168
169
170class wxLogStderr : public wxLog
171{
172public:
173 wxLogStderr(/* TODO: FILE *fp = (FILE *) NULL*/);
174};
175
176
177class wxLogTextCtrl : public wxLog
178{
179public:
180 wxLogTextCtrl(wxTextCtrl *pTextCtrl);
181};
182
183
184class wxLogGui : public wxLog
185{
186public:
187 wxLogGui();
188};
189
190class wxLogWindow : public wxLog
191{
192public:
193 wxLogWindow(wxFrame *pParent, // the parent frame (can be NULL)
194 const wxString& szTitle, // the title of the frame
a72f4631
RD
195 bool bShow = true, // show window immediately?
196 bool bPassToOld = true); // pass log messages to the old target?
d14a1e28 197
a72f4631 198 void Show(bool bShow = true);
d14a1e28
RD
199 wxFrame *GetFrame() const;
200 wxLog *GetOldLog() const;
201 bool IsPassingMessages() const;
202 void PassMessages(bool bDoPass);
203};
204
205
206class wxLogChain : public wxLog
207{
208public:
209 wxLogChain(wxLog *logger);
210 void SetLog(wxLog *logger);
211 void PassMessages(bool bDoPass);
212 bool IsPassingMessages();
213 wxLog *GetOldLog();
214};
215
93649c2c
RD
216// log everything to a buffer
217class wxLogBuffer : public wxLog
218{
219public:
220 wxLogBuffer();
221
222 // get the string contents with all messages logged
223 const wxString& GetBuffer() const { return m_str; }
224
225 // show the buffer contents to the user in the best possible way (this uses
226 // wxMessageOutputMessageBox) and clear it
227 virtual void Flush();
228};
229
d14a1e28
RD
230
231//---------------------------------------------------------------------------
232
233unsigned long wxSysErrorCode();
234const wxString wxSysErrorMsg(unsigned long nErrCode = 0);
4e819f10 235
214c4fbe 236%{// Make some wrappers that double any % signs so they are 'escaped'
4e819f10
RD
237 void wxPyLogFatalError(const wxString& msg)
238 {
239 wxString m(msg);
240 m.Replace(wxT("%"), wxT("%%"));
241 wxLogFatalError(m);
242 }
243
244 void wxPyLogError(const wxString& msg)
245 {
246 wxString m(msg);
247 m.Replace(wxT("%"), wxT("%%"));
248 wxLogError(m);
249 }
250
251 void wxPyLogWarning(const wxString& msg)
252 {
253 wxString m(msg);
254 m.Replace(wxT("%"), wxT("%%"));
255 wxLogWarning(m);
256 }
257
258 void wxPyLogMessage(const wxString& msg)
259 {
260 wxString m(msg);
261 m.Replace(wxT("%"), wxT("%%"));
262 wxLogMessage(m);
263 }
264
265 void wxPyLogInfo(const wxString& msg)
266 {
267 wxString m(msg);
268 m.Replace(wxT("%"), wxT("%%"));
269 wxLogInfo(m);
270 }
271
272 void wxPyLogDebug(const wxString& msg)
273 {
274 wxString m(msg);
275 m.Replace(wxT("%"), wxT("%%"));
276 wxLogDebug(m);
277 }
278
279 void wxPyLogVerbose(const wxString& msg)
280 {
281 wxString m(msg);
282 m.Replace(wxT("%"), wxT("%%"));
283 wxLogVerbose(m);
284 }
285
286 void wxPyLogStatus(const wxString& msg)
287 {
288 wxString m(msg);
289 m.Replace(wxT("%"), wxT("%%"));
290 wxLogStatus(m);
291 }
292
293 void wxPyLogStatusFrame(wxFrame *pFrame, const wxString& msg)
294 {
295 wxString m(msg);
296 m.Replace(wxT("%"), wxT("%%"));
297 wxLogStatus(pFrame, m);
298 }
299
300 void wxPyLogSysError(const wxString& msg)
301 {
302 wxString m(msg);
303 m.Replace(wxT("%"), wxT("%%"));
304 wxLogSysError(m);
305 }
306
307 void wxPyLogGeneric(unsigned long level, const wxString& msg)
308 {
309 wxString m(msg);
310 m.Replace(wxT("%"), wxT("%%"));
311 wxLogGeneric(level, m);
312 }
313
314 void wxPyLogTrace(unsigned long mask, const wxString& msg)
315 {
316 wxString m(msg);
317 m.Replace(wxT("%"), wxT("%%"));
318 wxLogTrace(mask, m);
319 }
320
321 void wxPyLogTrace(const wxString& mask, const wxString& msg)
322 {
323 wxString m(msg);
324 m.Replace(wxT("%"), wxT("%%"));
325 wxLogTrace(mask, m);
326 }
327
328%}
329
1b8c7ba6
RD
330%Rename(LogFatalError, void, wxPyLogFatalError(const wxString& msg));
331%Rename(LogError, void, wxPyLogError(const wxString& msg));
332%Rename(LogWarning, void, wxPyLogWarning(const wxString& msg));
333%Rename(LogMessage, void, wxPyLogMessage(const wxString& msg));
334%Rename(LogInfo, void, wxPyLogInfo(const wxString& msg));
335%Rename(LogDebug, void, wxPyLogDebug(const wxString& msg));
336%Rename(LogVerbose, void, wxPyLogVerbose(const wxString& msg));
337%Rename(LogStatus, void, wxPyLogStatus(const wxString& msg));
338%Rename(LogStatusFrame, void, wxPyLogStatusFrame(wxFrame *pFrame, const wxString& msg));
339%Rename(LogSysError, void, wxPyLogSysError(const wxString& msg));
340
341%Rename(LogGeneric, void, wxPyLogGeneric(unsigned long level, const wxString& msg));
4e819f10
RD
342
343%nokwargs wxPyLogTrace;
1b8c7ba6
RD
344%Rename(LogTrace, void, wxPyLogTrace(unsigned long mask, const wxString& msg));
345%Rename(LogTrace, void, wxPyLogTrace(const wxString& mask, const wxString& msg));
4e819f10 346
d14a1e28
RD
347
348// wxLogFatalError helper: show the (fatal) error to the user in a safe way,
349// i.e. without using wxMessageBox() for example because it could crash
350void wxSafeShowMessage(const wxString& title, const wxString& text);
351
352
353
354// Suspress logging while an instance of this class exists
355class wxLogNull
356{
357public:
358 wxLogNull();
359 ~wxLogNull();
360};
361
362
363
364//---------------------------------------------------------------------------
365
366%{
367// A wxLog class that can be derived from in wxPython
368class wxPyLog : public wxLog {
369public:
370 wxPyLog() : wxLog() {}
371
372 virtual void DoLog(wxLogLevel level, const wxChar *szString, time_t t) {
373 bool found;
6e6b3557 374 wxPyBlock_t blocked = wxPyBeginBlockThreads();
d14a1e28
RD
375 if ((found = wxPyCBH_findCallback(m_myInst, "DoLog"))) {
376 PyObject* s = wx2PyString(szString);
377 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iOi)", level, s, t));
378 Py_DECREF(s);
379 }
da32eb53 380 wxPyEndBlockThreads(blocked);
d14a1e28
RD
381 if (! found)
382 wxLog::DoLog(level, szString, t);
383 }
384
385 virtual void DoLogString(const wxChar *szString, time_t t) {
386 bool found;
6e6b3557 387 wxPyBlock_t blocked = wxPyBeginBlockThreads();
d14a1e28
RD
388 if ((found = wxPyCBH_findCallback(m_myInst, "DoLogString"))) {
389 PyObject* s = wx2PyString(szString);
390 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oi)", s, t));
391 Py_DECREF(s);
392 }
da32eb53 393 wxPyEndBlockThreads(blocked);
d14a1e28
RD
394 if (! found)
395 wxLog::DoLogString(szString, t);
396 }
397
a7a01418 398 DEC_PYCALLBACK_VOID_(Flush);
d14a1e28
RD
399 PYPRIVATE;
400};
a7a01418 401IMP_PYCALLBACK_VOID_(wxPyLog, wxLog, Flush);
d14a1e28
RD
402%}
403
404// Now tell SWIG about it
405class wxPyLog : public wxLog {
406public:
2b9048c5 407 %pythonAppend wxPyLog "self._setCallbackInfo(self, PyLog)"
d14a1e28
RD
408
409 wxPyLog();
410
411 void _setCallbackInfo(PyObject* self, PyObject* _class);
412};
413
414//---------------------------------------------------------------------------