redirect message from python extension

Hi,

I am facing to the problem how to redirect messages printed by Python
extension (written in C++) to the GUI.

For logging is used wx.stc.StyledTextCtrl class. They are two classes
with write() method - GMStdout and GMStderr which writes messages to
wx.stc.StyledTextCtrl in given style.

Pseudocode:

Python:

for Cext import Extension

ext = Extension(log)

C++ extension:

class Extension {

public:
Extension (PyObject *log)
{
    // redirect messages
    stdout = ???
    foo(stdout); // external c function which prints messages to stdout
}
};

Thanks for any pointer in advance...

Martin

···

--
Martin Landa <landa.martin gmail.com> * http://gama.fsv.cvut.cz/~landa *

Martin Landa wrote:

Hi,

I am facing to the problem how to redirect messages printed by Python
extension (written in C++) to the GUI.

For logging is used wx.stc.StyledTextCtrl class. They are two classes
with write() method - GMStdout and GMStderr which writes messages to
wx.stc.StyledTextCtrl in given style.

Pseudocode:

Python:

for Cext import Extension

ext = Extension(log)

C++ extension:

class Extension {

public:
Extension (PyObject *log)
{
    // redirect messages
    stdout = ???
    foo(stdout); // external c function which prints messages to stdout
}
};

Although the sys.stdout and sys.stderr start out life as file objects wrapping the process's C stdout and stderr, they don't have to stay that way, and reassigning sys.stdout does *not* reassign the C stdout. It sounds like what you want is to be able to write to whatever sys.stdout is currently set to from C code, right? If so then look at the PySys_WriteStdout API function.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!