#@+leo-ver=4
#@+node:@file redefine_put.py
"""Redefine the "put" and "put_nl" methods"""

from leoPlugins import *
from leoGlobals import *

#@+others
#@+node: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 leoFrame
	
	# Replace frame.put with newPut.
	funcToMethod(newPut,leoFrame.LeoFrame,"put")
	
	# Replace frame.putnl with newPutNl.
	funcToMethod(newPutNl,leoFrame.LeoFrame,"putnl")
#@-node:onStart
#@+node: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"):
	# print "newPut",s,
	if app().quitting > 0: return
	s = s.upper()
	if self.log:
			self.log.insert("end",s)
			self.log.see("end")
			self.log.update_idletasks()
	else: print s,

# Same as frame.putnl except writes two newlines.
def newPutNl (self):
	# print "newPutNl"
	if app().quitting > 0: return
	if self.log:
		self.log.insert("end","\n\n")
		self.log.see("end")
		self.log.update_idletasks()
	else: print
#@nonl
#@-node:newPut and newPutNl
#@-others

if 0: # Register the handlers...
	registerHandler("start2", onStart)
	
	__version__ = "1.2"
	plugin_signon(__name__)
#@nonl
#@-node:@file redefine_put.py
#@-leo
