def cursor_inside_comment(self): inside = False cursor = self.textCursor() pos = cursor.positionInBlock() user_data = syntax_highlighter.get_user_data(cursor.block()) if (user_data.comment_start != -1) and (pos > user_data.comment_start): inside = True return inside
def cursor_inside_comment(self): inside = False cursor = self.textCursor() pos = cursor.positionInBlock() user_data = syntax_highlighter.get_user_data(cursor.block()) if (user_data.comment_start != -1) and \ (pos > user_data.comment_start): inside = True return inside
def threaded_highlight(self, text): """Highlight each line using the info collected by the thread. This function doesn't need to execute the regular expressions to see where the highlighting starts and end for each rule, it just take the start and end point, and the proper highlighting style from the info returned from the thread and applied that to the document.""" hls = [] block = self.currentBlock() user_data = syntax_highlighter.get_user_data(block) user_data.clear_data() block_number = block.blockNumber() highlight_errors = lambda cf, ud: cf if self.errors and (block_number in self.errors.errorsSummary): highlight_errors = self.__highlight_lint elif self.pep8 and (block_number in self.pep8.pep8checks): highlight_errors = self.__highlight_pep8 elif self.migration and (block_number in self.migration.migration_data): highlight_errors = self.__highlight_migration char_format = block.charFormat() char_format = highlight_errors(char_format, user_data) self.setFormat(0, len(block.text()), char_format) block_styles = self._styles.get(block.blockNumber(), ()) for index, length, char_format in block_styles: char_format = highlight_errors(char_format, user_data) if (self.format(index) != STYLES['string']): self.setFormat(index, length, char_format) if char_format == STYLES['string']: hls.append((index, index + length)) user_data.add_str_group(index, index + length) elif char_format == STYLES['comment']: user_data.comment_start_at(index) self.setCurrentBlockState(0) if not self.multi_start: # Do multi-line strings in_multiline = self.match_multiline( text, *self.tri_single, hls=hls, highlight_errors=highlight_errors, user_data=user_data) if not in_multiline: in_multiline = self.match_multiline( text, *self.tri_double, hls=hls, highlight_errors=highlight_errors, user_data=user_data) else: # Do multi-line comment self.comment_multiline(text, self.multi_end[0], *self.multi_start) block.setUserData(user_data)
def cursor_inside_string(self): inside = False cursor = self.textCursor() pos = cursor.positionInBlock() user_data = syntax_highlighter.get_user_data(cursor.block()) for vals in user_data.str_groups: if vals[0] < pos < vals[1]: inside = True break return inside
def _get_errors_lines(self): """Return the number of lines that contains errors to highlight.""" errors_lines = [] block = self.document().begin() while block.isValid(): user_data = syntax_highlighter.get_user_data(block) if user_data.error: errors_lines.append(block.blockNumber()) block = block.next() return errors_lines
def _get_errors_lines(self): """Return the number of lines that contains errors to highlight.""" errors_lines = [] block = self.document().begin() while block.isValid(): user_data = syntax_highlighter.get_user_data(block) if user_data.error: errors_lines.append(block.blockNumber()) block = block.next()# block = next(block) return errors_lines
def threaded_highlight(self, text): """Highlight each line using the info collected by the thread. This function doesn't need to execute the regular expressions to see where the highlighting starts and end for each rule, it just take the start and end point, and the proper highlighting style from the info returned from the thread and applied that to the document.""" hls = [] block = self.currentBlock() user_data = syntax_highlighter.get_user_data(block) user_data.clear_data() block_number = block.blockNumber() highlight_errors = lambda cf, ud: cf if self.errors and (block_number in self.errors.errorsSummary): highlight_errors = self.__highlight_lint elif self.pep8 and (block_number in self.pep8.pep8checks): highlight_errors = self.__highlight_pep8 elif self.migration and ( block_number in self.migration.migration_data): highlight_errors = self.__highlight_migration char_format = block.charFormat() char_format = highlight_errors(char_format, user_data) self.setFormat(0, len(block.text()), char_format) block_styles = self._styles.get(block.blockNumber(), ()) for index, length, char_format in block_styles: char_format = highlight_errors(char_format, user_data) if (self.format(index) != STYLES['string']): self.setFormat(index, length, char_format) if char_format == STYLES['string']: hls.append((index, index + length)) user_data.add_str_group(index, index + length) elif char_format == STYLES['comment']: user_data.comment_start_at(index) self.setCurrentBlockState(0) if not self.multi_start: # Do multi-line strings in_multiline = self.match_multiline(text, *self.tri_single, hls=hls, highlight_errors=highlight_errors, user_data=user_data) if not in_multiline: in_multiline = self.match_multiline(text, *self.tri_double, hls=hls, highlight_errors=highlight_errors, user_data=user_data) else: # Do multi-line comment self.comment_multiline(text, self.multi_end[0], *self.multi_start) block.setUserData(user_data)
def realtime_highlight(self, text): """Highlight each line while it is being edited. This function apply the proper highlight to the line being edited by the user, this is a really fast process for each line once you already have the document highlighted, but slow to do it the first time to highlight all the lines together.""" hls = [] block = self.currentBlock() user_data = syntax_highlighter.get_user_data(block) user_data.clear_data() block_number = block.blockNumber() highlight_errors = lambda cf, ud: cf if self.errors and (block_number in self.errors.errorsSummary): highlight_errors = self.__highlight_lint elif self.pep8 and (block_number in self.pep8.pep8checks): highlight_errors = self.__highlight_pep8 elif self.migration and (block_number in self.migration.migration_data): highlight_errors = self.__highlight_migration char_format = block.charFormat() char_format = highlight_errors(char_format, user_data) self.setFormat(0, len(block.text()), char_format) for expression, nth, char_format in self.rules: index = expression.indexIn(text, 0) while index >= 0: # We actually want the index of the nth match index = expression.pos(nth) length = len(expression.cap(nth)) char_format = highlight_errors(char_format, user_data) if (self.format(index) != STYLES['string']): self.setFormat(index, length, char_format) if char_format == STYLES['string']: hls.append((index, index + length)) user_data.add_str_group(index, index + length) elif char_format == STYLES['comment']: user_data.comment_start_at(index) index = expression.indexIn(text, index + length) self.setCurrentBlockState(0) if not self.multi_start: # Do multi-line strings in_multiline = self.match_multiline( text, *self.tri_single, hls=hls, highlight_errors=highlight_errors, user_data=user_data) if not in_multiline: in_multiline = self.match_multiline( text, *self.tri_double, hls=hls, highlight_errors=highlight_errors, user_data=user_data) else: # Do multi-line comment self.comment_multiline(text, self.multi_end[0], *self.multi_start) #Highlight selected word if self.selected_word_pattern is not None: index = self.selected_word_pattern.indexIn(text, 0) while index >= 0: index = self.selected_word_pattern.pos(0) length = len(self.selected_word_pattern.cap(0)) char_format = self.format(index) color = STYLES['selectedWord'].foreground().color() color.setAlpha(100) char_format.setBackground(color) self.setFormat(index, length, char_format) index = self.selected_word_pattern.indexIn( text, index + length) #Spaces expression = QRegExp('\s+') index = expression.indexIn(text, 0) while index >= 0: index = expression.pos(0) length = len(expression.cap(0)) char_format = STYLES['spaces'] char_format = highlight_errors(char_format, user_data) self.setFormat(index, length, char_format) index = expression.indexIn(text, index + length) block.setUserData(user_data)
def realtime_highlight(self, text): """Highlight each line while it is being edited. This function apply the proper highlight to the line being edited by the user, this is a really fast process for each line once you already have the document highlighted, but slow to do it the first time to highlight all the lines together.""" hls = [] block = self.currentBlock() user_data = syntax_highlighter.get_user_data(block) user_data.clear_data() block_number = block.blockNumber() highlight_errors = lambda cf, ud: cf if self.errors and (block_number in self.errors.errorsSummary): highlight_errors = self.__highlight_lint elif self.pep8 and (block_number in self.pep8.pep8checks): highlight_errors = self.__highlight_pep8 elif self.migration and ( block_number in self.migration.migration_data): highlight_errors = self.__highlight_migration char_format = block.charFormat() char_format = highlight_errors(char_format, user_data) self.setFormat(0, len(block.text()), char_format) for expression, nth, char_format in self.rules: index = expression.indexIn(text, 0) while index >= 0: # We actually want the index of the nth match index = expression.pos(nth) length = len(expression.cap(nth)) char_format = highlight_errors(char_format, user_data) if (self.format(index) != STYLES['string']): self.setFormat(index, length, char_format) if char_format == STYLES['string']: hls.append((index, index + length)) user_data.add_str_group(index, index + length) elif char_format == STYLES['comment']: user_data.comment_start_at(index) index = expression.indexIn(text, index + length) self.setCurrentBlockState(0) if not self.multi_start: # Do multi-line strings in_multiline = self.match_multiline(text, *self.tri_single, hls=hls, highlight_errors=highlight_errors, user_data=user_data) if not in_multiline: in_multiline = self.match_multiline(text, *self.tri_double, hls=hls, highlight_errors=highlight_errors, user_data=user_data) else: # Do multi-line comment self.comment_multiline(text, self.multi_end[0], *self.multi_start) #Highlight selected word if self.selected_word_pattern is not None: index = self.selected_word_pattern.indexIn(text, 0) while index >= 0: index = self.selected_word_pattern.pos(0) length = len(self.selected_word_pattern.cap(0)) char_format = self.format(index) color = STYLES['selectedWord'].foreground().color() color.setAlpha(100) char_format.setBackground(color) self.setFormat(index, length, char_format) index = self.selected_word_pattern.indexIn( text, index + length) #Spaces expression = QRegExp('\s+') index = expression.indexIn(text, 0) while index >= 0: index = expression.pos(0) length = len(expression.cap(0)) char_format = STYLES['spaces'] char_format = highlight_errors(char_format, user_data) self.setFormat(index, length, char_format) index = expression.indexIn(text, index + length) block.setUserData(user_data)