]> 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
4b5a79cf 162 %pythonPrepend Destroy "args[0].this.own(False)";
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);
76b8fa1d
RD
203
204 %property(Frame, GetFrame, doc="See `GetFrame`");
205 %property(OldLog, GetOldLog, doc="See `GetOldLog`");
d14a1e28
RD
206};
207
208
209class wxLogChain : public wxLog
210{
211public:
212 wxLogChain(wxLog *logger);
213 void SetLog(wxLog *logger);
214 void PassMessages(bool bDoPass);
215 bool IsPassingMessages();
216 wxLog *GetOldLog();
76b8fa1d
RD
217
218 %property(OldLog, GetOldLog, doc="See `GetOldLog`");
d14a1e28
RD
219};
220
93649c2c
RD
221// log everything to a buffer
222class wxLogBuffer : public wxLog
223{
224public:
225 wxLogBuffer();
226
227 // get the string contents with all messages logged
76b8fa1d 228 const wxString& GetBuffer() const;
93649c2c
RD
229
230 // show the buffer contents to the user in the best possible way (this uses
231 // wxMessageOutputMessageBox) and clear it
232 virtual void Flush();
76b8fa1d
RD
233
234 %property(Buffer, GetBuffer, doc="See `GetBuffer`");
93649c2c
RD
235};
236
d14a1e28
RD
237
238//---------------------------------------------------------------------------
239
240unsigned long wxSysErrorCode();
241const wxString wxSysErrorMsg(unsigned long nErrCode = 0);
4e819f10 242
214c4fbe 243%{// Make some wrappers that double any % signs so they are 'escaped'
4e819f10
RD
244 void wxPyLogFatalError(const wxString& msg)
245 {
246 wxString m(msg);
247 m.Replace(wxT("%"), wxT("%%"));
248 wxLogFatalError(m);
249 }
250
251 void wxPyLogError(const wxString& msg)
252 {
253 wxString m(msg);
254 m.Replace(wxT("%"), wxT("%%"));
255 wxLogError(m);
256 }
257
258 void wxPyLogWarning(const wxString& msg)
259 {
260 wxString m(msg);
261 m.Replace(wxT("%"), wxT("%%"));
262 wxLogWarning(m);
263 }
264
265 void wxPyLogMessage(const wxString& msg)
266 {
267 wxString m(msg);
268 m.Replace(wxT("%"), wxT("%%"));
269 wxLogMessage(m);
270 }
271
272 void wxPyLogInfo(const wxString& msg)
273 {
274 wxString m(msg);
275 m.Replace(wxT("%"), wxT("%%"));
276 wxLogInfo(m);
277 }
278
279 void wxPyLogDebug(const wxString& msg)
280 {
281 wxString m(msg);
282 m.Replace(wxT("%"), wxT("%%"));
283 wxLogDebug(m);
284 }
285
286 void wxPyLogVerbose(const wxString& msg)
287 {
288 wxString m(msg);
289 m.Replace(wxT("%"), wxT("%%"));
290 wxLogVerbose(m);
291 }
292
293 void wxPyLogStatus(const wxString& msg)
294 {
295 wxString m(msg);
296 m.Replace(wxT("%"), wxT("%%"));
297 wxLogStatus(m);
298 }
299
300 void wxPyLogStatusFrame(wxFrame *pFrame, const wxString& msg)
301 {
302 wxString m(msg);
303 m.Replace(wxT("%"), wxT("%%"));
304 wxLogStatus(pFrame, m);
305 }
306
307 void wxPyLogSysError(const wxString& msg)
308 {
309 wxString m(msg);
310 m.Replace(wxT("%"), wxT("%%"));
311 wxLogSysError(m);
312 }
313
314 void wxPyLogGeneric(unsigned long level, const wxString& msg)
315 {
316 wxString m(msg);
317 m.Replace(wxT("%"), wxT("%%"));
318 wxLogGeneric(level, m);
319 }
320
321 void wxPyLogTrace(unsigned long mask, const wxString& msg)
322 {
323 wxString m(msg);
324 m.Replace(wxT("%"), wxT("%%"));
325 wxLogTrace(mask, m);
326 }
327
328 void wxPyLogTrace(const wxString& mask, const wxString& msg)
329 {
330 wxString m(msg);
331 m.Replace(wxT("%"), wxT("%%"));
332 wxLogTrace(mask, m);
333 }
334
335%}
336
1b8c7ba6
RD
337%Rename(LogFatalError, void, wxPyLogFatalError(const wxString& msg));
338%Rename(LogError, void, wxPyLogError(const wxString& msg));
339%Rename(LogWarning, void, wxPyLogWarning(const wxString& msg));
340%Rename(LogMessage, void, wxPyLogMessage(const wxString& msg));
341%Rename(LogInfo, void, wxPyLogInfo(const wxString& msg));
342%Rename(LogDebug, void, wxPyLogDebug(const wxString& msg));
343%Rename(LogVerbose, void, wxPyLogVerbose(const wxString& msg));
344%Rename(LogStatus, void, wxPyLogStatus(const wxString& msg));
345%Rename(LogStatusFrame, void, wxPyLogStatusFrame(wxFrame *pFrame, const wxString& msg));
346%Rename(LogSysError, void, wxPyLogSysError(const wxString& msg));
347
348%Rename(LogGeneric, void, wxPyLogGeneric(unsigned long level, const wxString& msg));
4e819f10
RD
349
350%nokwargs wxPyLogTrace;
1b8c7ba6
RD
351%Rename(LogTrace, void, wxPyLogTrace(unsigned long mask, const wxString& msg));
352%Rename(LogTrace, void, wxPyLogTrace(const wxString& mask, const wxString& msg));
4e819f10 353
d14a1e28
RD
354
355// wxLogFatalError helper: show the (fatal) error to the user in a safe way,
356// i.e. without using wxMessageBox() for example because it could crash
357void wxSafeShowMessage(const wxString& title, const wxString& text);
358
359
360
361// Suspress logging while an instance of this class exists
362class wxLogNull
363{
364public:
365 wxLogNull();
366 ~wxLogNull();
367};
368
369
370
371//---------------------------------------------------------------------------
372
373%{
374// A wxLog class that can be derived from in wxPython
375class wxPyLog : public wxLog {
376public:
377 wxPyLog() : wxLog() {}
378
379 virtual void DoLog(wxLogLevel level, const wxChar *szString, time_t t) {
380 bool found;
6e6b3557 381 wxPyBlock_t blocked = wxPyBeginBlockThreads();
d14a1e28
RD
382 if ((found = wxPyCBH_findCallback(m_myInst, "DoLog"))) {
383 PyObject* s = wx2PyString(szString);
384 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iOi)", level, s, t));
385 Py_DECREF(s);
386 }
da32eb53 387 wxPyEndBlockThreads(blocked);
d14a1e28
RD
388 if (! found)
389 wxLog::DoLog(level, szString, t);
390 }
391
392 virtual void DoLogString(const wxChar *szString, time_t t) {
393 bool found;
6e6b3557 394 wxPyBlock_t blocked = wxPyBeginBlockThreads();
d14a1e28
RD
395 if ((found = wxPyCBH_findCallback(m_myInst, "DoLogString"))) {
396 PyObject* s = wx2PyString(szString);
397 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oi)", s, t));
398 Py_DECREF(s);
399 }
da32eb53 400 wxPyEndBlockThreads(blocked);
d14a1e28
RD
401 if (! found)
402 wxLog::DoLogString(szString, t);
403 }
404
a7a01418 405 DEC_PYCALLBACK_VOID_(Flush);
d14a1e28
RD
406 PYPRIVATE;
407};
a7a01418 408IMP_PYCALLBACK_VOID_(wxPyLog, wxLog, Flush);
d14a1e28
RD
409%}
410
411// Now tell SWIG about it
412class wxPyLog : public wxLog {
413public:
2b9048c5 414 %pythonAppend wxPyLog "self._setCallbackInfo(self, PyLog)"
d14a1e28
RD
415
416 wxPyLog();
417
418 void _setCallbackInfo(PyObject* self, PyObject* _class);
419};
420
421//---------------------------------------------------------------------------