def __init__(self, document, palette): QtGui.QSyntaxHighlighter.__init__(self, document) self._palette = palette # Multi-line strings (expression, flag, style) # FIXME: The triple-quotes in these two lines will mess up the # syntax highlighting from this point onward self.tri_single = (QtCore.QRegExp("'''"), 1, self._style("string2")) self.tri_double = (QtCore.QRegExp('"""'), 2, self._style("string2")) rules = [] # Keyword, operator, and brace rules rules += [ (r"\b%s\b" % w, 0, self._style("keyword")) for w in PythonSyntaxHighlighter.keywords ] rules += [ (r"\b%s\b" % w, 0, self._style("builtin")) for w in PythonSyntaxHighlighter.builtins ] rules += [ (r"%s" % o, 0, self._style("operator")) for o in PythonSyntaxHighlighter.operators ] rules += [ (r"%s" % b, 0, self._style("brace")) for b in PythonSyntaxHighlighter.braces ] # All other rules rules += [ # 'self' (r"\bself\b", 0, self._style("self")), # Double-quoted string, possibly containing escape sequences (r'"[^"\\]*(\\.[^"\\]*)*"', 0, self._style("string")), # Single-quoted string, possibly containing escape sequences (r"'[^'\\]*(\\.[^'\\]*)*'", 0, self._style("string")), # 'def' followed by an identifier (r"\bdef\b\s*(\w+)", 1, self._style("defclass")), # 'class' followed by an identifier (r"\bclass\b\s*(\w+)", 1, self._style("defclass")), # From '#' until a newline (r"#[^\n]*", 0, self._style("comment")), # Numeric literals (r"\b[+-]?[0-9]+[lL]?\b", 0, self._style("numbers")), (r"\b[+-]?0[xX][0-9A-Fa-f]+[lL]?\b", 0, self._style("numbers")), ( r"\b[+-]?[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?\b", 0, self._style("numbers"), ), ] # Build a QtCore.QRegExp for each pattern self.rules = [(QtCore.QRegExp(pat), index, fmt) for (pat, index, fmt) in rules]
def __init__(self, parent): """ Construction :param parent: The parent QObject """ QtCore.QObject.__init__(self, parent) self._show_all_versions = False self._filter_reg_exp = QtCore.QRegExp() self._reset_user_lists()
def __init__(self, parent): """ Construction :param parent: The parent QObject """ QtCore.QObject.__init__(self, parent) self._show_all_versions = False self._filter_reg_exp = QtCore.QRegExp() self._available_users = [g_user_cache.current_user ] if g_user_cache.current_user else [] self._users = [g_user_cache.current_user ] if g_user_cache.current_user else []
def _update_filter(self, search_text): """ Update the search text in the filter model. :param search_text: The new search text to update the filter model with """ view_model = self._ui.task_tree.model() if not isinstance(view_model, EntityProxyModel): return # update the proxy filter search text: filter_reg_exp = QtCore.QRegExp(search_text, QtCore.Qt.CaseInsensitive, QtCore.QRegExp.FixedString) view_model.setFilterRegExp(filter_reg_exp)
def _on_search_changed(self, search_text): """ Slot triggered when the search text has been changed. :param search_text: The new search text """ # reset the current selection and get the previously selected item: prev_selected_item = self._reset_selection() try: # update the proxy filter search text: filter_reg_exp = QtCore.QRegExp(search_text, QtCore.Qt.CaseInsensitive, QtCore.QRegExp.FixedString) self._file_filters.filter_reg_exp = filter_reg_exp finally: # and update the selection - this will restore the original selection if possible. self._update_selection(prev_selected_item)
def _on_search_changed(self, search_text): """ Slot triggered when the search text has been changed. :param search_text: The new search text """ # reset the current selection without emitting any signals: prev_selected_item = self._reset_selection() try: # update the proxy filter search text: filter_reg_exp = QtCore.QRegExp(search_text, QtCore.Qt.CaseInsensitive, QtCore.QRegExp.FixedString) self._ui.entity_tree.model().setFilterRegExp(filter_reg_exp) finally: # and update the selection - this will restore the original selection if possible. self._update_selection(prev_selected_item) self._fix_expanded_rows()
def find_all(self, pattern, logs): highlight_format = QtGui.QTextCharFormat() highlight_format.setBackground( QtGui.QBrush(QtGui.QColor(80, 80, 80)) ) regex = QtCore.QRegExp(pattern, QtCore.Qt.CaseInsensitive) matches = [] pos = 0 index = regex.indexIn(logs, pos) count = 0 while (index != -1): count += 1 matched_length = regex.matchedLength() # append start index and length of last matched string # length could be different matches.append((index, matched_length)) # select the matched text and apply the desired format self.highlight_one(index, matched_length, highlight_format) # Move to the next match pos = index + matched_length index = regex.indexIn(logs, pos) return matches
def is_str_valid(self, value): """ Filter the incoming string value. :param value: The value to filter. :type value: str :return: True if the filter accepts the value, else False. :rtype: bool """ if self.filter_op == self.FilterOp.EQUAL: return value == self.filter_value if self.filter_op == self.FilterOp.NOT_EQUAL: return value != self.filter_value if self.filter_op in (self.FilterOp.IN, self.FilterOp.NOT_IN): if self.filter_value is None: self.filter_value = "" if value is None: value = "" regex = QtCore.QRegExp(self.filter_value, QtCore.Qt.CaseInsensitive, QtCore.QRegExp.FixedString) match = regex.indexIn(value) if self.filter_op == self.FilterOp.IN: return match >= 0 if self.filter_op == self.FilterOp.NOT_IN: return match < 0 assert False, "Unsupported operation for filter type 'str'" return False