]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_log.i
Change event names to clarify that they are only fired by button clicks, and note...
[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 // 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
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
162 %pythonPrepend Destroy "args[0].this.own(False)";
163 %extend { void Destroy() { delete self; } }
164 };
165
166
167 //---------------------------------------------------------------------------
168
169
170 class wxLogStderr : public wxLog
171 {
172 public:
173 wxLogStderr(/* TODO: FILE *fp = (FILE *) NULL*/);
174 };
175
176
177 class wxLogTextCtrl : public wxLog
178 {
179 public:
180 wxLogTextCtrl(wxTextCtrl *pTextCtrl);
181 };
182
183
184 class wxLogGui : public wxLog
185 {
186 public:
187 wxLogGui();
188 };
189
190 class wxLogWindow : public wxLog
191 {
192 public:
193 wxLogWindow(wxFrame *pParent, // the parent frame (can be NULL)
194 const wxString& szTitle, // the title of the frame
195 bool bShow = true, // show window immediately?
196 bool bPassToOld = true); // pass log messages to the old target?
197
198 void Show(bool bShow = true);
199 wxFrame *GetFrame() const;
200 wxLog *GetOldLog() const;
201 bool IsPassingMessages() const;
202 void PassMessages(bool bDoPass);
203
204 %property(Frame, GetFrame, doc="See `GetFrame`");
205 %property(OldLog, GetOldLog, doc="See `GetOldLog`");
206 };
207
208
209 class wxLogChain : public wxLog
210 {
211 public:
212 wxLogChain(wxLog *logger);
213 void SetLog(wxLog *logger);
214 void PassMessages(bool bDoPass);
215 bool IsPassingMessages();
216 wxLog *GetOldLog();
217
218 %property(OldLog, GetOldLog, doc="See `GetOldLog`");
219 };
220
221 // log everything to a buffer
222 class wxLogBuffer : public wxLog
223 {
224 public:
225 wxLogBuffer();
226
227 // get the string contents with all messages logged
228 const wxString& GetBuffer() const;
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();
233
234 %property(Buffer, GetBuffer, doc="See `GetBuffer`");
235 };
236
237
238 //---------------------------------------------------------------------------
239
240 unsigned long wxSysErrorCode();
241 const wxString wxSysErrorMsg(unsigned long nErrCode = 0);
242
243 %{// Make some wrappers that double any % signs so they are 'escaped'
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
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));
349
350 %nokwargs wxPyLogTrace;
351 %Rename(LogTrace, void, wxPyLogTrace(unsigned long mask, const wxString& msg));
352 %Rename(LogTrace, void, wxPyLogTrace(const wxString& mask, const wxString& msg));
353
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
357 void wxSafeShowMessage(const wxString& title, const wxString& text);
358
359
360
361 // Suspress logging while an instance of this class exists
362 class wxLogNull
363 {
364 public:
365 wxLogNull();
366 ~wxLogNull();
367 };
368
369
370
371 //---------------------------------------------------------------------------
372
373 %{
374 // A wxLog class that can be derived from in wxPython
375 class wxPyLog : public wxLog {
376 public:
377 wxPyLog() : wxLog() {}
378
379 virtual void DoLog(wxLogLevel level, const wxChar *szString, time_t t) {
380 bool found;
381 wxPyBlock_t blocked = wxPyBeginBlockThreads();
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 }
387 wxPyEndBlockThreads(blocked);
388 if (! found)
389 wxLog::DoLog(level, szString, t);
390 }
391
392 virtual void DoLogString(const wxChar *szString, time_t t) {
393 bool found;
394 wxPyBlock_t blocked = wxPyBeginBlockThreads();
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 }
400 wxPyEndBlockThreads(blocked);
401 if (! found)
402 wxLog::DoLogString(szString, t);
403 }
404
405 DEC_PYCALLBACK_VOID_(Flush);
406 PYPRIVATE;
407 };
408 IMP_PYCALLBACK_VOID_(wxPyLog, wxLog, Flush);
409 %}
410
411 // Now tell SWIG about it
412 class wxPyLog : public wxLog {
413 public:
414 %pythonAppend wxPyLog setCallbackInfo(PyLog)
415
416 wxPyLog();
417
418 void _setCallbackInfo(PyObject* self, PyObject* _class);
419 };
420
421 //---------------------------------------------------------------------------