"Notepad .LOG Timestamp Addition" by simon

Rating: (0 votes)

Report this Script

Name: Notepad .LOG Timestamp Addition
Uploaded By: simon
Date Created: May 2, 2009 3:33 a.m.
Date Modified: May 2, 2009 3:33 a.m.
Description: When a file is loaded with .LOG at the start this script adds a timestamp to the bottom of the file, like a journal. This functionality has now been integrated into PN, but the script is a useful example of handling document loading.
Num Views: 442
Num Downloads: 123

Contents

Download this script

import scintilla, pn, pypn.glue, time

oldDocLoad = pypn.glue.onDocLoad

def docLoad(doc):
    """ docLoad handler to implement notepad .LOG functionality"""

    # Get the edit component:
    s = scintilla.Scintilla(doc)

    # Get the first line:
    lineLength = s.LineLength(0)
    text = s.GetText(0, lineLength)

    # If we have .LOG then add a blank line and then the date and time
    if text.startswith(".LOG"):
        timestr = "\r\n\r\n" + time.asctime(time.localtime()) + "\r\n"
        s.AppendText(len(timestr), timestr)

        # Jump to the end of the document
        s.DocumentEnd()

    oldDocLoad(doc)

pypn.glue.onDocLoad = docLoad

Comments: