def getSTC(init=None, stcclass=FundamentalMode, count=1, lexer="Python", tab_size=4, use_tabs=False): refstc = MockSTC(MockWX.root) buffer = MockBuffer(refstc) frame = MockFrame(refstc) stc = stcclass(frame, frame, buffer, frame) frame.mode = stc #stc.SetLexer(lexer) stc.ConfigureLexer(lexer) # if lexer == wx.stc.STC_LEX_PYTHON: # # FIXME: this is a duplicate of the keyword string from # # PythonMode. Find a way to NotRepeatMyself instead of this. # stc.SetKeyWords(0, 'and as assert break class continue def del elif else except exec finally for from global if import in is lambda not or pass print raise return try while True False None self') stc.SetText("") stc.SetEOLMode(wx.stc.STC_EOL_LF) stc.SetProperty("fold", "1") stc.SetIndent(tab_size) stc.SetUseTabs(use_tabs) if init == 'py': stc.SetText("python source goes here") elif init == 'columns': for i in range(count): stc.AddText('%04d-0123456789\n' % i) stc.Colourise(0, stc.GetTextLength()) return stc
def processReturn(self, stc): """Add a newline and indent to the proper tab level. Indent to the level of the line above. This uses the findIndent method to determine the proper indentation of the line about to be added, inserts the appropriate end-of-line characters, and indents the new line to that indentation level. @param stc: stc of interest """ linesep = stc.getLinesep() stc.BeginUndoAction() # reindent current line (if necessary), then process the return #pos = stc.reindentLine() linenum = stc.GetCurrentLine() pos = stc.GetCurrentPos() col = stc.GetColumn(pos) #linestart = stc.PositionFromLine(linenum) #line = stc.GetLine(linenum)[:pos-linestart] #get info about the current line's indentation ind = stc.GetLineIndentation(linenum) self.dprint("format = %s col=%d ind = %d" % (repr(linesep), col, ind)) stc.SetTargetStart(pos) stc.SetTargetEnd(pos) if col <= ind: newline = linesep + self.getNewLineIndentString(stc, col, ind) elif not pos: newline = linesep else: stc.ReplaceTarget(linesep) pos += len(linesep) end = min(pos + 1, stc.GetTextLength()) # Scintilla always returns a fold level of zero on the last line, # so when trying to indent the last line, must add a newline # character. if pos == end and self.folding_last_line_bug: stc.AddText("\n") end = stc.GetTextLength() # When we insert a new line, the colorization isn't always # immediately updated, so we have to force that here before # calling findIndent to guarantee that the new line will have the # correct fold property set. stc.Colourise(stc.PositionFromLine(linenum), end) stc.SetTargetStart(pos) stc.SetTargetEnd(pos) ind = self.findIndent(stc, linenum + 1) self.dprint("pos=%d ind=%d fold=%d" % (pos, ind, (stc.GetFoldLevel(linenum+1)&wx.stc.STC_FOLDLEVELNUMBERMASK) - wx.stc.STC_FOLDLEVELBASE)) newline = stc.GetIndentString(ind) stc.ReplaceTarget(newline) stc.GotoPos(pos + len(newline)) stc.EndUndoAction()
def initSTC(stc, stylefile, language, custom=''): #get the styling information _faces = dict(faces) _faces.update(get_faces(stylefile)) styles = get_style(stylefile, language, _faces, 'default') styles.update(get_style(stylefile, language, _faces, custom)) ## print "got styling information:", [i.strip() for i in lines1] #get any extra bits extra = get_extra(stylefile, language) ## import pprint ## pprint.pprint(extra) #get the actual lexer lexer = wx.stc.STC_LEX_NULL if 'lexer' in extra: lex = extra['lexer'] if lex.startswith('wx'): lex = lex[2:] lex.lstrip('.') if hasattr(wx.stc, lex): lexer = getattr(wx.stc, lex) _base = 'fore:%(forecol)s,back:%(backcol)s,face:%(mono)s,size:%(size)d'%_faces stc.StyleResetDefault() stc.ClearDocumentStyle() stc.SetLexer(lexer) stc.kw = extra.get('keywords', '') stc.SetKeyWords(0, stc.kw) stc.StyleSetSpec(wx.stc.STC_STYLE_DEFAULT, _base) stc.StyleClearAll() for num, style in styles.iteritems(): if num >= 0: stc.StyleSetSpec(num, style) elif num == -1: setSelectionColour(stc, style) elif num == -2: setCursorColour(stc, style) elif num == -3: setEdgeColour(stc, style) #borrowed from STCStyleEditor bkCol = None if 0 in styles: prop = styles[0] else: prop = _base names, vals = parseProp(prop) if 'back' in names: bkCol = strToCol(vals['back']) if bkCol is None: bkCol = '#ffffff' stc.SetBackgroundColour(bkCol) stc.Colourise(0, stc.GetTextLength())
def Set(self, stc, line, delete=False): """Add/Delete the marker to the stc at the given line @note: overrode to ensure only one is set in a buffer at a time """ super(ErrorMarker, self).Set(stc, line, delete) start = stc.GetLineEndPosition(max(line-1, 0)) end = stc.GetLineEndPosition(line) if start == end: start = 0 stc.Colourise(start, end) # Refresh for background marker
def prepareSTC(stc, before): print "*** before *** repr=%s\n%s" % (repr(before), before) cursor = before.find("|") stc.SetText(before) # change "|" to the cursor stc.SetTargetStart(cursor) stc.SetTargetEnd(cursor + 1) stc.ReplaceTarget("") stc.GotoPos(cursor) stc.Colourise(0, stc.GetTextLength()) stc.showStyle()
def DeleteAll(self, stc): """Overrode to handle refresh issue""" super(ErrorMarker, self).DeleteAll(stc) stc.Colourise(0, stc.GetLength())
def DeleteAll(self, stc): """Overrode to handle refresh issue""" super(BreakpointStep, self).DeleteAll(stc) stc.Colourise(0, stc.GetLength())
def clearSTC(stc): stc.SetText("") stc.SetEOLMode(wx.stc.STC_EOL_LF) stc.SetProperty("fold", "1") stc.Colourise(0, stc.GetTextLength())