Category Archives: python

Line Movement Commands with PyPN

A bug on Google Code asked for an alternative to the built-in Transpose Lines command in Programmer’s Notepad, allowing a single command to move the current line up or down, allowing repeated use to shift a line through the current document.
To look at implementing this, I started with a python script - it’s so much [...]

Implementing Notepad’s .LOG Feature with PyPN

Notepad has a little-known feature where if you start a file with .LOG then every time the file is loaded the current date and time will be appended to the end of the file - allowing you to use a simple text file as a sort of diary.
A feature request came in for this and, [...]

Context-Sensitive Python Help

Over on the forums, Michel Claveau shows how he gets context-sensitive help for Python code in Programmer’s Notepad:

Check where your python help file is (e.g. c:\python25\doc\Python25.chm)
Install keyHH from http://www.keyworks.net/keyhh.htm
Create a new tool in PN:     - name: Python context Help     - command: c:\windows\keyhh     - parameters: -MyHelp -#klink “%w” c:\python25\doc\Python25.chm     - shortcut: [...]

Programmer’s Notepad - Calculator Part 2

This time we’re going to use a PyPN script to evaluate maths expressions. We’re cheating a little, because we’re just going to ask python to evaluate a string and get a number back out.

import pn, scintilla

@script(”Calculator”)
def DoMaths():
s = scintilla.Scintilla(pn.CurrentDoc())

if s.SelectionEnd - s.SelectionStart < 1:
[...]

Programmer’s Notepad - a Calculator?!

One of the recent feature requests for Programmer’s Notepad was to add the ability in PN to perform basic numeric conversions, e.g. decimal to hex. Also the ability to evaluate simple mathematical expressions like 2+3=.
With the PyPN extension this is very easy, and the required features can even be bound to keyboard shortcuts.
Number Conversions:
The first [...]

Build 667 and PyPN 0.5

A new development build is available on Sourceforge, get it here:
Download PN 2.0.7.667
Also: Zip Distribution | Portable Edition Zip
This build introduces the global scheme management changes that have been promised for a long time. This means that (where the schemes have been updated already) you can change a single colour and have keywords, numbers, properties [...]

Tabs to Spaces with PyPN

Want to convert your tabs to spaces and annoyed that your editor author hasn’t implemented that feature in a handy menu item yet?
Add a PyPN script to do it:
import pn
import scintilla
from pypn.decorators import script

def SetTarget(e, x, y):
e.TargetStart = x
e.TargetEnd = y

@script(”Tabs to Spaces”, “Text”)
def TabsToSpaces():
editor = scintilla.Scintilla(pn.CurrentDoc())

tabSpaces = editor.TabWidth
spaces = “”
for x in range(tabSpaces):
spaces = [...]

PyPN: Upload to FTP

Over in the forums, MurphyMc shows a sample bit of script that will upload your current file to FTP using Python via a PyPN script. It currently hard-codes site/user/pass etc. but these could easily be retrieved from elsewhere (potentially even project properties in the future).
Save To FTP Script
It’s easy to imagine how this could be [...]

PyPN: Validate Your Xml

Have you tried playing with PyPN and PN’s scripts system yet? If not, then perhaps you should. A large number of requests on PN’s Feature Requests tracker could be implemented as scripts. Some perhaps not so elegantly as if they were built in, others perfectly.
To start looking at ways that PyPN enhances Programmer’s Notepad, let’s [...]

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 [...]