Ejemplo n.º 1
0
def doBase64():
    """ This method will grab the curent selection/document and
        create a new document that is a base64 vesion of the text """
    doc = pn.CurrentDoc()
    if doc is not None:  #Lets try not to crash pn too often...
        editor = scintilla.Scintilla(doc)
        start = editor.SelectionStart
        end = editor.SelectionEnd
        if (start == end):  #nothing is selected so we will just grab it all...
            start = 0
            end = editor.Length
        text = editor.GetTextRange(start, end)
        newDoc = pn.NewDocument(None)
        newEditor = scintilla.Scintilla(newDoc)
        newEditor.BeginUndoAction()
        encoded = base64.b64encode(text)
        l = len(encoded)
        m = 0
        while l > 80:
            str = encoded[m:m + 80] + '\n'
            newEditor.AppendText(len(str), str)
            l, m = l - 80, m + 80
        str = encoded[m:m + l]
        newEditor.AppendText(len(str), str)
        newEditor.EndUndoAction()
 def __init__(self, pndoc=None):
     """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
     self._closed = False
     self._softspace = 0
     if not pndoc == None:
         self.doc = pndoc
         self.__editor = scintilla.Scintilla(self.doc)
     else:
         doc = pn.NewDocument(None)
         self.__editor = scintilla.Scintilla(pn.CurrentDoc())
         self.__editor.BeginUndoAction()
Ejemplo n.º 3
0
def TabsToSpaces():
    editor = scintilla.Scintilla(pn.CurrentDoc())

    tabSpaces = editor.TabWidth
    spaces = ""
    for x in range(tabSpaces):
        spaces = spaces + " "

    end = editor.Length

    SetTarget(editor, 0, end)
    editor.SearchFlags = 0
    editor.BeginUndoAction()

    pos = editor.SearchInTarget(1, "\t")

    while (pos != -1):
        l1 = editor.TargetEnd - editor.TargetStart
        editor.ReplaceTarget(tabSpaces, spaces)

        # adjust doc length
        end = end + tabSpaces - l1
        start = pos + tabSpaces

        if start >= end:
            pos = -1
        else:
            SetTarget(editor, start, end)
            pos = editor.SearchInTarget(1, "\t")

    editor.EndUndoAction()
Ejemplo n.º 4
0
def InvertCase():
    editor = scintilla.Scintilla(pn.CurrentDoc())
    editor.BeginUndoAction()
    selText = editor.GetTextRange(editor.SelectionStart, editor.SelectionEnd)
    selText = selText.swapcase()
    editor.ReplaceSel(selText)
    editor.EndUndoAction()
Ejemplo n.º 5
0
def _handleCommand(text, repetitions):
    """ Handle a simple command """
    sci = scintilla.Scintilla(pn.CurrentDoc())

    for x in xrange(repetitions):
        if text == 'j':
            sci.LineDown()
        elif text == 'k':
            sci.LineUp()
        elif text == 'h':
            sci.CharLeft()
        elif text == 'l':
            sci.CharRight()
        elif text == '^':
            sci.Home()
        elif text == '$':
            sci.LineEnd()
        elif text == 'w':
            sci.WordRight()
        elif text == 'b':
            sci.WordLeft()
        elif text == 'u':
            sci.Undo()
        elif text == 'i':
            return _insertMode(sci)
        else:
            return text

    return ""
Ejemplo n.º 6
0
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()
Ejemplo n.º 7
0
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()
Ejemplo n.º 8
0
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()
Ejemplo n.º 9
0
def undoBase64():
    """ This method will grab the curent selection/document and
        create a new document that is the base64 decoded vesion 
        of the text """
    doc = pn.CurrentDoc()
    if doc is not None:  #Lets try not to crash pn too often...
        editor = scintilla.Scintilla(doc)
        start = editor.SelectionStart
        end = editor.SelectionEnd
        if (start == end):  #nothing is selected so we will just grab it all...
            start = 0
            end = editor.Length
        text = editor.GetTextRange(start, end)
        decoded = base64.b64decode(text)
        newDoc = pn.NewDocument(None)
        newEditor = scintilla.Scintilla(newDoc)
        newEditor.BeginUndoAction()
        newEditor.AppendText(len(decoded), decoded)
        newEditor.EndUndoAction()
    def stopRecording(self):
        """ The user wants to stop recording, or the document the recording 
		was made in is being closed. Read the document in as a script ready
		to run and cancel the recording settings. """
        self._flushbuf()
        doc = pn.NewDocument("python")
        sci = scintilla.Scintilla(doc)
        sci.ReplaceSel(self.script)
        pn.EvalDocument(doc)
        self.script = None
Ejemplo n.º 11
0
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 = '\r\n'.join(laLines)
    editor.ReplaceSel(lsReplace)
    editor.EndUndoAction()
def ValidateXml():
    editor = scintilla.Scintilla(pn.CurrentDoc())
    text = editor.GetText(editor.Length)

    parser = expat.ParserCreate()

    try:
        parser.Parse(text, True)
    except expat.ExpatError as ex:
        pn.ClearOutput()
        pn.AddOutput("Error: " + str(ex))
 def wrappedScript():
     """ Wrap the script function to automatically group undo """
     if not auto_undo:
         f()
     else:
         s = scintilla.Scintilla(pn.CurrentDoc())
         try:
             s.BeginUndoAction()
             f()
         finally:
             s.EndUndoAction()
Ejemplo n.º 14
0
def _handleChangeCommand(command, text):
    """ Handle the c, d and y commands """
    m = re.match("^([0-9]+)?((i[w\\(\\[])|[w$ld]|t(.))?$", text)
    if m == None:
        return command + text

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

    target = _getTarget(s)

    try:
        return _handleChangeCommandInner(command, text, m, s)
    finally:
        _setTarget(s, target[0], target[1])
Ejemplo n.º 15
0
def python_indent(c, doc):
	sci = scintilla.Scintilla(doc)
	if c == '\n' or c == '\r':
		pos = sci.CurrentPos
		line = sci.LineFromPosition( pos )
		
		lc = findPrevLineLastChar( pos, sci )
		
		# If the previous line ended with a colon, then indent
		if lc == ':':
			indent = sci.GetLineIndentation( line )
			
			# The DumbIndent system may already have indented this line...
			previndent = sci.GetLineIndentation( line - 1 )
			if indent == previndent or indent == 0:
				indent += 4
				sci.IndentLine( line, indent )
Ejemplo n.º 16
0
    def scintilla_widget(contents, read_only, auto_indent=True):
        """Static method that creates a new scintilla widget and sets up
        basic options.  DOES not show the widget, which must be done by the
        caller.
        """
        ## Create new Scintilla widget
        scin = scintilla.Scintilla()
        scin.SetText(contents)
        scin.SetReadOnly(read_only)
        scin.set_size_request(100, 100)
        scin.StyleSetFont(scintilla.STYLE_DEFAULT, "!Monospace")
        scin.SetZoom(-2)

        ## Default configuration for Scintilla
        scin.SetUseTabs(False)
        scin.SetTabWidth(4)
        scin.SetIndent(4)
        scin.SetReadOnly(0)

        ## Put line numbers in margin 0.  Determine width in pixels
        ## required for displaying up to 99999 lines
        req_width = scin.TextWidth(scintilla.STYLE_LINENUMBER, "_99999")
        scin.SetMarginTypeN(1, scintilla.SC_MARGIN_NUMBER)
        scin.SetMarginWidthN(1, req_width)

        ## Define an on-key callback to maintain indentation when '\n' is
        ## pressed.  This is activated only when the member
        ## maintain_indentation (added to the widget) is true
        scin.plide_maintain_indentation = auto_indent

        def char_added_callback(scin, char):
            if scin.plide_maintain_indentation and char == ord('\n'):
                lastline = scin.LineFromPosition(scin.GetCurrentPos()) - 1
                if lastline >= 0:
                    indent = scin.GetLineIndentation(lastline)
                    # print >>sys.stderr, "Autoindenting to", indent
                    scin.SetLineIndentation(lastline + 1, indent)
                    for i in xrange(indent):
                        scin.CharRight()
            return False  # Keep processing

        scin.connect("CharAdded", char_added_callback)

        return scin