]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_log.i
reSWIGged
[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
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 // change log target, pLogger may be NULL
84 static wxLog *SetActiveTarget(wxLog *pLogger);
85
86 // suspend the message flushing of the main target until the next call
87 // to Resume() - this is mainly for internal use (to prevent wxYield()
88 // from flashing the messages)
89 static void Suspend();
90
91 // must be called for each Suspend()!
92 static void Resume();
93
94
95 // verbose mode is activated by standard command-line '-verbose'
96 // option
97 static void SetVerbose(bool bVerbose = true);
98
99 // Set log level. Log messages with level > logLevel will not be logged.
100 static void SetLogLevel(wxLogLevel logLevel);
101
102 // should GetActiveTarget() try to create a new log object if the
103 // current is NULL?
104 static void DontCreateOnDemand();
105
106 // trace mask (see wxTraceXXX constants for details)
107 static void SetTraceMask(wxTraceMask ulMask);
108
109 // add string trace mask
110 static void AddTraceMask(const wxString& str);
111
112 // remove string trace mask
113 static void RemoveTraceMask(const wxString& str);
114
115 // remove all string trace masks
116 static void ClearTraceMasks();
117
118 // get string trace masks
119 static const wxArrayString &GetTraceMasks();
120
121 // sets the timestamp string: this is used as strftime() format string
122 // for the log targets which add time stamps to the messages - set it
123 // to NULL to disable time stamping completely.
124 static void SetTimestamp(const wxChar *ts);
125
126
127 // gets the verbose status
128 static bool GetVerbose();
129
130 // get trace mask
131 static wxTraceMask GetTraceMask();
132
133 // is this trace mask in the list?
134 static bool IsAllowedTraceMask(const wxChar *mask);
135
136 // return the current loglevel limit
137 static wxLogLevel GetLogLevel();
138
139
140 // get the current timestamp format string (may be NULL)
141 static const wxChar *GetTimestamp();
142
143
144 %extend {
145 static wxString TimeStamp() {
146 wxString msg;
147 wxLog::TimeStamp(&msg);
148 return msg;
149 }
150 }
151
152 %extend { void Destroy() { delete self; } }
153 };
154
155
156 //---------------------------------------------------------------------------
157
158
159 class wxLogStderr : public wxLog
160 {
161 public:
162 wxLogStderr(/* TODO: FILE *fp = (FILE *) NULL*/);
163 };
164
165
166 class wxLogTextCtrl : public wxLog
167 {
168 public:
169 wxLogTextCtrl(wxTextCtrl *pTextCtrl);
170 };
171
172
173 class wxLogGui : public wxLog
174 {
175 public:
176 wxLogGui();
177 };
178
179 class wxLogWindow : public wxLog
180 {
181 public:
182 wxLogWindow(wxFrame *pParent, // the parent frame (can be NULL)
183 const wxString& szTitle, // the title of the frame
184 bool bShow = true, // show window immediately?
185 bool bPassToOld = true); // pass log messages to the old target?
186
187 void Show(bool bShow = true);
188 wxFrame *GetFrame() const;
189 wxLog *GetOldLog() const;
190 bool IsPassingMessages() const;
191 void PassMessages(bool bDoPass);
192 };
193
194
195 class wxLogChain : public wxLog
196 {
197 public:
198 wxLogChain(wxLog *logger);
199 void SetLog(wxLog *logger);
200 void PassMessages(bool bDoPass);
201 bool IsPassingMessages();
202 wxLog *GetOldLog();
203 };
204
205
206 //---------------------------------------------------------------------------
207
208 unsigned long wxSysErrorCode();
209 const wxString wxSysErrorMsg(unsigned long nErrCode = 0);
210
211 %{// Make somce wrappers that double any % signs so they are 'escaped'
212 void wxPyLogFatalError(const wxString& msg)
213 {
214 wxString m(msg);
215 m.Replace(wxT("%"), wxT("%%"));
216 wxLogFatalError(m);
217 }
218
219 void wxPyLogError(const wxString& msg)
220 {
221 wxString m(msg);
222 m.Replace(wxT("%"), wxT("%%"));
223 wxLogError(m);
224 }
225
226 void wxPyLogWarning(const wxString& msg)
227 {
228 wxString m(msg);
229 m.Replace(wxT("%"), wxT("%%"));
230 wxLogWarning(m);
231 }
232
233 void wxPyLogMessage(const wxString& msg)
234 {
235 wxString m(msg);
236 m.Replace(wxT("%"), wxT("%%"));
237 wxLogMessage(m);
238 }
239
240 void wxPyLogInfo(const wxString& msg)
241 {
242 wxString m(msg);
243 m.Replace(wxT("%"), wxT("%%"));
244 wxLogInfo(m);
245 }
246
247 void wxPyLogDebug(const wxString& msg)
248 {
249 wxString m(msg);
250 m.Replace(wxT("%"), wxT("%%"));
251 wxLogDebug(m);
252 }
253
254 void wxPyLogVerbose(const wxString& msg)
255 {
256 wxString m(msg);
257 m.Replace(wxT("%"), wxT("%%"));
258 wxLogVerbose(m);
259 }
260
261 void wxPyLogStatus(const wxString& msg)
262 {
263 wxString m(msg);
264 m.Replace(wxT("%"), wxT("%%"));
265 wxLogStatus(m);
266 }
267
268 void wxPyLogStatusFrame(wxFrame *pFrame, const wxString& msg)
269 {
270 wxString m(msg);
271 m.Replace(wxT("%"), wxT("%%"));
272 wxLogStatus(pFrame, m);
273 }
274
275 void wxPyLogSysError(const wxString& msg)
276 {
277 wxString m(msg);
278 m.Replace(wxT("%"), wxT("%%"));
279 wxLogSysError(m);
280 }
281
282 void wxPyLogGeneric(unsigned long level, const wxString& msg)
283 {
284 wxString m(msg);
285 m.Replace(wxT("%"), wxT("%%"));
286 wxLogGeneric(level, m);
287 }
288
289 void wxPyLogTrace(unsigned long mask, const wxString& msg)
290 {
291 wxString m(msg);
292 m.Replace(wxT("%"), wxT("%%"));
293 wxLogTrace(mask, m);
294 }
295
296 void wxPyLogTrace(const wxString& mask, const wxString& msg)
297 {
298 wxString m(msg);
299 m.Replace(wxT("%"), wxT("%%"));
300 wxLogTrace(mask, m);
301 }
302
303 %}
304
305 %name(LogFatalError) void wxPyLogFatalError(const wxString& msg);
306 %name(LogError) void wxPyLogError(const wxString& msg);
307 %name(LogWarning) void wxPyLogWarning(const wxString& msg);
308 %name(LogMessage) void wxPyLogMessage(const wxString& msg);
309 %name(LogInfo) void wxPyLogInfo(const wxString& msg);
310 %name(LogDebug) void wxPyLogDebug(const wxString& msg);
311 %name(LogVerbose) void wxPyLogVerbose(const wxString& msg);
312 %name(LogStatus) void wxPyLogStatus(const wxString& msg);
313 %name(LogStatusFrame) void wxPyLogStatusFrame(wxFrame *pFrame, const wxString& msg);
314 %name(LogSysError) void wxPyLogSysError(const wxString& msg);
315
316 %name(LogGeneric) void wxPyLogGeneric(unsigned long level, const wxString& msg);
317
318 %nokwargs wxPyLogTrace;
319 %name(LogTrace) void wxPyLogTrace(unsigned long mask, const wxString& msg);
320 %name(LogTrace) void wxPyLogTrace(const wxString& mask, const wxString& msg);
321
322
323 // wxLogFatalError helper: show the (fatal) error to the user in a safe way,
324 // i.e. without using wxMessageBox() for example because it could crash
325 void wxSafeShowMessage(const wxString& title, const wxString& text);
326
327
328
329 // Suspress logging while an instance of this class exists
330 class wxLogNull
331 {
332 public:
333 wxLogNull();
334 ~wxLogNull();
335 };
336
337
338
339 //---------------------------------------------------------------------------
340
341 %{
342 // A wxLog class that can be derived from in wxPython
343 class wxPyLog : public wxLog {
344 public:
345 wxPyLog() : wxLog() {}
346
347 virtual void DoLog(wxLogLevel level, const wxChar *szString, time_t t) {
348 bool found;
349 bool blocked = wxPyBeginBlockThreads();
350 if ((found = wxPyCBH_findCallback(m_myInst, "DoLog"))) {
351 PyObject* s = wx2PyString(szString);
352 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iOi)", level, s, t));
353 Py_DECREF(s);
354 }
355 wxPyEndBlockThreads(blocked);
356 if (! found)
357 wxLog::DoLog(level, szString, t);
358 }
359
360 virtual void DoLogString(const wxChar *szString, time_t t) {
361 bool found;
362 bool blocked = wxPyBeginBlockThreads();
363 if ((found = wxPyCBH_findCallback(m_myInst, "DoLogString"))) {
364 PyObject* s = wx2PyString(szString);
365 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oi)", s, t));
366 Py_DECREF(s);
367 }
368 wxPyEndBlockThreads(blocked);
369 if (! found)
370 wxLog::DoLogString(szString, t);
371 }
372
373 PYPRIVATE;
374 };
375 %}
376
377 // Now tell SWIG about it
378 class wxPyLog : public wxLog {
379 public:
380 %pythonAppend wxPyLog "self._setCallbackInfo(self, PyLog)"
381
382 wxPyLog();
383
384 void _setCallbackInfo(PyObject* self, PyObject* _class);
385 };
386
387 //---------------------------------------------------------------------------