redirect of standard output of jython to JTextArea

Discussion in 'Python' started by Jan Gregor, Jan 27, 2005.

  1. Jan Gregor

    Jan Gregor Guest

    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
     
    Jan Gregor, Jan 27, 2005
    #1
    1. Advertising

  2. Jan Gregor

    Jan Gregor Guest

    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

    Jan Gregor wrote:
    > 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
     
    Jan Gregor, Jan 27, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. electric sheep

    Redirect System.out to JTextArea ?

    electric sheep, May 19, 2004, in forum: Java
    Replies:
    3
    Views:
    5,682
    electric sheep
    May 20, 2004
  2. David McNab
    Replies:
    0
    Views:
    501
    David McNab
    Apr 9, 2004
  3. Divya Prakash
    Replies:
    0
    Views:
    444
    Divya Prakash
    Dec 19, 2006
  4. Pinegar, Kent T

    FW: [Jython-users] Jython Licensing Question

    Pinegar, Kent T, Jul 24, 2008, in forum: Python
    Replies:
    0
    Views:
    356
    Pinegar, Kent T
    Jul 24, 2008
  5. Venks
    Replies:
    5
    Views:
    245
    Ken Bloom
    Dec 6, 2007
Loading...

Share This Page