X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/d14a1e28567de23c586bc80017073d0c39f8d18f..6f67d53729164f54dd65540d4622eee47d47c6fe:/wxPython/src/_log.i diff --git a/wxPython/src/_log.i b/wxPython/src/_log.i index 57ccf8c5b0..f02fdb8467 100644 --- a/wxPython/src/_log.i +++ b/wxPython/src/_log.i @@ -54,14 +54,14 @@ class wxLog { public: wxLog(); - + ~wxLog(); // these functions allow to completely disable all log messages // is logging disabled now? static bool IsEnabled(); // change the flag state, return the previous one - static bool EnableLogging(bool doIt = TRUE); + static bool EnableLogging(bool doIt = true); // static sink function static void OnLog(wxLogLevel level, const wxChar *szString, time_t t); @@ -80,9 +80,12 @@ public: // create one if none exists static wxLog *GetActiveTarget(); + %disownarg( wxLog* pLogger ); + %newobject SetActiveTarget; // change log target, pLogger may be NULL static wxLog *SetActiveTarget(wxLog *pLogger); - + %cleardisown( wxLog* pLogger ); + // suspend the message flushing of the main target until the next call // to Resume() - this is mainly for internal use (to prevent wxYield() // from flashing the messages) @@ -94,7 +97,7 @@ public: // verbose mode is activated by standard command-line '-verbose' // option - static void SetVerbose(bool bVerbose = TRUE); + static void SetVerbose(bool bVerbose = true); // Set log level. Log messages with level > logLevel will not be logged. static void SetLogLevel(wxLogLevel logLevel); @@ -103,6 +106,13 @@ public: // current is NULL? static void DontCreateOnDemand(); + // log the count of repeating messages instead of logging the messages + // multiple times + static void SetRepetitionCounting(bool bRepetCounting = true); + + // gets duplicate counting status + static bool GetRepetitionCounting(); + // trace mask (see wxTraceXXX constants for details) static void SetTraceMask(wxTraceMask ulMask); @@ -149,6 +159,7 @@ public: } } + %pythonAppend Destroy "args[0].thisown = 0"; %extend { void Destroy() { delete self; } } }; @@ -181,14 +192,17 @@ class wxLogWindow : public wxLog public: wxLogWindow(wxFrame *pParent, // the parent frame (can be NULL) const wxString& szTitle, // the title of the frame - bool bShow = TRUE, // show window immediately? - bool bPassToOld = TRUE); // pass log messages to the old target? + bool bShow = true, // show window immediately? + bool bPassToOld = true); // pass log messages to the old target? - void Show(bool bShow = TRUE); + void Show(bool bShow = true); wxFrame *GetFrame() const; wxLog *GetOldLog() const; bool IsPassingMessages() const; void PassMessages(bool bDoPass); + + %property(Frame, GetFrame, doc="See `GetFrame`"); + %property(OldLog, GetOldLog, doc="See `GetOldLog`"); }; @@ -200,6 +214,24 @@ public: void PassMessages(bool bDoPass); bool IsPassingMessages(); wxLog *GetOldLog(); + + %property(OldLog, GetOldLog, doc="See `GetOldLog`"); +}; + +// log everything to a buffer +class wxLogBuffer : public wxLog +{ +public: + wxLogBuffer(); + + // get the string contents with all messages logged + const wxString& GetBuffer() const; + + // show the buffer contents to the user in the best possible way (this uses + // wxMessageOutputMessageBox) and clear it + virtual void Flush(); + + %property(Buffer, GetBuffer, doc="See `GetBuffer`"); }; @@ -207,21 +239,118 @@ public: unsigned long wxSysErrorCode(); const wxString wxSysErrorMsg(unsigned long nErrCode = 0); -void wxLogFatalError(const wxString& msg); -void wxLogError(const wxString& msg); -void wxLogWarning(const wxString& msg); -void wxLogMessage(const wxString& msg); -void wxLogInfo(const wxString& msg); -void wxLogDebug(const wxString& msg); -void wxLogVerbose(const wxString& msg); -void wxLogStatus(const wxString& msg); -%name(LogStatusFrame)void wxLogStatus(wxFrame *pFrame, const wxString& msg); -void wxLogSysError(const wxString& msg); - -void wxLogTrace(const wxString& msg); -%name(LogTraceMask)void wxLogTrace(const wxString& mask, const wxString& msg); - -void wxLogGeneric(unsigned long level, const wxString& msg); + +%{// Make some wrappers that double any % signs so they are 'escaped' + void wxPyLogFatalError(const wxString& msg) + { + wxString m(msg); + m.Replace(wxT("%"), wxT("%%")); + wxLogFatalError(m); + } + + void wxPyLogError(const wxString& msg) + { + wxString m(msg); + m.Replace(wxT("%"), wxT("%%")); + wxLogError(m); + } + + void wxPyLogWarning(const wxString& msg) + { + wxString m(msg); + m.Replace(wxT("%"), wxT("%%")); + wxLogWarning(m); + } + + void wxPyLogMessage(const wxString& msg) + { + wxString m(msg); + m.Replace(wxT("%"), wxT("%%")); + wxLogMessage(m); + } + + void wxPyLogInfo(const wxString& msg) + { + wxString m(msg); + m.Replace(wxT("%"), wxT("%%")); + wxLogInfo(m); + } + + void wxPyLogDebug(const wxString& msg) + { + wxString m(msg); + m.Replace(wxT("%"), wxT("%%")); + wxLogDebug(m); + } + + void wxPyLogVerbose(const wxString& msg) + { + wxString m(msg); + m.Replace(wxT("%"), wxT("%%")); + wxLogVerbose(m); + } + + void wxPyLogStatus(const wxString& msg) + { + wxString m(msg); + m.Replace(wxT("%"), wxT("%%")); + wxLogStatus(m); + } + + void wxPyLogStatusFrame(wxFrame *pFrame, const wxString& msg) + { + wxString m(msg); + m.Replace(wxT("%"), wxT("%%")); + wxLogStatus(pFrame, m); + } + + void wxPyLogSysError(const wxString& msg) + { + wxString m(msg); + m.Replace(wxT("%"), wxT("%%")); + wxLogSysError(m); + } + + void wxPyLogGeneric(unsigned long level, const wxString& msg) + { + wxString m(msg); + m.Replace(wxT("%"), wxT("%%")); + wxLogGeneric(level, m); + } + + void wxPyLogTrace(unsigned long mask, const wxString& msg) + { + wxString m(msg); + m.Replace(wxT("%"), wxT("%%")); + wxLogTrace(mask, m); + } + + void wxPyLogTrace(const wxString& mask, const wxString& msg) + { + wxString m(msg); + m.Replace(wxT("%"), wxT("%%")); + wxLogTrace(mask, m); + } + +%} + +%Rename(LogFatalError, void, wxPyLogFatalError(const wxString& msg)); +%Rename(LogError, void, wxPyLogError(const wxString& msg)); +%Rename(LogWarning, void, wxPyLogWarning(const wxString& msg)); +%Rename(LogMessage, void, wxPyLogMessage(const wxString& msg)); +%Rename(LogInfo, void, wxPyLogInfo(const wxString& msg)); +%Rename(LogDebug, void, wxPyLogDebug(const wxString& msg)); +%Rename(LogVerbose, void, wxPyLogVerbose(const wxString& msg)); +%Rename(LogStatus, void, wxPyLogStatus(const wxString& msg)); +%Rename(LogStatusFrame, void, wxPyLogStatusFrame(wxFrame *pFrame, const wxString& msg)); +%Rename(LogSysError, void, wxPyLogSysError(const wxString& msg)); + +%Rename(LogGeneric, void, wxPyLogGeneric(unsigned long level, const wxString& msg)); + +%nokwargs wxPyLogTrace; +%Rename(LogTrace, void, wxPyLogTrace(unsigned long mask, const wxString& msg)); +%Rename(LogTrace, void, wxPyLogTrace(const wxString& mask, const wxString& msg)); + // wxLogFatalError helper: show the (fatal) error to the user in a safe way, // i.e. without using wxMessageBox() for example because it could crash @@ -249,38 +378,40 @@ public: virtual void DoLog(wxLogLevel level, const wxChar *szString, time_t t) { bool found; - wxPyBeginBlockThreads(); + wxPyBlock_t blocked = wxPyBeginBlockThreads(); if ((found = wxPyCBH_findCallback(m_myInst, "DoLog"))) { PyObject* s = wx2PyString(szString); wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iOi)", level, s, t)); Py_DECREF(s); } - wxPyEndBlockThreads(); + wxPyEndBlockThreads(blocked); if (! found) wxLog::DoLog(level, szString, t); } virtual void DoLogString(const wxChar *szString, time_t t) { bool found; - wxPyBeginBlockThreads(); + wxPyBlock_t blocked = wxPyBeginBlockThreads(); if ((found = wxPyCBH_findCallback(m_myInst, "DoLogString"))) { PyObject* s = wx2PyString(szString); wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oi)", s, t)); Py_DECREF(s); } - wxPyEndBlockThreads(); + wxPyEndBlockThreads(blocked); if (! found) wxLog::DoLogString(szString, t); } + DEC_PYCALLBACK_VOID_(Flush); PYPRIVATE; }; +IMP_PYCALLBACK_VOID_(wxPyLog, wxLog, Flush); %} // Now tell SWIG about it class wxPyLog : public wxLog { public: - %addtofunc wxPyLog "self._setCallbackInfo(self, PyLog)" + %pythonAppend wxPyLog "self._setCallbackInfo(self, PyLog)" wxPyLog();