Hi,
StyledTextCtrl should work. You'll need to "catch" the data streams in
some kind of variable and do some formatting to the text before sending
them on to the StyledTextCtrl though since the data will just be plain
text otherwise. Since their just strings, redirect stdout/stderr to a
variable to hold the string, do the necessary formatting and then write
the string to the StyledTextCtrl.
------
I have done something similar to this. It may be used as a replacement of
the std log window wxPython offers.
If I recall correctly the sys.stdout msgs are in blue, sys.stderr msgs are
in red and so on. Can be easily extended.
http://spinecho.ze.cx/ > frmouterr-py251-wxpy2842.zip
Jean-Michel Fauth, Switzerland
thanks a lot for this example! Now I am trying to redirect
subprocess.Popen().std[out|err].
Example:
subprocess.Popen([...], stdin=None, stdout=None, stderr=GMStderr,
close_fds=True)
Based on your code:
class GMStderr:
def __init__(self, gmstc):
self.gmstc = gmstc
self.buffer = tempfile.TemporaryFile(mode="w")
def write(self, s):
# if self.gmstc.GetParent().IsShown() == False:
# self.gmstc.GetParent().Show()
s = s.replace('\n', os.linesep)
p1 = self.gmstc.GetCurrentPos()
self.gmstc.AddText(s)
self.gmstc.EnsureCaretVisible()
p2 = self.gmstc.GetCurrentPos()
self.gmstc.SetStyling(p2 - p1 + 1, self.gmstc.StyleError)
def fileno(self):
return self.buffer.fileno()
def __del__(self):
self.buffer.flush()
self.buffer.seek(0,0)
for line in self.buffer.readlines():
self.write(line)
The problem is that stderr content is printed to textwidget after the
command is executed (class destructor). I need to update textwidget
content everytime a buffer file is changed (line written)...
Thanks a lot for any hits...
Martin
···
2007/10/16, jmf <jfauth@bluewin.ch>:
--
Martin Landa <landa.martin@gmail.com> * http://gama.fsv.cvut.cz/~landa *