def StyleText(stc, start, end): """Style the text @param stc: Styled text control instance @param start: Start position @param end: end position """ cpos = 0 stc.StartStyling(cpos, 0x1f) lexer = get_lexer_by_name("html+django") doctxt = stc.GetTextRange(0, end) wineol = stc.GetEOLChar() == "\r\n" for token, txt in lexer.get_tokens(doctxt): # print token, txt style = TOKEN_MAP.get(token, STC_DJANGO_DEFAULT) if style == STC_DJANGO_PREPROCESSOR and txt.startswith(u'#'): style = STC_DJANGO_COMMENT # elif style == STC_DJANGO_STRING and txt[-1] not in '"\'': # style = STC_DJANGO_STRINGEOL tlen = len(txt) if wineol and "\n" in txt: tlen += txt.count("\n") if tlen: stc.SetStyling(tlen, style) cpos += tlen stc.StartStyling(cpos, 0x1f)
def StyleText(self, event): """Handle the EVT_STC_STYLENEEDED event""" stc = event.GetEventObject() # Last correctly styled character last_styled_pos = stc.GetEndStyled() # Get styling range for this call line = stc.LineFromPosition(last_styled_pos) start_pos = stc.PositionFromLine(line) end_pos = event.GetPosition() # Walk the line and find all the symbols to style # Note: little inefficient doing one char at a time # but just to illustrate the process. while start_pos < end_pos: stc.StartStyling(start_pos, 0x1f) char = stc.GetCharAt(start_pos) if char in self.ortho_symbols: # Set Symbol Keyword style style = OrthoEventsLexer.STC_STYLE_ORTHO_KW else: # Set Default style style = OrthoEventsLexer.STC_STYLE_ORTHO_DEFAULT # Set the styling byte information for 1 char from # current styling position (start_pos) with the # given style. stc.SetStyling(1, style) start_pos += 1
def StyleText(stc, start, end): """Style the text @param stc: Styled text control instance @param start: Start position @param end: end position @todo: performance improvements @todo: style errors caused by unicode characters (related to internal utf8) """ cpos = 0 stc.StartStyling(cpos, 0x1f) lexer = get_lexer_by_name("s") is_wineol = stc.GetEOLMode() == wx.stc.STC_EOL_CRLF for token, txt in lexer.get_tokens(stc.GetTextRange(0, end)): style = TOKEN_MAP.get(token, STC_S_DEFAULT) tlen = len(txt) # Account for \r\n end of line characters if is_wineol and "\n" in txt: tlen += txt.count("\n") if tlen: stc.SetStyling(tlen, style) cpos += tlen stc.StartStyling(cpos, 0x1f)
def styleText(self, stc, start, end): dprint("Styling text from %d - %d" % (start, end)) start = self.adjustStart(stc, start) for pos, count, style in self.iterStyles(stc, start, end): #dprint("pos=%d, count=%d: token=%d" % (pos, count, style)) if count > 0: stc.StartStyling(pos, 0x1f) stc.SetStyling(count, style)
def apply(self, ): stc = self.stc start = self.start if not self.started: stc.StartStyling(self.start, self.bits) for length, style in self.buffer: stc.SetStyling(length, style) start += length self.buffer = [] self.start = start
def StyleText(self, evt): """Handle the EVT_STC_STYLENEEDED event.""" stc = evt.GetEventObject() last_styled_pos = stc.GetEndStyled() line = stc.LineFromPosition(last_styled_pos) start_pos = stc.PositionFromLine(line) end_pos = evt.GetPosition() while start_pos < end_pos: stc.StartStyling(start_pos, 0x1f) curchar = chr(stc.GetCharAt(start_pos)) if curchar in self.alpha: start = stc.WordStartPosition(start_pos, True) end = start + 1 while chr(stc.GetCharAt(end)) != " " and end < stc.GetLength(): end += 1 word = stc.GetTextRange(start, end) if word in self.keywords: style = self.STC_EXPR_KEYWORD stc.SetStyling(len(word), style) elif word in self.keywords2: style = self.STC_EXPR_KEYWORD2 stc.SetStyling(len(word), style) else: style = self.STC_EXPR_DEFAULT stc.SetStyling(len(word), style) start_pos += len(word) elif curchar == ";": eol = stc.GetLineEndPosition(stc.LineFromPosition(start_pos)) style = self.STC_EXPR_COMMENT stc.SetStyling(eol - start_pos, style) start_pos = eol else: style = self.STC_EXPR_DEFAULT stc.SetStyling(1, style) start_pos += 1
def StyleText(stc, start, end): """Style the text @param stc: Styled text control instance @param start: Start position @param end: end position """ for index, token, txt in lexer.get_tokens_unprocessed( stc.GetTextRange(0, end)): # print index, token, txt style = TOKEN_MAP.get(token, STC_NONMEM_DEFAULT) # print "Text=%s, len=%s" % (txt, len(txt)) stc.StartStyling(index, 0x1f) tlen = len(txt) if tlen: stc.SetStyling(len(txt), style)
def StyleText(stc, start, end): """Style the text @param stc: Styled text control instance @param start: Start position @param end: end position """ # First, figure out the line based on the position. line = stc.LineFromPosition(start) # Find the start of the line that's been styled before this one. while line > 0 and stc.GetLineState(line) == 0: line -= 1 eline = stc.LineFromPosition(end) state = stc.GetLineState(line) - 1 if state < 0: state = 0 for ln in range(line, eline + 1): text = stc.GetLine(ln).encode('utf-8') len_text = len(text) text = text.strip() if len(text) == 0: state = 0 else: if len(text) > 0: ch = text[0] ix = issl_table.find(ch) if ix >= 0: state = ix + 1 stc.StartStyling(stc.PositionFromLine(ln), 0xFF) stc.SetStyling(len_text, state) stc.SetLineState(ln, state + 1)
def StyleText(self, event): """Handle the EVT_STC_STYLENEEDED event""" stc = event.GetEventObject() featurelist = genbank.gb.get_all_feature_positions() if featurelist == None: #no features pass else: for entry in featurelist: featuretype, complement, start, finish, name, index = entry featuretype = featuretype.replace('-', 'a') #for -10 and -35 region featuretype = featuretype.replace("5'", "a5") #for 5' features featuretype = featuretype.replace("3'", "a3") #for 5' features color = eval(featuretype)['color'] #get the color of feature (as string) assert type(color) == str if color == 'red' and complement == False: style = DNALexer.STC_STYLE_RED_FW elif color == 'red' and complement == True: style = DNALexer.STC_STYLE_RED_RV elif color == 'orange' and complement == False: style = DNALexer.STC_STYLE_ORANGE_FW elif color == 'orange' and complement == True: style = DNALexer.STC_STYLE_ORANGE_RV elif color == 'yellow' and complement == False: style = DNALexer.STC_STYLE_YELLOW_FW elif color == 'yellow' and complement == True: style = DNALexer.STC_STYLE_YELLOW_RV elif color == 'green' and complement == False: style = DNALexer.STC_STYLE_GREEN_FW elif color == 'green' and complement == True: style = DNALexer.STC_STYLE_GREEN_RV elif color == 'cyan' and complement == False: style = DNALexer.STC_STYLE_CYAN_FW elif color == 'cyan' and complement == True: style = DNALexer.STC_STYLE_CYAN_RV elif color == 'blue' and complement == False: style = DNALexer.STC_STYLE_BLUE_FW elif color == 'blue' and complement == True: style = DNALexer.STC_STYLE_BLUE_RV elif color == 'purple' and complement == False: style = DNALexer.STC_STYLE_PURPLE_FW elif color == 'purple' and complement == True: style = DNALexer.STC_STYLE_PURPLE_RV elif color == 'magenta' and complement == False: style = DNALexer.STC_STYLE_MAGENTA_FW elif color == 'magenta' and complement == True: style = DNALexer.STC_STYLE_MAGENTA_RV elif color == 'burgundy' and complement == False: style = DNALexer.STC_STYLE_BURGUNDY_FW elif color == 'burgundy' and complement == True: style = DNALexer.STC_STYLE_BURGUNDY_RV elif color == 'grey' and complement == False: style = DNALexer.STC_STYLE_GREY_FW elif color == 'grey' and complement == True: style = DNALexer.STC_STYLE_GREY_RV else: style = DNALexer.STC_STYLE_DEFAULT start -= 1 stc.StartStyling(start, 0x1f) length = finish-start if length == 0: stc.StartStyling(start-1, 0x1f) length = 1 stc.SetStyling(length, style) #color restriction sites for enzyme in genbank.restriction_sites: sites = genbank.restriction_sites[enzyme].restrictionSites if len(sites) > 0: for site in sites: start = site[1] finish = site[2] style = DNALexer.STC_STYLE_ENZYMES if start < finish: # enzyme cuts in the strain stc.StartStyling(start-1, 0x1f) length = finish-(start-1) if length == 0: stc.StartStyling(start-1, 0x1f) length = 1 stc.SetStyling(length, style) else: # enzyme is exactly throughout the 0 # the beginning: stc.StartStyling(0, 0x1f) length = finish stc.SetStyling(length, style) # and the end: stc.StartStyling(start-1, 0x1f) length = len(genbank.gb.gbfile['dna']) - start + 1 stc.SetStyling(length, style) #color search hits if genbank.search_hits != None: for hit in genbank.search_hits: ##add logic here for hits that are broken up start, finish = hit style = DNALexer.STC_STYLE_SEARCH_HITS stc.StartStyling(start-1, 0x1f) length = finish-(start-1) if length == 0: stc.StartStyling(start-1, 0x1f) length = 1 stc.SetStyling(length, style)