print_cp.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 » print_cp.py
#@+leo-ver=4-thin
#@+node:ekr.20060621123339:@thin examples/print_cp.py
#@<< docstring >>
#@+node:ekr.20060621123339.1:<< docstring >>
'''A plugin showing how to convert an @button node to a plugin.

This plugin registers the 'print-cp' minibuffer command.'''
#@-node:ekr.20060621123339.1:<< docstring >>
#@nl

__version__ = '0.1'
#@<< version history >>
#@+node:ekr.20060621123339.2:<< version history >>
#@@killcolor
#@+at
# 
# v 0.1: Initial version.
#@-at
#@nonl
#@-node:ekr.20060621123339.2:<< version history >>
#@nl

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

if 0:
    Pmw = g.importExtension('Pmw',    pluginName=__name__,verbose=True,required=True)
    Tk  = g.importExtension('Tkinter',pluginName=__name__,verbose=True,required=True)

# Whatever other imports your plugins uses.
#@nonl
#@-node:ekr.20060621123339.3:<< imports >>
#@nl

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

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

    ok = g.app.gui.guiName() == "tkinter"

    if ok:
        # leoPlugins.registerHandler('after-create-leo-frame',onCreate)
        leoPlugins.registerHandler(('new','open2'),onCreate)

    return ok
#@nonl
#@-node:ekr.20060621123339.4:init
#@+node:ekr.20060621123339.5:onCreate
def onCreate (tag, keys):

    c = keys.get('c')
    if not c: return

    thePluginController = pluginController(c)
#@nonl
#@-node:ekr.20060621123339.5:onCreate
#@+node:ekr.20060621123339.6:class pluginController
class pluginController:

    #@    @+others
    #@+node:ekr.20060621123339.7:__init__
    def __init__ (self,c):
        self.c = c
        c.k.registerCommand('print-cp',shortcut=None,func=self.print_cp)
        script = "c.k.simulateCommand('print-cp')"
        g.app.gui.makeScriptButton(c,script=script,buttonText='Print c & p',bg='red')
    #@nonl
    #@-node:ekr.20060621123339.7:__init__
    #@+node:ekr.20060621124649:print_cp
    def print_cp (self,event=None):

        c = self.c ; p = c.p
        g.es_print('c: %s' % (c.fileName()),color='red')
        g.es_print('p: %s' % (p.h),color='red')
    #@nonl
    #@-node:ekr.20060621124649:print_cp
    #@-others
#@nonl
#@-node:ekr.20060621123339.6:class pluginController
#@-others
#@nonl
#@-node:ekr.20060621123339:@thin examples/print_cp.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.