script_io_to_body.py :  » Development » Leo » Leo-4.7.1-final » leo » plugins » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Development » Leo 
Leo » Leo 4.7.1 final » leo » plugins » script_io_to_body.py
#@+leo-ver=4-thin
#@+node:edream.110203113231.925:@thin script_io_to_body.py
"""Send output from the Execute Script command to the end of the body pane"""

#@@language python
#@@tabwidth -4

__version__ = "1.5"

#@<< imports >>
#@+node:ekr.20050101090207.4:<< imports >>
import leo.core.leoGlobals as g
import leo.core.leoPlugins as leoPlugins

Tk = g.importExtension('Tkinter',pluginName=__name__,verbose=True)
#@nonl
#@-node:ekr.20050101090207.4:<< imports >>
#@nl
#@<< version history >>
#@+node:ekr.20071212114235:<< version history >>
#@@nocolor
#@+at
# 
# 1.5 EKR: A complete rewrite. Now works with Leo 4.4.5 code base.
#@-at
#@nonl
#@-node:ekr.20071212114235:<< version history >>
#@nl

#@+others
#@+node:ekr.20071025195133:init
def init():

    ok = Tk and not g.app.unitTesting
        # Not for unit testing: modifies core classes.
    if not ok: return False

    if g.app.gui is None:
        g.app.createTkGui(__file__)

    if g.app.gui.guiName() != "tkinter": return False

    leoPlugins.registerHandler('after-create-leo-frame',onCreate)

    g.plugin_signon(__name__)

    return True
#@-node:ekr.20071025195133:init
#@+node:ekr.20071212092332:onCreate
def onCreate (tag, keys):

    c = keys.get('c')
    if c and c.frame.log:

        g.pr('overriding c.executeScript')

        # Inject ivars.
        log = c.frame.log
        c.script_io_to_body_oldexec  = c.executeScript
        c.script_io_to_body_oldput   = log.put
        c.script_io_to_body_oldputnl = log.putnl

        # Override c.executeScript.
        g.funcToMethod(newExecuteScript,c.__class__,'executeScript')
        c.k.overrideCommand('execute-script',c.executeScript)
#@-node:ekr.20071212092332:onCreate
#@+node:edream.110203113231.928:newPut and newPutNl
# Same as frame.put except sends output to the end of the body text.
def newPut (self,s,*args,**keys):

    body = self.frame.body ; w = body.bodyCtrl

    # g.pr('newPut',repr(s),w,g.callers())

    if w:
        w.insert("end",s)
        body.onBodyChanged("Typing")
    # else: g.pr(s,newline=False)

# Same as frame.putnl except sends output to the end of the body text.
def newPutNl (self,s,*args,**keys):

    newPut (self,'\n')
#@-node:edream.110203113231.928:newPut and newPutNl
#@+node:ekr.20071212091008.1:newExecuteScript & helpers
def newExecuteScript (self,
    event=None,p=None,script=None,
    useSelectedText=True,define_g=True,
    define_name='__main__',silent=False
):

    c = self ; log = c.frame.log
    redirect(c)

    # Use silent to suppress 'end of script message'
    c.script_io_to_body_oldexec(event,p,script,useSelectedText,define_g,define_name,silent=True)
    undirect(c)

    # Now issue the 'end of script' message'
    if not silent:
        tabName = log and hasattr(log,'tabName') and log.tabName or 'Log'
        g.ecnl()
        g.es("end of script",color="purple",tabName=tabName)
#@+node:ekr.20071212090128:redirect
def redirect (c):

    log = c.frame.log.__class__

    g.funcToMethod(newPut,log,"put")
    g.funcToMethod(newPutNl,log,"putnl")
#@nonl
#@-node:ekr.20071212090128:redirect
#@+node:ekr.20071212091008:undirect
def undirect (c):

    log = c.frame.log.__class__

    g.funcToMethod(c.script_io_to_body_oldput,log,"put")
    g.funcToMethod(c.script_io_to_body_oldputnl,log,"putnl")
#@-node:ekr.20071212091008:undirect
#@-node:ekr.20071212091008.1:newExecuteScript & helpers
#@-others
#@-node:edream.110203113231.925:@thin script_io_to_body.py
#@-leo
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.