redirect of standard output of jython to JTextArea

J

Jan Gregor

Hello

I want to redirect output of jython's functions print and println to
JTextArea component. Is it possible ?

I tried this (swingConsole.textArea is instance):

In my class

self.printStream= MyPrintStream(System.out)
System.setOut(self.printStream)

----------------------------------------------------
class MyPrintStream (PrintStream):

def println (str):
swingConsole.textArea.append(str)

def print (str):
swingConsole.textArea.append(str)


Output is still directed to standard output.


Thanks for help,
Jan
 
J

Jan Gregor

problem solved.

in class:

sys.stdout = StdOutRedirector(self)


class StdOutRedirector:
def __init__(self, console):
self.console = console

def write(self, data):
#print >> sys.stderr, ">>%s<<" % data
if data != '\n':
# This is a sucky hack. Fix printResult
self.console.textArea.append(data)

Jan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top