Quantcast

redirect message from python extension

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

redirect message from python extension

Martin Landa-2
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 *
_______________________________________________
wxpython-users mailing list
[hidden email]
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: redirect message from python extension

Robin Dunn
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!

_______________________________________________
wxpython-users mailing list
[hidden email]
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users
Loading...