PyPN


22
Sep 06

PN 2.0.7.610 and PyPN 0.3 Released

I’m pleased to announce that the current development build on SourceForge of PN 2 is now 2.0.7.610 which contains just minor fixes from .609 to make working with extensions better. PyPN 0.3 adds a number of features over the first two releases and also several bugfixes.

Download PN 2.0.7.610

Download PyPN 0.3

Remember you’ll need Python 2.4 installed to use PyPN.


17
Aug 06

Announcing pyPN-0.1

I finally got some time to clean up and zip up the current pyPN bits and have uploaded them to the web site:

http://www.pnotepad.org/files/pypn-0.1.zip

You will need the latest development build of PN (2.0.7.608 at the time of writing) and Python 2.4 to use this.

What is pyPN?

pyPN is the first extension for Programmer’s Notepad 2, and provides support for scripting PN using Python! You can already do a lot, but there’s also a lot of functionality yet to be exposed.

Other extensions can be provided using the same mechanism pyPN uses, see http://www.pnotepad.org/plugindoc/ for the gory C++ details (not as scary as you might think!).

Version 0.1

This is definitely beta software, so please experiment and report plenty of feedback! Extract the files into your PN folder and restart PN. If you already have a config.xml file you’ll need to merge the two files.

There will be more documentation as time goes on, but the code includes one very simple sample script showing how scripts can be built in to the scripts window. You can turn any python file or buffer into a runnable script by right-clicking and selecting “Use as Script” – this will add the window to the scripts window from where you can double-click to run.

So, some simple examples:

import pn
pn.AddOutput(“Hello!\n”)

This will add text to the output window (you’ll need to show the window first).

To work with scintilla (the text editing component) try something like this:

import pn, scintilla
s = scintilla.Scintilla(pn.CurrentDoc())
s.AppendText(6, “Hello!”)

When you make a mistake in your script at runtime the traceback will be shown in the output window (again, you need to manually show this).

Note that if you put broken scripts in the scripts directory this will currently crash PN on startup – this will  be fixed in future versions.

Finally note that you get some automatic indenting when writing Python code now, the code for this is in the init.py file. You can write indenters for other languages in a similar style. The indenting isn’t perfect, but I love it!

Let me know how you get on, and post anything that works for others to see as either a comment or on the forums!


2
Feb 06

PyPN

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

@script()
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!