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 import_libs(dir): """ Imports the libs, returns a list of the libraries. Pass in dir to scan """ library_list = [] #debug.OutputDebugString(str(os.listdir(os.path.abspath(dir)))) for f in os.listdir(os.path.abspath(dir)): module_name, ext = os.path.splitext(f) # Handles no-extension files, etc. if ext == '.py': # Important, ignore .pyc/other files. try: module = __import__("scripts." + module_name, globals(), locals(), []) #debug.OutputDebugString( 'imported module: %s' % (module_name) ) library_list.append(module) except Exception, ex: pn.AddOutput("Script Import Error with " + str(module_name) + ".py: " + str(ex))
def _handleChangeCommandInner(command, text, m, s): """ Do all command handling, target restoration and undo block handled externally """ pos = s.CurrentPos end = -1 repetitions = 1 if m.group(1) != None: repetitions = int(m.group(1)) what = m.group(2) remainder = m.group(4) # Calculate our change target: if what == None: return command + text elif what == "w": end = s.WordEndPosition(pos, True) end = _findFurtherWordEnds(s, end, repetitions - 1) elif what == "$": lineAtEnd = s.LineFromPosition(s.Length) line = s.LineFromPosition(pos) + (repetitions - 1) if line > lineAtEnd: line = lineAtEnd end = s.GetLineEndPosition(line) elif what == "l": end = pos + repetitions elif what[0] == "t": end = pos for x in range(0, repetitions): pn.AddOutput("\nLooking for " + remainder + " at " + str(end)) end = _findNext(s, remainder[0], end) elif what == "d": startLine = s.LineFromPosition(pos) pos = s.PositionFromLine(startLine) endLine = startLine + repetitions if endLine >= s.LineCount: endLine = s.LineCount - 1 end = s.GetLineEndPosition(endLine) else: end = s.PositionFromLine(endLine) elif what == "iw": # In word end = s.WordEndPosition(pos, True) pos = s.WordStartPosition(pos, True) end = _findFurtherWordEnds(s, end, repetitions - 1) elif what == "i(": # In braces pos, end = _getBraceRange(s, '(', ')') elif what == "i[": # In square braces pos, end = _getBraceRange(s, '[', ']') if pos == -1 or end == -1: pn.AddOutput("Failed to find the range to alter") # Give up, we couldn't get a good position set. return "" _setTarget(s, pos, end) if command == "d": # Delete s.ReplaceTarget(0, "") return "" elif command == "c": # Go back to the editor for overwriting the target return _overwriteTargetMode(s) elif command == "y": yankText = s.GetTextRange(pos, end) pn.SetClipboardText(yankText) s.ReplaceTarget(0, "") return ""