To get around the problem of not having a place print from a python
script unless Leo is run from a console,  I figured out a way to
redirect to a tab pan that is separate from Log that I want to share

Using a class defined as

class LeoTabPrint:
    """
    Simple class with a write method that will send print to a LeoTab
Pane
     use with sys.stdout to redirect  as so:
              foo = LeoTabPrint(tWindow)
              sys.stdout = foo
              print "Tab print test
     """
    def __init__(self,tab,clear=None):
        self.tab=tab
        c.frame.log.selectTab(self.tab)
        if clear:
            c.frame.log.clearTab(tWindow)
    def write(self, string):
        g.es(string,tabName=self.tab)

the code below redirects all print statements to the new tab

#  Redirection of  stdout
import sys
tWindow= 'Test'
c.frame.log.selectTab(tWindow)
foo = LeoTabPrint(tWindow,clear=True)
sys.stdout = foo

print "Tab print test"

Note that clear=True clears the tab pane, which I found makes it easy
to check the script output compared to using g.redirectStdout() that
redirects stdout to the current log pane

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/leo-editor?hl=en.

Reply via email to