PyPN API Description

The API for Programmer's Notepad is based mostly upon three modules: pn, scintilla, and glue. The pn module serves as a base and provides some basic application functionality as well as access to the other APIs. The scintilla module provides access to the Scintilla editor. Finally, the glue module provides a way for scripts to bind themselves into the Programmer's Notepad event model.

The pn Module

Utilities for working with Programmer's Notepad, entry point for all APIs.

 import pn

pn Data Elements

pn : Data
pn.IDOK : 1 User's response was OK.
pn.IDCANCEL : 2 User's response was Cancel.
pn.IDYES : 6 User's response was Yes.
pn.IDNO : 7 User's response was No.
pn.MB_ICONERROR : 16 Display an error icon.
pn.MB_ICONINFORMATION : 64 Display an information icon.
pn.MB_ICONQUESTION : 32 Display a question icon.
pn.MB_OK : 0 OK MessageBox
pn.MB_OKCANCEL : 1 OK/Cancel MessageBox
pn.MB_YESNOCANCEL : 3 Yes/No/Cancel MessageBox
pn.MB_YESNO : 4 Yes/No MessageBox

pn Methods

pn : Methods
pn.AddOutput(text) : None Place text to output window.
pn.AppPath() : str Return the path to the application.
pn.ClearOutput() : None Clears the current contents of the output window.
pn.CurrentDoc() : IDocument Returns the currently selecected document
pn.GetUserSearchOptions() : ISearchOptions Get the object storing the user's current search options
pn.InputBox(title, prompt) : str Ask the user for input - result is a string.
pn.MessageBox(prompt, title, type) : int Presents a MessageBox to the user. Note the type is determined by the constants MB_XXX. Result is an int indicating the responce.
pn.NewDocument(scheme_name) : IDocument Creates a new document
pn.OpenDocument(fullFileName, schemeName) : IDocument Opens an existing document. Note the scheme name can be None but it must be entered.
pn.RegisterScript(func, name, group) : None Registers a script with PN and updates the script window.
pn.SetOutputBasePath(path) : None Set the path to use to make relative paths parsed in output text absolute.
pn.SetOutputDefaultParser() : None Switch to the default output parser
pn.SetOutputRegEx(regexStr) : None Set the regular expression used to parse output text for errors

pn Classes

FindNextResult

pn.FindNextResult : class
Enumeration used to determine the outcome of a search.
pn.FindNextResult : Data
fnNotFound : 0 No results found with current search.
fnFound : 1 A result was returned.
fnReachedStart : 2 Search as reached the place where it began.
fnInvalidRegex : 3 The regex is not valid.
fnInvalidSearch : 4 The search is not valid.
values List of the values for each enumeration object.

IDocument

pn.IDocument : class
PN Document interface.
IDocument : Data
CanSave Indicates whether the document can be saved (i.e. it has a filename)
CurrentScheme Name of the document's current scheme.
FileName Full filename of the document.
Modified Indicates whether the document has been modified
Title Display name of the document
IDocument : Methods
Close(self) : None Closes the document.
FindNext(self, searchOptions) : FindNextResult Does a search in the current document. If fnFound is returned then the result is selected in the current document.
IsValid(self) : bool Check if this document object is still valid
Replace(self, searchOptions) : bool Replace the current find match based on user search settings, see GetUserSearchOptions.
ReplaceAll(self, searchOptions) : int Replace all based on user search settings, see GetUserSearchOptions
Save(self) : bool Save the document.
SendMessage(self, MESSAGE, WPARAM, LPARAM) Send a message to the scintilla window.
SendMessage(self, MESSAGE, int, string) Sends a message to the scintilla window passing text.

ISearchOptions

pn.ISearchOptions : class
PN search options interface.
FileExts File types.
FindText Search field text
Found
IncludeHidden
LoopOK
MatchCase Case sensitive
MatchWholeWord Require match to an entire word.
Recurse Search recursivly though folder structure. i.e. Search subdirectories.
ReplaceInSelection
ReplaceText Test to use in place of match.
SearchBackwards Search from current position to top.
SearchPath Path of directory to do file search in.
UseRegExp Use regular expressions in the search text field.
UseSlashes Use backslash expressions.

The glue Module

Functions for hooking into pn's event handling.

 import glue

glue Methods

glue : Methods
glue.getSchemeConfig(name) : None Get a pypn scheme configuration, used to hook up indenter functions and character added handlers.
glue.onCharAdded(c, doc) Method called when a character is added, default behaviour manages calling indenters and also calls any method registered with glue.schemes[scheme].on_char_added
glue.onDocLoad(doc) Method called when a document is loaded into PN.
glue.onDocSave(filename, doc) Method called when a document is about to be saved to a file.
glue.onDocSaved(doc) Method called when a document has been saved.
glue.onModifiedChanged(modified, doc) Method called when the modified flag is changed.
glue.onWriteProtectChanged(protected, doc) Method called when the read only status of a document is changed.
glue.registerScript(f, group, scriptName) This is called by the script decorator to register a script.
glue.runScript(name) This is called by PN to run a script by name.
glue.startRecording() PN calls this to start recording a script, all recording actions are delegated to the Recorder class.

The scintilla Module

PyPN's interface to the Scintilla editor.

import scintilla

scintilla Classes

Scintilla

scintilla.Scintilla : class
The Scintilla class is the primary interface into the document's scintilla editor. You can get an instance of the class by using its constructor passing in the the document that you would like to edit:
 editor = scintilla.Scintilla(pn.CurrentDoc())

Scintilla Methods

The Scintilla class is a library wrapper for the scintilla editor – this means that most of the methods below correspond to an equivalent Scintilla message. You can gain additional information from the Scintilla API.

Scintilla : Methods
__init__(self, doc) : None
AddRefDocument(self, int) : None
AddStyledText(self, length, styledText) : None
AddText(self, length, text) : None Inserts text at the current position within the document.
Allocate(self, size) : None Allocate a document buffer large enough to store a given size. This will not shrink the document buffer smaller than its current contents requires.
AppendText(self, length, text) : None Appends text to the end of the document.
AssignCmdKey(self, (int)key, (int)command) : None Redefining the key bindings.
AutoCActive(self) : bool Returns true if there is an active auto-completion list and zero if there is not.
AutoCCancel(self) : None Cancels any auto-complete list displayed.
AutoCComplete(self) : None Auto-completion with current selection. This has the same effect as the tab key in the editor.
AutoCGetCurrent(self) : int
AutoCPosStart(self) : int
AutoCSelect(self, str) : None
AutoCSetFillUps(self, str) : None
AutoCShow(self, int, str) : None
AutoCStops(self, str) : None
BackTab(self) : None Same as user pressing Shift+Tab in the the document editor. Moves current pos backwards based upon tabsize.
BeginUndoAction(self) : None Mark an undo save point. Generally this comes in pairs with EndUndoAction() where everything done to the document between the BeginUndoAction() and EndUndoAction() can be undone.
BraceBadLight(self, pos) : None
BraceHighlight(self, pos, (int)maxReStyle) : None
BraceMatch(self, int) : int Will match braces on the following brace character: '(', ')', '[', ']', '{', '}', '<', and '>'. It will search forward if the brace at pos is an opening brace, backwards if it is a closing brace. The match will only occur if the style's match OR the matching brace is beyond the current styling.
CallTipActive(self) : bool Returns true if a call tip window is currently open.
CallTipCancel(self) : None Cancels any displayed call tip.
CallTipPosStart(self) : int returns the position at which CallTipShow() was called.
CallTipSetBack(self, int) : None
CallTipSetFore(self, int) : None
CallTipSetForeHlt(self, int) : None
CallTipSetHlt(self, hlStart, hlEnd) : None Selects a region of text to display in a highlighted style. Unhilighted text is drawn in gray.
CallTipShow(self, pos, tipText) : None Displays a call tip box at the position given. If a call tip box is already active this has no effect.
CanPaste(self) : bool Returns true is document is not read only.
CanRedo(self) : bool
CanUndo(self) : bool
Cancel(self) : None
CharLeft(self) : None Moves current pos left one character.
CharLeftExtend(self) : None Extends the current selection left one character.
CharLeftRectExtend(self) : None
CharRight(self) : None Moves current pos right one character.
CharRightExtend(self) : None Extends the current selection left one character.
CharRightRectExtend(self) : None
ChooseCaretX(self) : None
Clear(self) : None Clears the current selection. If nothing is selected it clears the current character under the cursor.
ClearAll(self) : None If document is not read-only that this will clear the contents of the current document.
ClearAllCmdKeys(self) : None
ClearCmdKey(self, int) : None
ClearDocumentStyle(self) : None Clears the document styles to 0. Not the same as turning off syntax highlighting. see Colourize() to reapply the styles.
ClearRegisteredImages(self) : None Clears the images registered with the Auto-completion lists.
Colourise(self, start, end) : None Requests the current lexer to colourize the current document between start and end.
ConvertEOLs(self, (int)eolStyle) : None Convert the End of Line styles to. (CRLF: 0, CR: 1, LF: 2).
Copy(self) : None Copies the current selection to the clipboard.
CopyRange(self, start, end) : None Copies the text between start:end into the clipboard.
CopyText(self, length, text) : None Copies length character from the string text into the clipboard.
CreateDocument(self) : int Creates a new empty document. The document is not attached to any editor window.
Cut(self) : None Cuts the current selection from the document and places the selected text into the clipboard.
DelLineLeft(self) : None Deletes the characters on the current line from the current position to the end of the line.
DelLineRight(self) : None Deletes the character on the current line from the current position to the beginning of the line.
DelWordLeft(self) : None Deletes the character from the current position to the end of the word.
DelWordRight(self) : None Deletes the character from the current position to the beginning of the word.
DeleteBack(self) : None Deletes the char just behind the current position.
DeleteBackNotLine(self) : None
DocLineFromVisible(self, int) : int
DocumentEnd(self) : None Sets current position to the end of the document.
DocumentEndExtend(self) : None Extends the current selection to the end of the document.
DocumentStart(self) : None Sets current position to the beginning of the document.
DocumentStartExtend(self) : None Extends the current selection to the beginning of the document.
EditToggleOvertype(self) : None Toggles overwrite mode.
EmptyUndoBuffer(self) : None Clears the undo buffer.
EndUndoAction(self) : None Mark the end of an
EnsureVisible(self, int) : None
EnsureVisibleEnforcePolicy(self, int) : None
FindColumn(self, int, int) : int
FindText(self, int, int, str, int) : object
FormFeed(self) : None
FormatRange(self, bool, int) : int
GetCharAt(self, pos) : int Get the character at the given position.
GetCurLine(self) : tuple
GetLine(self, lineNum) : str Get the line at lineNum.
GetLineEndPosition(self, lineNum) : int Return the position of the EOL for line number lineNum
GetLineIndentPosition(self, int) : int
GetLineIndentation(self, int) : int
GetLineSelEndPosition(self, int) : int Get the ending line number of the current selection.
GetLineSelStartPosition(self, int) : int Get the beginning line number of the current selection.
GetLineState(self, int) : int
GetLineVisible(self, int) : bool
GetPropertyInt(self, str, int) : int
GetStyleAt(self, pos) : int Get the style at the position given by pos.
GetStyledText(self, object) : int
GetText(self, int) : str
GetTextRange(self, start, end) : str Get the text between postions start and end
GotoLine(self, lineNum) : None Move the current position to the beginning of of line lineNum
GotoPos(self, pos) : None Move the current position to pos
GrabFocus(self) : None Make this document current focus.
HideLines(self, int, int) : None
HideSelection(self, bool) : None
Home(self) : None Goto the start of the current line (after indention)
HomeDisplay(self) : None
HomeDisplayExtend(self) : None
HomeExtend(self) : None Extend the selection to the start of the current line (after indention)
HomeRectExtend(self) : None
HomeWrap(self) : None
HomeWrapExtend(self) : None
IndentLine(self, int, int) : None
IndicGetFore(self, int) : int
IndicGetStyle(self, int) : int
IndicSetFore(self, int, int) : None
IndicSetStyle(self, int, int) : None
InsertText(self, len, text) : None Insert text into document at the current location.
LineCopy(self) : None
LineCut(self) : None
LineDelete(self) : None
LineDown(self) : None
LineDownExtend(self) : None
LineDownRectExtend(self) : None
LineDuplicate(self) : None
LineEnd(self) : None
LineEndDisplay(self) : None
LineEndDisplayExtend(self) : None
LineEndExtend(self) : None
LineEndRectExtend(self) : None
LineEndWrap(self) : None
LineEndWrapExtend(self) : None
LineFromPosition(self, int) : int
LineLength(self, int) : int
LineScroll(self, int, int) : None
LineScrollDown(self) : None
LineScrollUp(self) : None
LineTranspose(self) : None
LineUp(self) : None
LineUpExtend(self) : None
LineUpRectExtend(self) : None
LinesJoin(self) : None
LinesSplit(self, int) : None
LoadLexerLibrary(self, str) : None
LowerCase(self) : None Converts the current selection to lower case.
MarkerAdd(self, line, number) : int Adds a Marker to the left hand margin. The displayed marker number is 1 - number. Returns a handle to the marker or -1 if the marker was not net.
MarkerDefine(self, markerNumber, symbol) : None Defines a marker. For a description of the various symbols please see the scintilla documentation.
MarkerDefinePixmap(self, int, str) : None
MarkerDelete(self, line, markerNumber) : None Removes a marker. If markerNumber is set to -1 the all markers on that line are removed.
MarkerDeleteAll(self, markerNumber) : None Deletes all instances of a given markerNumber.
MarkerDeleteHandle(self, markerHandle) : None Deletes a marker based upon its handle. The handle is returned by MarkerAdd.
MarkerGet(self, line) : int Returns a 32bit number defining what markers are defined on a line. Marker 0 is bit 0, Marker 1 is bit 1 etc.
MarkerLineFromHandle(self, markerHandle) : int Returns the line number for a given marker handle. This will return the line number after operations that change the line orderings.
MarkerNext(self, startLine, mask) : int Finds the next line that has a marker defined in the mask. For the mask marker 0 is bit 0, marker 1 is bit 1 etc… There are 32 markers available.
MarkerPrevious(self, startLine, mask) : int Finds the previous (searching up) line that has a marker defined in the mask. For the mask marker 0 is bit 0, marker 1 is bit 1 etc… There are 32 markers available.
MarkerSetBack(self, markerNumber, colour) : None Sets the marker's background colour.
MarkerSetFore(self, markerNumber, colour) : None Sets the marker's foreground colour.
MoveCaretInsideView(self) : None
NewLine(self) : None Inserts a new lines as though the user pressed the enter key.
PageDown(self) : None Moves the current position down one page as though the user pressed the Page down key.
PageDownExtend(self) : None Extends the current selection down one page. Same as Shift+Page Down.
PageDownRectExtend(self) : None
PageUp(self) : None Moves the current position up one page as though the user had pressed the Page Up key.
PageUpExtend(self) : None Extends the current selection up one page as though the user had pressed shift+Page Up.
PageUpRectExtend(self) : None
ParaDown(self) : None Moves the current position down the beginning of the next paragraph.
ParaDownExtend(self) : None Extends the current selection down to the beginning of the next paragraph.
ParaUp(self) : None Moves the current position up to the beginning of the next paragraph.
ParaUpExtend(self) : None Extends the current selection up to the beginning of the next paragraph.
Paste(self) : None Pastes the textual content of the clipboard into the document at the current position
PointXFromPosition(self, pos : int) : int Returns the x-coordinate for the given position.
PointYFromPosition(self, pos : int) : int Returns the y-coordinate for the given position.
PositionAfter(self, int) : int
PositionBefore(self, int) : int
PositionFromLine(self, int) : int
PositionFromPoint(self, int, int) : int
PositionFromPointClose(self, int, int) : int
Redo(self) : None
RegisterImage(self, int, str) : None
ReleaseDocument(self, int) : None
ReplaceSel(self, str) : None
ReplaceTarget(self, int, str) : int
ReplaceTargetRE(self, int, str) : int
ScrollCaret(self) : None
SearchAnchor(self) : None
SearchInTarget(self, int, str) : int
SearchNext(self, int, str) : int
SearchPrev(self, int, str) : int
SelectAll(self) : None Sets the selection start to 0 and the selection end to the length of the document.
SetCharsDefault(self) : None
SetFoldFlags(self, flags : int) : None Sets visual markers in the document (as apposed to the margin) for folding. 1 = Experimental, Draw Boxes 2 = Draw line above if expanded 4 = Draw line above if collapsed 8 = Draw line below if expanded 16 = Draw line below if collapsed
SetFoldMarginColour(self, bool, int) : None
SetFoldMarginHiColour(self, bool, int) : None
SetHotspotActiveBack(self, bool, int) : None
SetHotspotActiveFore(self, bool, int) : None
SetHotspotActiveUnderline(self, bool) : None
SetHotspotSingleLine(self, bool) : None
SetKeyWords(self, keyWordSet : int, keyWordList : str) : None You can set up to 9 sets of keywords. keyWordSet integer from 0 to 8 indicating the keyword set you would like to set. keyWordList is a list of keywords separated by whitespace (\x20,\n,\r,\t). Words must be made of non-whitespace characters. How the keywords are used is entirely up to the lexer.
SetLexerLanguage(self, str) : None
SetLineIndentation(self, int, int) : None
SetLineState(self, int, int) : None
SetProperty(self, str, str) : None
SetSavePoint(self) : None Marks the document as unchanged. This would be called right after a save operation to let scintilla know the document is unmodified. [b]Can not undo[/b] from this point.
SetSel(self, start, end) : None Sets the current selection.
SetSelBack(self, bool, int) : None
SetSelFore(self, bool, int) : None
SetStyling(self, int, int) : None
SetStylingEx(self, int, str) : None
SetText(self, str) : None Sets the text of the current document.
SetVisiblePolicy(self, int, int) : None
SetWhitespaceBack(self, bool, int) : None
SetWhitespaceChars(self, str) : None Sets the whitespace characters.
SetWhitespaceFore(self, bool, int) : None
SetWordChars(self, str) : None Sets the word characters. Words are defined to be contiguous sequences of these characters. This definition is used in scintilla's movement and manipulation routines.
SetXCaretPolicy(self, int, int) : None
SetYCaretPolicy(self, int, int) : None
ShowLines(self, int, int) : None
StartRecord(self) : None
StartStyling(self, int, int) : None
StopRecord(self) : None
StutteredPageDown(self) : None
StutteredPageDownExtend(self) : None
StutteredPageUp(self) : None
StutteredPageUpExtend(self) : None
StyleResetDefault(self) : None
StyleSetBack(self, int, int) : None
StyleSetBold(self, int, bool) : None
StyleSetCase(self, int, int) : None
StyleSetChangeable(self, int, bool) : None
StyleSetCharacter(self, int, int) : None
StyleSetClearAll(self) : None
StyleSetEOLFilled(self, int, bool) : None
StyleSetFont(self, int, str) : None
StyleSetFore(self, int, int) : None
StyleSetHotSpot(self, int, bool) : None
StyleSetItalic(self, int, bool) : None
StyleSetSize(self, int, int) : None
StyleSetUnderline(self, int, bool) : None
StyleSetVisible(self, int, bool) : None
Tab(self) : None Same as user pressing the tab key.
TargetAsUTF8(self, str) : int
TargetFromSelection(self) : None
TextHeight(self, int) : int
TextWidth(self, int, str) : int
ToggleCaretSticky(self) : None
ToggleFold(self, int) : None
Undo(self) : None Undo.
UpperCase(self) : None
UsePopUp(self, bool) : None
UserListShow(self, int, str) : None
VCHome(self) : None
VCHomeExtend(self) : None
VCHomeRectExtend(self) : None
VCHomeWrap(self) : None
VCHomeWrapExtend(self) : None
VisibleFromDocLine(self, int) : int
WordEndPosition(self, int, bool) : int Moves the current position to the end of the current word.
WordLeft(self) : None Moves the current position to the beginning of the next word to the left.
WordLeftEnd(self) : None Moves the current position to the end of the next word to the left.
WordLeftEndExtend(self) : None Extends the current selection to the end of the next word to the left.
WordLeftExtend(self) : None Extends the current selection to the beginning of the next word to the left.
WordPartLeft(self) : None
WordPartLeftExtend(self) : None
WordPartRight(self) : None
WordPartRightExtend(self) : None
WordRight(self) : None Moves the current position to the beginning of the next word to the right.
WordRightEnd(self) : None Moves the current position to the end of the next word to the right.
WordRightEndExtend(self) : None Extends the current selection to the end of the next word to the right.
WordRightExtend(self) : None Extends the current selection to the beginning of the next word to the right.
WordStartPosition(self, int, bool) : int Find the position of the first char of the current word.
ZoomIn(self) : None Uniformly increases the size of the text in this document.
ZoomOut(self) : None Uniformly decreases the size of the text in this document.

Scintilla Data

Scintilla : Data
Anchor Selections are always between the anchor and the current location. Note that this is not necessarily the same as the selection start.
AutoCAutoHide
AutoCCancelAtStart
AutoCChooseSingle
AutoCDropRestOfWord
AutoCIgnoreCase
AutoCSeparator
AutoCTypeSeparator
BackSpaceUnIndents
BufferedDraw
CaretFore
CaretLineBack
CaretLineVisible
CaretPeriod
CaretSticky
CaretWidth
CodePage
Column
ControlCharSymbol
CurrentPos The current position of the cursor.
Cursor
DirectFunction
DirectPointer
DocPointer
EOLMode
EdgeColour
EdgeColumn
EdgeMode
EndAtLastLine
EndStyled
FirstVisibleLine
Focus
FoldExpanded
FoldLevel
FoldParent
HScrollBar
HighlightGuide
Indent
IndentationGuides
LastChild
LayoutCache
Length
Lexer
LineCount
LinesOnScreen
MarginLeft
MarginMaskN
MarginRight
MarginSensitiveN
MarginTypeN
MarginWidthN
MaxLineState
ModEventMask
Modify
MouseDownCaptures
MouseDwellTime
Overtype
PrintColourMode
PrintMagnification
PrintWrapMode
ReadOnly
ScrollWidth
SearchFlags
SelText
SelectionEnd
SelectionIsRectangle
SelectionMode
SelectionStart
Status
StyleBits
TabIndents
TabWidth : int The number of spaces equivalent to a tab.
TargetEnd
TargetStart
TextLength
TwoPhaseDraw
UndoCollection
UsePalette
UseTabs
VScrollBar
ViewEOL
ViewWS
WrapMode
XOffset
Zoom : int The current zoom level.
 
pypn_api_pages.txt · Last modified: 2009/06/01 16:31 by Nicholas
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki