Archive

Archive for the ‘PyPN’ Category

PyPN Script Repository

May 13th, 2009

Like the idea of using Python scripts to enhance Programmer’s Notepad but not sure where to start? James Yoneda has created the awesome ScriptShare website for exactly this purpose:

Scriptshare in Google Chrome

Scriptshare in Google Chrome

There are a bunch of scripts already there, and hopefully you will add yours too! We’re working on getting this moved over to pnotepad.org eventually.

My thanks to James for putting this effort in and creating such a useful site in such short time!

Simon PN, PyPN, python

PyPN 0.10.973 Released

May 13th, 2009

I’m happy to announce a minor bug fix release for PyPN, the Python extension for Programmer’s Notepad. This release fixes a PN crash if you tried to create a Scintilla object with no active document, and also the exception syntax problem preventing PyPN from working in Python 2.4-2.5.

Downloads

Simon PN, PyPN, python

Programmer’s Notepad 2 0.9.962 Released

May 2nd, 2009

The latest testing release of Programmer’s Notepad is out. This release brings a whole bunch of great changes: Script (macro) recording when using PyPN, a customizable toolbar, firefox-style tab ordering and smart highlight. There are also a load of bug fixes too.

Downloads

There is also a new PyPN release fixing a couple of issues with the included scripts from the last build:

Thanks to all the users who have put time and effort into reporting and following up on bugs, testing, and contributing patches.

Simon PN, PyPN

Programmer’s Notepad 2 0.9.921 Released

February 11th, 2009

The latest testing release of Programmer’s Notepad 2 is finally out. There are plenty of fixes in this release, and a few minor new features too. Of particular note are the following:

  1. Updates to the extensions interface allowing extensions to create menu items
  2. International input fixed (I know this will please a whole bunch of users)
  3. Read only edit protection cleaned up
  4. More text transforms, also available from context menu
  5. Tab to space and vice versa conversions fixed
  6. Notepad’s .LOG feature natively supported
  7. Fix a problem using PN on the Windows 7 beta causing PN to hang on exit

Downloads

There is a new PyPN release supporting the updated plugin interface:

Thanks to all the users who have put time and effort into reporting and following up on bugs, testing, and contributing patches.

Simon PN, PyPN, python

Search within comments

November 5th, 2008

There was a question on the programming reddit today about finding text within comments only. There’s no way to do this from the UI in Programmer’s Notepad, but it’s easy in PyPN:

d = pn.CurrentDoc()
s = scintilla.Scintilla(d)

searchopts = pn.GetUserSearchOptions()

while not pn.CurrentDoc().FindNext(searchopts) == -1:
    # s.GetStyleAt(s.TargetStart) will work in the next PyPN release
    style = d.SendMessage(2010, s.TargetStart, 0)
    # pn.AddOutput(str(style)) - find the current style
    if d.SendMessage(2010, s.TargetStart, 0) == 2:
    break

That small bit of code will find whatever is in the current user’s search options only where the style is 2 – that’s the C++ comment style number. Sadly these numbers are not uniform across schemes, so we’d need to do a bit more work to do this properly across anything. To turn that small snippet of code into a script that can be run from a keyboard shortcut is also easy:

import pn, scintilla

@script("Find In C++ Comments")
def FindInCComments():
    d = pn.CurrentDoc()
    s = scintilla.Scintilla(d)

    searchopts = pn.GetUserSearchOptions()

    while not pn.CurrentDoc().FindNext(searchopts) == -1:
        style = d.SendMessage(2010, s.TargetStart, 0)
        if d.SendMessage(2010, s.TargetStart, 0) == 2:
        break

Just save that into your scripts directory and you’re good to go!

Simon PN, PyPN

Programmer’s Notepad 2 0.9.853

October 13th, 2008

Turbo Pascal Preset  Read only, browser and open files 

Mark All

Today I released a new 0.9 build, here are the highlights:

  1. Create file backups when saving (option, defaulting to off)
  2. Updated some of the images in Find dialog and main UI, read only indicator now uses a tab image instead of text
  3. Extension configuration now stored in user settings directory, meaning this works on Vista without an admin prompt
  4. You can now choose to poll for updates of testing releases (like this one)
  5. Uncomment now works for multiple line-comment lines at once
  6. New keyboard shortcuts for line comments (if you haven’t customised your shortcuts, you’ll get Ctrl-, and Ctrl-. as defaults)
  7. Fixed a crash when going to the Advanced options page
  8. Added a new Turbo preset for Turbo Pascal lovers
  9. Improved the ZenBurn preset
  10. Default scheme font on Vista is now Consolas, still Lucida Console on XP and below

All that, and just since mid-September when .840 was released. If you missed that one, you missed all this:

  1. Allow opening workspace files
  2. Restore editor windows when jumping to a line or tag
  3. Improve regular expressions support (Xpressive now working just fine)
  4. Works on Win2k again
  5. Don’t hold directories open after selecting files
  6. Support explorer context menus in Browser, Open Files and Projects items
  7. Added Mark All (you can’t configure the colors yet, but that’s coming!)
  8. Find in all Project Files
  9. Find next across all open files

You didn’t think I’d been slacking did you?! There have also been lots of behind-the-scenes changes to improve stability and the quality of the code. Not too much more to go now before a new stable release is born. Then onwards with the push to 2.1.

You can download the latest bits here:

0.9.853 Installer

0.9.853 Portable

I’ve also updated PyPN to support Python 2.6 as well as 2.5 and 2.4:

PyPN 0.9.853 for Python 2.4

PyPN 0.9.853 for Python 2.5

PyPN 0.9.853 for Python 2.6

Simon PN, PyPN

Line Movement Commands with PyPN

June 3rd, 2008

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 quicker than writing C++ code to add these commands and going through compile/test for every change.

Here’s how to add these commands as a couple of scripts (which of course can have keyboard shortcuts):

import pn, scintilla, pypn.glue

@script("Move Line Up", "Text")
def MoveLineUp():
	s = scintilla.Scintilla(pn.CurrentDoc())
	l = s.LineFromPosition(s.CurrentPos)
	if (l == 0):
		return

	s.BeginUndoAction()
	s.LineTranspose()
	s.LineUp()
	s.EndUndoAction()

@script("Move Line Down", "Text")
def MoveLineDown():
	s = scintilla.Scintilla(pn.CurrentDoc())
	l = s.LineFromPosition(s.CurrentPos)
	if (l == (s.LineCount-1)):
		return

	s.BeginUndoAction()
	s.LineDown()
	s.LineTranspose()
	s.EndUndoAction()

Drop this in a file in your scripts directory to use it (remember you need PyPN installed), or wait for the next version of PN which has these commands built in.

Simon PN, PyPN, python

Implementing Notepad’s .LOG Feature with PyPN

May 28th, 2008

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, pending a decision on whether to support it directly in Programmer’s Notepad, I decided to show how it could be implemented using the latest PyPN bits:

Updated: Fixed a couple of minor bugs thanks to Jeff Rivett:

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

Just drop this code in a file called dotlog.py under Programmer’s Notepad\scripts and you’ll have the .LOG functionality. This all uses the very latest 2.0.9 unstable bits and the related PyPN build.

Simon PN, PyPN, python

Programmer’s Notepad 2 0.9.794 Released

May 28th, 2008

It’s time for a second 0.9 unstable release, bringing a number of bug fixes and new features:

  • Automatic Update Check - at launch Programmer’s Notepad checks in the background whether there is an update available and shows you a message if there is one.
  • Vista open and save dialogs are now used throughout when you’re running Vista, previous OS versions should be unaffected
  • Programmer’s Notepad is now marked as Vista-aware, meaning that reads and writes to Program Files and similar locations are no longer redirected to the Virtual Store.
  • Find in Files can now search all open files
  • PyPN update 0.9 fixes a couple of event handlers

The update check is a very commonly requested feature. The system understands the difference between stable and unstable releases so most users will only ever see stable updates.

Currently there’s no UI option to enable unstable update checks (there will be!) but you can enable them for yourself by setting this registry value (assuming you’re using a default PN install):

Key: HKEY_CURRENT_USER\Software\Echo Software\PN2\General Settings
Value (REG_DWORD): CheckForUnstableUpdates = 1

209

What else is new in the 0.9 series?

  1. File browser window
  2. Open files window
  3. New, far better regular expressions support (multiline is coming)
  4. More colour schemes (I’m currently using ZenBurn) and the base styles adapt better with the colour schemes
  5. New PyPN release with more event hooks
  6. More Vista control styling dotted around (when running on Vista!)

Downloads

Installer: http://pnotepad.googlecode.com/files/pn209794.exe
Zip: http://pnotepad.googlecode.com/files/pn209794.zip
Portable Zip: http://pnotepad.googlecode.com/files/portable-pn209794.zip
PyPN for Python 2.4: http://pnotepad.googlecode.com/files/pypn-0.9.794-py24.zip
PyPN for Python 2.5: http://pnotepad.googlecode.com/files/pypn-0.9.794-py25.zip

Simon PN, PyPN, software

Programmer’s Notepad - Calculator Part 2

October 27th, 2007

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:
        return

    sel = s.SelText

    i = eval(sel)
    if type(i) in [int, float, complex]:
        pn.AddOutput(str(i))

To use this, simply select an expression like “5+5″ in the editor, run the script, and the output window will contain the evaluation of the expression.

This script is very simple, and in fact could be generalised to a python expression evaluator, but it serves the intended purpose well. It could also be adapted to make sure that expressions are of the form "exp=" and then put the result after the = sign, or perhaps to replace the selected expression with the result. These changes are left as exercises for the reader!

Simon PN, PyPN, python