mod_autosave.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 » mod_autosave.py
#@+leo-ver=4-thin
#@+node:edream.110203113231.724:@thin mod_autosave.py
#@<< docstring >>
#@+node:ekr.20060108123253:<< docstring >>
"""Autosave the Leo document every so often.

The time between saves is given in seconds in autosave.ini."""
#@nonl
#@-node:ekr.20060108123253:<< docstring >>
#@nl

#@@language python
#@@tabwidth -4

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

if g.isPython3:
    import configparser as ConfigParser
else:
    import ConfigParser

import os
import time
#@nonl
#@-node:ekr.20060108123141:<< imports >>
#@nl
#@<< version history >>
#@+node:ekr.20060108123141.1:<< version history >>
#@@nocolor
#@+at
# 
# 0.1, 0.2 By Paul Paterson.
# 0.3 EKR:
# - Removed calls to g.top.
# - Added init function.
# 0.4 EKR: call g.enableIdleTimeHook() in init.
#@-at
#@nonl
#@-node:ekr.20060108123141.1:<< version history >>
#@nl

__version__ = "0.4" # EKR: call g.enableIdleTimeHook()

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

    ok = not g.app.unitTesting # Don't want autosave after unit testing.
    if ok:
        # Register the handlers...
        global LAST_AUTOSAVE, ACTIVE, AUTOSAVE_INTERVAL

        AUTOSAVE_INTERVAL = 600
        ACTIVE = "Yes"
        LAST_AUTOSAVE = time.time()
        applyConfiguration()

        # Register the handlers...
        leoPlugins.registerHandler("idle", autosave)
        g.es("auto save enabled",color="orange")
        g.plugin_signon( __name__ )

        # Bug fix: 2009/10/06
        if ACTIVE == "Yes":
            g.enableIdleTimeHook()

    return ok
#@nonl
#@-node:ekr.20060108123141.2:init
#@+node:edream.110203113231.725:applyConfiguration
def applyConfiguration(config=None):

    """Called when the user presses the "Apply" button on the Properties form"""

    global LAST_AUTOSAVE, ACTIVE, AUTOSAVE_INTERVAL

    if config is None:
        fileName = os.path.join(g.app.loadDir,"../","plugins","mod_autosave.ini")
        config = ConfigParser.ConfigParser()
        config.read(fileName)

    ACTIVE = config.get("Main", "Active")
    AUTOSAVE_INTERVAL = int(config.get("Main", "Interval"))
#@nonl
#@-node:edream.110203113231.725:applyConfiguration
#@+node:edream.110203113231.726:autosave
def autosave(tag, keywords):

    """Save the current document if it has a name"""

    global LAST_AUTOSAVE

    c = keywords.get('c')

    if g.app.killed or not c or not c.exists: return

    if ACTIVE == "Yes":
        if time.time() - LAST_AUTOSAVE > AUTOSAVE_INTERVAL:
            if c.mFileName and c.changed:
                g.es("Autosave: %s" % time.ctime(),color="orange")
                c.fileCommands.save(c.mFileName)
            LAST_AUTOSAVE = time.time()
#@nonl
#@-node:edream.110203113231.726:autosave
#@-others
#@nonl
#@-node:edream.110203113231.724:@thin mod_autosave.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.