I’m making progress with the Python scripting system, and am getting close to releasing a new testing build that has this functionality enabled. This won’t be for the weak of heart because I suspect there will be all sorts of problems to iron out.

Adding a new python script to be run is easy, there is a scripts directory under your Programmer’s Notepad install, and any python file placed in there will be automatically loaded at run time. PN does not see every bit of code in that file as a script, instead you must register your function as a script when desired.

To do this, you use the “script” decorator:


from pypn.decorators import *
import debug

def myFirstScript():
    debug.OutputDebugString("hello world!")

This will automatically register a script called “myFirstScript” under a group of scripts called “Python”. You can also re-name your script and/or specify the name of a group of scripts to include it in:

@script("My First Script", "Tutorial")
def myFirstScript():
    debug.OutputDebugString("hello more advanced world!")

Scripts appear in a new Scripts docking window in PN with a tree. Currently the only way to run a script is to double-click on it but you will eventually be able to assign shortcuts to them.

Of course, having started with scripts, you now want to do something visible:

import pn
@script("Say Hello!", "Tutorial")
def sayHello():
    d = pn.CurrentDoc()
    Scintilla(d).AppendText(12, "Hello World!")

This uses the Scintilla API method AppendText to add the string “Hello World!” to your document (12 is the number of characters in that string). There are a number of functions in the Scintilla API that can be made much easier to use from Python, and that will happen over time.

I’ll post some more documentation over the next few days, hopefully leading up to a release!