]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/_log.i
Changes to how overridable C++ methods are virtualized for Python.
[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
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
214c4fbe 155 %pythonAppend Destroy "args[0].thisown = 0";
d14a1e28 156 %extend { void Destroy() { delete self; } }
a7a01418
RD
157
158 void DoLog(wxLogLevel level, const wxChar *szString, long t);
159 void DoLogString(const wxChar *szString, long t);
d14a1e28
RD
160};
161
162
163//---------------------------------------------------------------------------
164
165
166class wxLogStderr : public wxLog
167{
168public:
169 wxLogStderr(/* TODO: FILE *fp = (FILE *) NULL*/);
170};
171
172
173class wxLogTextCtrl : public wxLog
174{
175public:
176 wxLogTextCtrl(wxTextCtrl *pTextCtrl);
177};
178
179
180class wxLogGui : public wxLog
181{
182public:
183 wxLogGui();
184};
185
186class wxLogWindow : public wxLog
187{
188public:
189 wxLogWindow(wxFrame *pParent, // the parent frame (can be NULL)
190 const wxString& szTitle, // the title of the frame
a72f4631
RD
191 bool bShow = true, // show window immediately?
192 bool bPassToOld = true); // pass log messages to the old target?
d14a1e28 193
a72f4631 194 void Show(bool bShow = true);
d14a1e28
RD
195 wxFrame *GetFrame() const;
196 wxLog *GetOldLog() const;
197 bool IsPassingMessages() const;
198 void PassMessages(bool bDoPass);
199};
200
201
202class wxLogChain : public wxLog
203{
204public:
205 wxLogChain(wxLog *logger);
206 void SetLog(wxLog *logger);
207 void PassMessages(bool bDoPass);
208 bool IsPassingMessages();
209 wxLog *GetOldLog();
210};
211
93649c2c
RD
212// log everything to a buffer
213class wxLogBuffer : public wxLog
214{
215public:
216 wxLogBuffer();
217
218 // get the string contents with all messages logged
219 const wxString& GetBuffer() const { return m_str; }
220
221 // show the buffer contents to the user in the best possible way (this uses
222 // wxMessageOutputMessageBox) and clear it
223 virtual void Flush();
224};
225
d14a1e28
RD
226
227//---------------------------------------------------------------------------
228
229unsigned long wxSysErrorCode();
230const wxString wxSysErrorMsg(unsigned long nErrCode = 0);
4e819f10 231
214c4fbe 232%{// Make some wrappers that double any % signs so they are 'escaped'
4e819f10
RD
233 void wxPyLogFatalError(const wxString& msg)
234 {
235 wxString m(msg);
236 m.Replace(wxT("%"), wxT("%%"));
237 wxLogFatalError(m);
238 }
239
240 void wxPyLogError(const wxString& msg)
241 {
242 wxString m(msg);
243 m.Replace(wxT("%"), wxT("%%"));
244 wxLogError(m);
245 }
246
247 void wxPyLogWarning(const wxString& msg)
248 {
249 wxString m(msg);
250 m.Replace(wxT("%"), wxT("%%"));
251 wxLogWarning(m);
252 }
253
254 void wxPyLogMessage(const wxString& msg)
255 {
256 wxString m(msg);
257 m.Replace(wxT("%"), wxT("%%"));
258 wxLogMessage(m);
259 }
260
261 void wxPyLogInfo(const wxString& msg)
262 {
263 wxString m(msg);
264 m.Replace(wxT("%"), wxT("%%"));
265 wxLogInfo(m);
266 }
267
268 void wxPyLogDebug(const wxString& msg)
269 {
270 wxString m(msg);
271 m.Replace(wxT("%"), wxT("%%"));
272 wxLogDebug(m);
273 }
274
275 void wxPyLogVerbose(const wxString& msg)
276 {
277 wxString m(msg);
278 m.Replace(wxT("%"), wxT("%%"));
279 wxLogVerbose(m);
280 }
281
282 void wxPyLogStatus(const wxString& msg)
283 {
284 wxString m(msg);
285 m.Replace(wxT("%"), wxT("%%"));
286 wxLogStatus(m);
287 }
288
289 void wxPyLogStatusFrame(wxFrame *pFrame, const wxString& msg)
290 {
291 wxString m(msg);
292 m.Replace(wxT("%"), wxT("%%"));
293 wxLogStatus(pFrame, m);
294 }
295
296 void wxPyLogSysError(const wxString& msg)
297 {
298 wxString m(msg);
299 m.Replace(wxT("%"), wxT("%%"));
300 wxLogSysError(m);
301 }
302
303 void wxPyLogGeneric(unsigned long level, const wxString& msg)
304 {
305 wxString m(msg);
306 m.Replace(wxT("%"), wxT("%%"));
307 wxLogGeneric(level, m);
308 }
309
310 void wxPyLogTrace(unsigned long mask, const wxString& msg)
311 {
312 wxString m(msg);
313 m.Replace(wxT("%"), wxT("%%"));
314 wxLogTrace(mask, m);
315 }
316
317 void wxPyLogTrace(const wxString& mask, const wxString& msg)
318 {
319 wxString m(msg);
320 m.Replace(wxT("%"), wxT("%%"));
321 wxLogTrace(mask, m);
322 }
323
324%}
325
1b8c7ba6
RD
326%Rename(LogFatalError, void, wxPyLogFatalError(const wxString& msg));
327%Rename(LogError, void, wxPyLogError(const wxString& msg));
328%Rename(LogWarning, void, wxPyLogWarning(const wxString& msg));
329%Rename(LogMessage, void, wxPyLogMessage(const wxString& msg));
330%Rename(LogInfo, void, wxPyLogInfo(const wxString& msg));
331%Rename(LogDebug, void, wxPyLogDebug(const wxString& msg));
332%Rename(LogVerbose, void, wxPyLogVerbose(const wxString& msg));
333%Rename(LogStatus, void, wxPyLogStatus(const wxString& msg));
334%Rename(LogStatusFrame, void, wxPyLogStatusFrame(wxFrame *pFrame, const wxString& msg));
335%Rename(LogSysError, void, wxPyLogSysError(const wxString& msg));
336
337%Rename(LogGeneric, void, wxPyLogGeneric(unsigned long level, const wxString& msg));
4e819f10
RD
338
339%nokwargs wxPyLogTrace;
1b8c7ba6
RD
340%Rename(LogTrace, void, wxPyLogTrace(unsigned long mask, const wxString& msg));
341%Rename(LogTrace, void, wxPyLogTrace(const wxString& mask, const wxString& msg));
4e819f10 342
d14a1e28
RD
343
344// wxLogFatalError helper: show the (fatal) error to the user in a safe way,
345// i.e. without using wxMessageBox() for example because it could crash
346void wxSafeShowMessage(const wxString& title, const wxString& text);
347
348
349
350// Suspress logging while an instance of this class exists
351class wxLogNull
352{
353public:
354 wxLogNull();
355 ~wxLogNull();
356};
357
358
359
360//---------------------------------------------------------------------------
361
362%{
363// A wxLog class that can be derived from in wxPython
364class wxPyLog : public wxLog {
365public:
366 wxPyLog() : wxLog() {}
367
368 virtual void DoLog(wxLogLevel level, const wxChar *szString, time_t t) {
369 bool found;
6e6b3557 370 wxPyBlock_t blocked = wxPyBeginBlockThreads();
d14a1e28
RD
371 if ((found = wxPyCBH_findCallback(m_myInst, "DoLog"))) {
372 PyObject* s = wx2PyString(szString);
373 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iOi)", level, s, t));
374 Py_DECREF(s);
375 }
da32eb53 376 wxPyEndBlockThreads(blocked);
d14a1e28
RD
377 if (! found)
378 wxLog::DoLog(level, szString, t);
379 }
380
381 virtual void DoLogString(const wxChar *szString, time_t t) {
382 bool found;
6e6b3557 383 wxPyBlock_t blocked = wxPyBeginBlockThreads();
d14a1e28
RD
384 if ((found = wxPyCBH_findCallback(m_myInst, "DoLogString"))) {
385 PyObject* s = wx2PyString(szString);
386 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oi)", s, t));
387 Py_DECREF(s);
388 }
da32eb53 389 wxPyEndBlockThreads(blocked);
d14a1e28
RD
390 if (! found)
391 wxLog::DoLogString(szString, t);
392 }
393
a7a01418 394 DEC_PYCALLBACK_VOID_(Flush);
d14a1e28
RD
395 PYPRIVATE;
396};
a7a01418 397IMP_PYCALLBACK_VOID_(wxPyLog, wxLog, Flush);
d14a1e28
RD
398%}
399
400// Now tell SWIG about it
401class wxPyLog : public wxLog {
402public:
2b9048c5 403 %pythonAppend wxPyLog "self._setCallbackInfo(self, PyLog)"
d14a1e28
RD
404
405 wxPyLog();
406
407 void _setCallbackInfo(PyObject* self, PyObject* _class);
408};
409
410//---------------------------------------------------------------------------