On Wed, Jan 7, 2009 at 3:54 AM, rhh <[email protected]> wrote:

>
> Is there another way to suppress the printing of or redirect leo
> traceback errors to std out instead of to the log pane? g.redirect
> does not seem to work.


There is always a way :-) The real question is, "how easy is it?"

The place to start looking is c.executeScript.  It calls
g.handleScriptException, which in turn calls g.es.

So a script, plugin or script button could replace g.es with print.  Like
this::

    def my_g_es (*args,**keys):
        print ''.join(args)
    g.es = my_g_es

    print 1/0

However, it is not so easy to restore g.es afterward.  For example, doing it
in a 'finally' clause doesn't work, because g.es is restored too soon.

Happily, c.executeScript calls g.redirectScriptOutput and
g.self.unredirectScriptOutput().  These do the reverse of what is wanted,
but we can just replace them.

First, run this script::

old_g_es = g.es

def g_es (*args,**keys):
    print (''.join(args))

def redirect():
    g.es = g_es

def undirect():
    g.es = old_g_es

g.funcToMethod(redirect,c,name='redirectScriptOutput')
g.funcToMethod(undirect,c,name='unredirectScriptOutput')

print('script output now goes to the console')

After running this script, try executing the following script::

print 1/0

HTH.

Edward

--~--~---------~--~----~------------~-------~--~----~
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