My favorites | Sign in
Project Home Downloads Issues Source
New issue   Search
for
  Advanced search   Search tips   Subscriptions

Issue 973 attachment: text.py (3.2 KB)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
###############################################################################
## Some basic script functions shipped with Programmer's Notepad by various
## authors including:
## Simon Steele
## Scott (wischeese)
## Benoit

import pn
import scintilla
import string
from pypn.decorators import script

@script("Sort Lines", "Text")
def SortLines():
""" Sort Lines (By Scott (wischeese)) """
editor = scintilla.Scintilla(pn.CurrentDoc())
editor.BeginUndoAction()
lsSelection = editor.GetTextRange(editor.SelectionStart, editor.SelectionEnd)
laLines = lsSelection.splitlines(0)
laLines.sort()
lsReplace = string.join(laLines, '\r\n' )
editor.ReplaceSel(lsReplace)
editor.EndUndoAction()

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

@script("Tabs to Spaces", "Text")
def TabsToSpaces():
editor = scintilla.Scintilla(pn.CurrentDoc())
tab_width = editor.TabWidth
editor.BeginUndoAction()
lsSelection = editor.GetTextRange(editor.SelectionStart, editor.SelectionEnd)
laLines = lsSelection.splitlines(0)
for i in range(len(laLines)):
index = laLines[i].find('\t')
while index != -1:
spaces = ' '*(tab_width - index%tab_width)
laLines[i] = laLines[i].replace('\t', spaces, 1)
index = laLines[i].find('\t')

lsReplace = '\r\n'.join(laLines)
editor.ReplaceSel(lsReplace)
editor.EndUndoAction()

@script("Right-align table", "Text")
def UpperCase():
""" Align text to the right in columns """
editor = scintilla.Scintilla(pn.CurrentDoc())
editor.BeginUndoAction()
selText = editor.GetTextRange(editor.SelectionStart, editor.SelectionEnd)

editor.ReplaceSel(selText)
editor.EndUndoAction()

@script("Upper case", "Text")
def UpperCase():
""" Convert text to Upper Case by Benoit """
editor = scintilla.Scintilla(pn.CurrentDoc())
editor.BeginUndoAction()
selText = editor.GetTextRange(editor.SelectionStart, editor.SelectionEnd)
selText = selText.upper()
editor.ReplaceSel(selText)
editor.EndUndoAction()

@script("Lower case", "Text")
def LowerCase():
""" Convert text to Lower Case by Benoit """
editor = scintilla.Scintilla(pn.CurrentDoc())
editor.BeginUndoAction()
selText = editor.GetTextRange(editor.SelectionStart, editor.SelectionEnd)
selText = selText.lower()
editor.ReplaceSel(selText)
editor.EndUndoAction()

@script("Capitalize case", "Text")
def Capitalize():
""" Capitalise text by Benoit """
editor = scintilla.Scintilla(pn.CurrentDoc())
editor.BeginUndoAction()
selText = editor.GetTextRange(editor.SelectionStart, editor.SelectionEnd)
selText = selText.capitalize()
editor.ReplaceSel(selText)
editor.EndUndoAction()

@script("Title case", "Text")
def TitleCase():
""" Title case text by Benoit """
editor = scintilla.Scintilla(pn.CurrentDoc())
editor.BeginUndoAction()
selText = editor.GetTextRange(editor.SelectionStart, editor.SelectionEnd)
selText = selText.title()
editor.ReplaceSel(selText)
editor.EndUndoAction()

@script("Invert case", "Text")
def InvertCase():
editor = scintilla.Scintilla(pn.CurrentDoc())
editor.BeginUndoAction()
selText = editor.GetTextRange(editor.SelectionStart, editor.SelectionEnd)
selText = selText.swapcase()
editor.ReplaceSel(selText)
editor.EndUndoAction()
Powered by Google Project Hosting