472,952 Members | 2,193 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,952 software developers and data experts.

wxpython: Redirect the stdout to a textctrl

Hi:

I want to redirect stdout to a textctrl I have. From what I read in
the wxpython documentation, I can use the wxLogTextCtrl class to do
this. I am doing the following:

class MyGui(gui.MyFrame): #gui.MyFrame generated by wxGlade
def __init__(self, *args, **kwds):
gui.MyFrame.__init__(self, *args, **kwds)
# ... code removed ...
wx.Log_SetActiveTarget(wx.LogTextCtrl(self.text_ct rl_2))
print 'foo' #to test the redirection

if __name__ == "__main__":
app = wx.App(redirect=wx.LogTextCtrl)
wx.InitAllImageHandlers()
gui = MyGui(None, -1, "")
app.SetTopWindow(gui)
gui.Show()
app.MainLoop()

However, the output instead of going to my textctrl, goes to a new
window named "xwPython: stdout/stderr".

What am I missing?

Jun 19 '07 #1
3 6070
On Jun 19, 3:16 pm, Alejandro <alejandro.weinst...@gmail.comwrote:
Hi:

I want to redirect stdout to a textctrl I have. From what I read in
the wxpython documentation, I can use the wxLogTextCtrl class to do
this. I am doing the following:

class MyGui(gui.MyFrame): #gui.MyFrame generated by wxGlade
def __init__(self, *args, **kwds):
gui.MyFrame.__init__(self, *args, **kwds)
# ... code removed ...
wx.Log_SetActiveTarget(wx.LogTextCtrl(self.text_ct rl_2))
print 'foo' #to test the redirection

if __name__ == "__main__":
app = wx.App(redirect=wx.LogTextCtrl)
wx.InitAllImageHandlers()
gui = MyGui(None, -1, "")
app.SetTopWindow(gui)
gui.Show()
app.MainLoop()

However, the output instead of going to my textctrl, goes to a new
window named "xwPython: stdout/stderr".

What am I missing?
Give this a try:

<code>

class XPinst(wx.App):
def __init__(self, redirect=False, filename=None):
wx.App.__init__(self, redirect, filename)

def OnInit(self):
self.frame = wx.Frame(None, -1, title='Redirect Test',
size=(620,450),
style=wx.STAY_ON_TOP|
wx.DEFAULT_FRAME_STYLE)

panel = wx.Panel(self.frame, -1)

self.log = wx.TextCtrl(panel, -1, size=(500,400),
style = wx.TE_MULTILINE|wx.TE_READONLY|
wx.HSCROLL)
redir=RedirectText(self.log)
sys.stdout=redir
print 'test'

self.frame.Show()
return True

class RedirectText:
def __init__(self,aWxTextCtrl):
self.out=aWxTextCtrl

def write(self,string):
self.out.WriteText(string)

</code>

Mike

Jun 19 '07 #2
On Jun 19, 5:07 pm, kyoso...@gmail.com wrote:
Give this a try:

<code>
[good piece of code]
</code>
It worked like a charm! Thanks.

I still don't understand why my initial aproach didn't work as
expected.

Regards,
Alejandro.
Jun 20 '07 #3
On Jun 20, 4:03 pm, Alejandro <alejandro.weinst...@gmail.comwrote:
On Jun 19, 5:07 pm, kyoso...@gmail.com wrote:Give this a try:
<code>

[good piece of code]
</code>

It worked like a charm! Thanks.

I still don't understand why my initial aproach didn't work as
expected.

Regards,
Alejandro.
Alejandro,

Yeah, I'm not sure what the deal is with your code. But I've never
used the LogTextCtrl widget. You might ask why it doesn't work
directly by posting to the wxPython user's group here:
http://www.wxpython.org/maillist.php

Mike

Jun 20 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: newgene | last post by:
Hi, group, I guess it is a simple question for you, but it puzzles me for a while. I use a wxTextCtrl in my application for output result and any exception msg. I know I can add new msg onto...
3
by: Logan | last post by:
I asked a similar question already in the wxPython mailing list, but did not get an answer up to now: 1.) When using a TextCtrl with styles (color etc.) in wxPython, is it then possible to get a...
3
by: Lo?c Mah? | last post by:
Hello I try to use a Validator for a TxtCtrl placed in a Panel with a Button in order to trigger the Validator and test the content of TxtCtrl. I have looked into wxPython documentation and...
1
by: sillyemperor | last post by:
I was a new guy of Python,when i want to test my wxPython app by unittest,it couldn`t work.I fund a stubmaker.py but it only for wxDialog but all widgets.Can someone can tell me how test wxPython...
5
by: citronelu | last post by:
I made a small wxPython app that retrieves web data; for visual logging I use a TextCtrl widget, and stdout is redirected to it, something like this: class RedirectOutput: def __init__(self,...
9
by: Tyler | last post by:
Hello All: I am currently working on a project to create an FEM model for school. I was thinking about using wxPython to gather the 12 input variables from the user, then, after pressing the...
1
by: justme | last post by:
Hello I've been happily scripting away for the last few years (Matlab, now Python) and all has been fine. Now I find myself scripting up code for clients, but they all want a nice GUI. I've had...
1
by: [david] | last post by:
What am I doing wrong? I'm trying to capture stdErr in a multi-threaded program. This code crashes wxPython with /Py Assertion Error: C++ assertion "m_count=-1 || m_count=-2" failed/ What I'm...
4
by: Jimmy | last post by:
hi, all I'm having a problem with creating custom events in wxpython. I have a class A handling some data processing work and another class B of GUI matter. I need GUI to display information...
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.