redefine_put.py :  » Development » Leo » Leo-4.7.1-final » leo » plugins » examples » 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 » examples » redefine_put.py
#@+leo-ver=4-thin
#@+node:edream.110203113231.921:@thin examples/redefine_put.py
"""Redefine the "put" and "put_nl" methods"""

#@@language python
#@@tabwidth -4

#@<< imports >>
#@+node:ekr.20050101090207.6:<< 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.6:<< imports >>
#@nl

#@+others
#@+node:edream.110203113231.922:onStart
#@+at 
#@nonl
# This code illustrates how to redefine _any_ method of Leo.
# Python makes this is almost too easy :-)
#@-at
#@@c

def onStart (tag,keywords):

    import leo.plugins.tkGui as tkGui
    leoTkinterFrame = tkGui.leoTkinterFrame
    log = leoTkinterFrame.leoTkinterLog

    # Replace frame.put with newPut.
    g.funcToMethod(newPut,log,"put")

    # Replace frame.putnl with newPutNl.
    g.funcToMethod(newPutNl,log,"putnl")
#@nonl
#@-node:edream.110203113231.922:onStart
#@+node:edream.110203113231.923:newPut and newPutNl
# Contrived examples of how to redefine frame.put and frame.putnl

# Same as frame.put except converts everything to upper case.
def newPut (self,s,color="black"):
    g.pr("newPut",s,newline=False)
    if g.app.quitting > 0: return
    s = s.upper()
    t = self.logCtrl
    if t:
            t.insert("end",s)
            t.see("end")
            t.update_idletasks()
    else: g.pr(s,newline=False)

# Same as frame.putnl except writes two newlines.
def newPutNl (self):
    g.pr("newPutNl")
    if g.app.quitting > 0: return
    t = self.logCtrl
    if t:
        t.insert("end","\n\n")
        t.see("end")
        t.update_idletasks()
    else: g.pr('')
#@nonl
#@-node:edream.110203113231.923:newPut and newPutNl
#@-others

if Tk and not g.app.unitTesting: # Not for unit testing: overrides core methods.

    # Register the handlers...
    leoPlugins.registerHandler("start2", onStart)

    __version__ = "1.2"
    g.plugin_signon(__name__)
#@nonl
#@-node:edream.110203113231.921:@thin examples/redefine_put.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.