chapter_hoist.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 » chapter_hoist.py
#@+leo-ver=4-thin
#@+node:ekr.20060328125925:@thin chapter_hoist.py
#@<< docstring >>
#@+node:ekr.20060328125925.1:<< docstring >>
"""A plugin to create hoist buttons.  It is kind of a Chapters lite plugin

This plugin puts two buttons in the icon area: a button called 'Save Hoist' and
a button called 'Dehoist'.

The 'Save Hoist' button hoists the presently selected node and creates a button
which can later rehoist the same node.

The 'Dehoist' button performs one level of dehoisting

Requires at least version 0.19 of mod_scripting
"""
#@nonl
#@-node:ekr.20060328125925.1:<< docstring >>
#@nl
#@<< imports >>
#@+node:ekr.20060328125925.2:<< imports >>
import leo.core.leoGlobals as g
import leo.core.leoPlugins as leoPlugins
from mod_scripting import scriptingController

Tk = g.importExtension('Tkinter',pluginName=__name__,verbose=True)
#@-node:ekr.20060328125925.2:<< imports >>
#@nl

__version__ = "0.4"
#@<< version history >>
#@+node:ekr.20060328125925.3:<< version history >>
#@+at
# 
# 0.1 btheado: initial creation.
# 0.2 EKR: changed to @thin.
# 0.3 EKR: init now succeeds for unit tests.
# 0.4 EKR: use new calling sequences for sc.createIconButton.
#          Among other things, this creates the save-hoist commnand.
#@-at
#@nonl
#@-node:ekr.20060328125925.3:<< version history >>
#@nl

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

    ok = Tk is not None # OK for unit tests.

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

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

        if ok:
            # Note: call onCreate _after_ reading the .leo file.
            # That is, the 'after-create-leo-frame' hook is too early!
            leoPlugins.registerHandler(('new','open2'),onCreate)
            g.plugin_signon(__name__)

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

    """Handle the onCreate event in the chapterHoist plugin."""

    c = keys.get('c')

    if c:
        sc = scriptingController(c)
        ch = chapterHoist(sc,c)
#@-node:ekr.20060328125925.5:onCreate
#@+node:ekr.20060328125925.6:class chapterHoist
class chapterHoist:
    #@    @+others
    #@+node:ekr.20060328125925.7: ctor
    def __init__ (self,sc,c):
        self.createSaveHoistButton(sc,c)
        self.createDehoistButton(sc,c)
    #@-node:ekr.20060328125925.7: ctor
    #@+node:ekr.20060328125925.8:createSaveHoistButton
    def createSaveHoistButton(self,sc,c):

        def saveHoistCallback(event=None,self=self,sc=sc,c=c):
            self.createChapterHoistButton(sc,c,c.p)
            c.hoist()
            return 'break'

        b = sc.createIconButton(
            text='save-hoist',
            command = saveHoistCallback,
            shortcut = None,
            statusLine='Create hoist button current node',
            bg='LightSteelBlue1')

        return b
    #@nonl
    #@-node:ekr.20060328125925.8:createSaveHoistButton
    #@+node:ekr.20060328125925.9:createDehoistButton
    def createDehoistButton(self,sc,c):

        def dehoistCallback(event=None,c=c):
            c.dehoist()
            return 'break'

        b = sc.createIconButton(
            text='dehoist',
            command=dehoistCallback,
            shortcut=None,
            statusLine='Dehoist',
            bg='LightSteelBlue1')

        return b
    #@nonl
    #@-node:ekr.20060328125925.9:createDehoistButton
    #@+node:ekr.20060328125925.10:createChapterHoistButton
    def createChapterHoistButton (self,sc,c,p):

        '''Generates a hoist button for the headline at the given position'''    
        h = p.h
        buttonText = sc.getButtonText(h)
        statusLine = "Hoist %s" % h

        def hoistButtonCallback (event=None,self=self,c=c,p=p.copy()):
            while (c.canDehoist()):
                c.dehoist()
            c.selectPosition(p)
            c.hoist()
            return 'break'

        b = sc.createIconButton(
            text=buttonText,
            command=hoistButtonCallback,
            statusLine=statusLine,
            shortcut=None,
            bg='LightSteelBlue1')
    #@-node:ekr.20060328125925.10:createChapterHoistButton
    #@-others
#@nonl
#@-node:ekr.20060328125925.6:class chapterHoist
#@-others
#@nonl
#@-node:ekr.20060328125925:@thin chapter_hoist.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.