Пример #1
0
    def __init__(self, parent=None):
        QSyntaxHighlighter.__init__(self, parent)
        self.rules = []
        self.commentStart = QRegExp("#")
        self.commentEnd = QRegExp("\n")
        self.commentFormat = QTextCharFormat()
        self.commentFormat.setFontItalic(True)
        self.commentFormat.setForeground(Qt.darkGray)
        f = QTextCharFormat()
        r = QRegExp()
        r.setMinimal(True)
        f.setFontWeight(QFont.Normal)
        f.setForeground(Qt.darkBlue)
        tagList = ["\\bignore_hosts\\b", "\\bsync_hosts\\b",
                   "\\bignore_nodes\\b", "\\bsync_nodes\\b",
                   "\\bignore_topics\\b", "\\bignore_publishers\\b",
                   "\\bignore_topics\\b", "\\bsync_topics\\b",
                   "\\bignore_subscribers\\b", "\\bsync_services\\b",
                   "\\bsync_topics_on_demand\\b", "\\bsync_remote_nodes\\b"]
        for tag in tagList:
            r.setPattern(tag)
            self.rules.append((QRegExp(r), QTextCharFormat(f)))

        f.setForeground(Qt.darkGreen)
        f.setFontWeight(QFont.Bold)
        attrList = ["\\b\\*|\\*\\B|\\/\\*"]
        for attr in attrList:
            r.setPattern(attr)
            self.rules.append((QRegExp(r), QTextCharFormat(f)))
Пример #2
0
    def __init__(self, parent=None):
        QSyntaxHighlighter.__init__(self, parent)
        self.rules = []
        self.comment_start = QRegExp("<!--")
        self.comment_end = QRegExp("-->")
        self.comment_format = self._create_format(Qt.darkGray, 'italic')
#        self.mark_background = QBrush(QColor(251, 247, 222))
        # create patterns for braces
        self.rules.append((self._create_regexp("</?|/?>"), self._create_format(QColor(24, 24, 24))))
        # create patterns for TAG
        tag_list = '|'.join(["\\b%s\\b" % t for t in self.LAUNCH_CHILDS.keys()])
        self.rules.append((self._create_regexp(tag_list), self._create_format(Qt.darkRed)))
        # create patterns for ATTRIBUTES
        attr_list = '|'.join(set(["\\b%s" % attr for v in self.LAUNCH_ATTR.values() for attr in v.keys()]))
        self.rules.append((self._create_regexp(attr_list), self._create_format(QColor(0, 100, 0))))  # darkGreen
        # create patterns for substitutions
        self.rule_arg = (self._create_regexp("\\$\\(.*\\)"), self._create_format(QColor(77, 0, 38)))
        # create patterns for DOCTYPE
        self.rules.append((self._create_regexp("<!DOCTYPE.*>"), self._create_format(Qt.lightGray)))
        self.rules.append((self._create_regexp("<\\?xml.*\\?>"), self._create_format(Qt.lightGray)))
        # create patterns for yaml parameter inside
        self.rules.append((self._create_regexp("^\s*[_.\w]*\s*:"), self._create_format(Qt.darkBlue)))
        # create patterns for yaml oneline strings inside
        self.rules.append((self._create_regexp("'.*'"), self._create_format(Qt.blue)))
        # create pattern for list signes
        self.rules.append((self._create_regexp("^\s*-"), self._create_format(Qt.darkRed, 'bold')))
        # create pattern for digits
        self.rules.append((self._create_regexp("\\d+"), self._create_format(QColor(127, 64, 127))))
        # create patterns for strings
        self.string_pattern = QRegExp("\"")
        self.string_format = self._create_format(Qt.blue)
        # part to select an XML block
        self._tag_hl_range = []  # list with puples (start, length)
        self._tag_hl_last = set()  # set with blocks of last highlighted tags
Пример #3
0
    def __init__(self, parent=None):
        QSyntaxHighlighter.__init__(self, parent)
        self.rules = []
        self.commentStart = QRegExp("#")
        self.commentEnd = QRegExp("\n")
        self.commentFormat = QTextCharFormat()
        self.commentFormat.setFontItalic(True)
        self.commentFormat.setForeground(Qt.darkGray)
        f = QTextCharFormat()
        r = QRegExp()
        r.setMinimal(True)
        f.setFontWeight(QFont.Normal)
        f.setForeground(Qt.darkBlue)
        tagList = [
            "\\bignore_hosts\\b", "\\bsync_hosts\\b", "\\bignore_nodes\\b",
            "\\bsync_nodes\\b", "\\bignore_topics\\b",
            "\\bignore_publishers\\b", "\\bignore_topics\\b",
            "\\bsync_topics\\b", "\\bignore_subscribers\\b",
            "\\bsync_services\\b", "\\bsync_topics_on_demand\\b",
            "\\bsync_remote_nodes\\b"
        ]
        for tag in tagList:
            r.setPattern(tag)
            self.rules.append((QRegExp(r), QTextCharFormat(f)))

        f.setForeground(Qt.darkGreen)
        f.setFontWeight(QFont.Bold)
        attrList = ["\\b\\*|\\*\\B|\\/\\*"]
        for attr in attrList:
            r.setPattern(attr)
            self.rules.append((QRegExp(r), QTextCharFormat(f)))
Пример #4
0
    def __init__(self, parent=None):
        QSyntaxHighlighter.__init__(self, parent)
        self.rules = []
        self.commentStart = QRegExp("#")
        self.commentEnd = QRegExp("\n|\r")
        self.default_format = QTextCharFormat()
        self.default_format.setForeground(QColor(24, 24, 24))
        self.commentFormat = QTextCharFormat()
        self.commentFormat.setFontItalic(True)
        self.commentFormat.setForeground(Qt.darkGray)

        tagList = ["\\btrue\\b", "\\bfalse\\b"]
        # create patterns for tags
        for tag in tagList:
            self.rules.append(
                (self._create_regexp(tag), self._create_format(Qt.blue)))

        # create pattern for digits
        self.rules.append((self._create_regexp("\\d+"),
                           self._create_format(QColor(127, 64, 127))))

        # create pattern for params
        self.rules.append((self._create_regexp("\s*[_.\w]*\s*:"),
                           self._create_format(Qt.darkBlue)))

        # create pattern for params
        self.rules.append(
            (self._create_regexp(":\s*:[_\.\w]*$|:\s*\@[_\.\w]*$"),
             self._create_format(Qt.darkBlue)))

        # create pattern for list signes
        self.rules.append((self._create_regexp("^\s*-"),
                           self._create_format(Qt.darkRed, 'bold')))

        # create pattern for ???
        self.rules.append(
            (self._create_regexp("^---$"), self._create_format(Qt.darkRed)))

        # create pattern for braces
        self.rules.append((self._create_regexp("[\[\]\{\}\,]"),
                           self._create_format(Qt.darkGreen)))

        # create patterns for strings
        self.rules.append((self._create_regexp("\".*\"|\'.*\'"),
                           self._create_format(Qt.blue)))

        # create patterns for substitutions
        self.rules.append((self._create_regexp("\\$\\(.*\\)"),
                           self._create_format(QColor(127, 64, 127))))

        # create patterns for DOCTYPE
        self.rules.append((self._create_regexp("<!DOCTYPE.*>"),
                           self._create_format(Qt.lightGray)))
        self.rules.append((self._create_regexp("<\\?xml.*\\?>"),
                           self._create_format(Qt.lightGray)))
 def __init__(self, parent=None):
     QSyntaxHighlighter.__init__(self, parent)
     self.rules = []
     self.comment_start = QRegExp("<!--")
     self.comment_end = QRegExp("-->")
     self.comment_format = self._create_format(Qt.darkGray, 'italic')
     #        self.mark_background = QBrush(QColor(251, 247, 222))
     # create patterns for braces
     self.rules.append((self._create_regexp("</?|/?>"),
                        self._create_format(QColor(24, 24, 24))))
     # create patterns for TAG
     tag_list = '|'.join(
         ["\\b%s\\b" % t for t in self.LAUNCH_CHILDS.keys()])
     self.rules.append(
         (self._create_regexp(tag_list), self._create_format(Qt.darkRed)))
     # create patterns for ATTRIBUTES
     attr_list = '|'.join(
         set([
             "\\b%s" % attr for v in self.LAUNCH_ATTR.values()
             for attr in v.keys()
         ]))
     self.rules.append((self._create_regexp(attr_list),
                        self._create_format(QColor(0, 100,
                                                   0))))  # darkGreen
     # create patterns for substitutions
     self.rule_arg = (self._create_regexp("\\$\\(.*\\)"),
                      self._create_format(QColor(77, 0, 38)))
     # create patterns for DOCTYPE
     self.rules.append((self._create_regexp("<!DOCTYPE.*>"),
                        self._create_format(Qt.lightGray)))
     self.rules.append((self._create_regexp("<\\?xml.*\\?>"),
                        self._create_format(Qt.lightGray)))
     # create patterns for yaml parameter inside
     self.rules.append((self._create_regexp("^\s*[_.\w]*\s*:"),
                        self._create_format(Qt.darkBlue)))
     # create patterns for yaml oneline strings inside
     self.rules.append(
         (self._create_regexp("'.*'"), self._create_format(Qt.blue)))
     # create pattern for list signes
     self.rules.append((self._create_regexp("^\s*-"),
                        self._create_format(Qt.darkRed, 'bold')))
     # create pattern for digits
     self.rules.append((self._create_regexp("\\d+"),
                        self._create_format(QColor(127, 64, 127))))
     # create patterns for strings
     self.string_pattern = QRegExp("\"")
     self.string_format = self._create_format(Qt.blue)
     # part to select an XML block
     self._tag_hl_range = []  # list with puples (start, length)
     self._tag_hl_last = set()  # set with blocks of last highlighted tags
Пример #6
0
    def __init__(self, parent=None):
        QSyntaxHighlighter.__init__(self, parent)
        self.rules = []
        self.commentStart = QRegExp("#")
        self.commentEnd = QRegExp("\n|\r")
        self.default_format = QTextCharFormat()
        self.default_format.setForeground(QColor(24, 24, 24))
        self.commentFormat = QTextCharFormat()
        self.commentFormat.setFontItalic(True)
        self.commentFormat.setForeground(Qt.darkGray)

        tagList = ["\\btrue\\b", "\\bfalse\\b"]
        # create patterns for tags
        for tag in tagList:
            self.rules.append((self._create_regexp(tag), self._create_format(Qt.blue)))

        # create pattern for digits
        self.rules.append((self._create_regexp("\\d+"), self._create_format(QColor(127, 64, 127))))

        # create pattern for params
        self.rules.append((self._create_regexp("^\s*[_.\w]*\s*:"), self._create_format(Qt.darkBlue)))

        # create pattern for params
        self.rules.append((self._create_regexp(":\s*:[_\.\w]*$|:\s*\@[_\.\w]*$"), self._create_format(Qt.darkBlue)))

        # create pattern for list signes
        self.rules.append((self._create_regexp("^\s*-"), self._create_format(Qt.darkRed, 'bold')))

        # create pattern for ???
        self.rules.append((self._create_regexp("^---$"), self._create_format(Qt.darkRed)))

        # create pattern for braces
        self.rules.append((self._create_regexp("[\[\]\{\}\,]"), self._create_format(Qt.darkGreen)))

        # create patterns for strings
        self.rules.append((self._create_regexp("\".*\"|\'.*\'"), self._create_format(Qt.blue)))

        # create patterns for substitutions
        self.rules.append((self._create_regexp("\\$\\(.*\\)"), self._create_format(QColor(127, 64, 127))))

        # create patterns for DOCTYPE
        self.rules.append((self._create_regexp("<!DOCTYPE.*>"), self._create_format(Qt.lightGray)))
        self.rules.append((self._create_regexp("<\\?xml.*\\?>"), self._create_format(Qt.lightGray)))
 def __init__(self, parent=None):
     QSyntaxHighlighter.__init__(self, parent)
     self._grep_format = QTextCharFormat()
     self._grep_rule = None
     self.rules = []
     self.rules.append((self._create_regexp(r'.*\[DEBUG\].*',
                                            syntax=QRegExp.RegExp),
                        self._create_format(QColor(57, 181, 74))))
     self.rules.append((self._create_regexp(r'.*\[INFO\].*',
                                            syntax=QRegExp.RegExp),
                        self._create_format(QColor('#FFFAFA'))))
     self.rules.append((self._create_regexp(r'.*\[WARN\].*',
                                            syntax=QRegExp.RegExp),
                        self._create_format(QColor(255, 199, 6))))
     self.rules.append((self._create_regexp(r'.*WARNING.*',
                                            syntax=QRegExp.RegExp),
                        self._create_format(QColor(255, 199, 6))))
     self.rules.append((self._create_regexp(r'.*\[ERROR\].*',
                                            syntax=QRegExp.RegExp),
                        self._create_format(QColor(222, 56, 43))))
     self.rules.append((self._create_regexp(r'.*\[FATAL\].*',
                                            syntax=QRegExp.RegExp),
                        self._create_format(QColor(255, 0, 0))))  #red
Пример #8
0
 def __init__(self, parent=None, is_launch=True):
     QSyntaxHighlighter.__init__(self, parent)
     self._is_launch = is_launch
     self.rules = []
     self.comment_start = QRegExp("<!--")
     self.comment_end = QRegExp("-->")
     self.comment_format = self._create_format(Qt.darkGray, 'italic')
     #        self.mark_background = QBrush(QColor(251, 247, 222))
     # create patterns for braces
     self.rules.append((self._create_regexp("</?|/?>"),
                        self._create_format(QColor(24, 24, 24))))
     # create patterns for TAG
     if self._is_launch:
         tag_list = '|'.join(
             ["\\b%s\\b" % t for t in self.LAUNCH_CHILDS.keys()])
         self.rules.append((self._create_regexp(tag_list),
                            self._create_format(Qt.darkRed)))
     else:
         self.rules.append(
             (self._create_regexp(">|/>|<[/.\w:]*[\s\t>]|<[/.\w:]*$"),
              self._create_format(Qt.darkRed)))
     # create patterns for ATTRIBUTES
     if self._is_launch:
         attr_list = '|'.join(
             set([
                 "\\b%s" % attr for v in self.LAUNCH_ATTR.values()
                 for attr in v.keys()
             ]))
         self.rules.append((self._create_regexp(attr_list),
                            self._create_format(QColor(0, 100,
                                                       0))))  # darkGreen
     else:
         self.rules.append((self._create_regexp("[_.\w]*="),
                            self._create_format(QColor(0, 100,
                                                       0))))  # darkGreen
     # create patterns for substitutions
     self.rule_arg = (self._create_regexp("\\$\\(.*\\)"),
                      self._create_format(QColor(77, 0, 38)))
     # create patterns for DOCTYPE
     self.rules.append((self._create_regexp("<!DOCTYPE.*>"),
                        self._create_format(Qt.lightGray)))
     self.rules.append((self._create_regexp("<\\?xml.*\\?>"),
                        self._create_format(Qt.lightGray)))
     # create patterns for yaml parameter inside
     self.rules.append((self._create_regexp("[_.\w]*\s*:"),
                        self._create_format(Qt.darkBlue)))
     # create patterns for yaml oneline strings inside
     self.rules.append(
         (self._create_regexp("'.*'"), self._create_format(Qt.blue)))
     # create pattern for list signes
     self.rules.append((self._create_regexp("^\s*-"),
                        self._create_format(Qt.darkRed, 'bold')))
     # create pattern for digits
     self.rules.append((self._create_regexp("\\d+"),
                        self._create_format(QColor(127, 64, 127))))
     self.yaml_comment_rule = (self._create_regexp("#[.]*"),
                               self._create_format(Qt.darkGray))
     # create deprecated
     self.dep_pattern = []
     if self.DEPRECATED_PARAMETER:
         attr_list = '|'.join(
             set([
                 r'name="%s"' % attr
                 for attr in self.DEPRECATED_PARAMETER.keys()
             ]))
         # print(attr_list)
         self.dep_pattern.append(
             (self._create_regexp(attr_list),
              self._create_format(QColor(250, 0, 0), 'bold')))  # red
     # create patterns for strings
     self.string_pattern = QRegExp("\"")
     self.string_format = self._create_format(Qt.blue)
     # part to select an XML block
     self._tag_hl_range = []  # list with puples (start, length)
     self._tag_hl_last = []  # set with blocks of last highlighted tags
     self._color_hl_tag = QColor(255, 128, 0)
Пример #9
0
    def __init__(self, document, is_dark=False, default=None):
        QSyntaxHighlighter.__init__(self, document)

        def contents_changed():
            self.highlightBlock("document.toPlainText()")

        document.contentsChanged.connect(contents_changed)

        self.is_dark = is_dark
        self.default = default

        global reformat

        if is_dark:
            STYLES = DARK_STYLES
        else:
            STYLES = BRIGHT_STYLES

        if default != None:
            STYLES['defaults'] = reformat(*default)

        # 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 = (QRegExp("'''"), 1, STYLES['string2'])
        self.tri_double = (QRegExp('"""'), 2, STYLES['string2'])

        rules = []

        rules += [(r'%s' % w, 0, STYLES['defaults'])
                  for w in PythonHighlighter.defaults]
        # Keyword, operator, and brace rules
        rules += [(r'\b%s\b' % w, 0, STYLES['keyword'])
                  for w in PythonHighlighter.keywords]
        rules += [(r'%s' % o, 0, STYLES['operator'])
                  for o in PythonHighlighter.operators]
        rules += [(r'%s' % b, 0, STYLES['brace'])
                  for b in PythonHighlighter.braces]

        # All other rules
        rules += [
            # 'self'
            (r'\bself\b', 0, STYLES['self']),

            # Double-quoted string, possibly containing escape sequences
            (r'"[^"\\]*(\\.[^"\\]*)*"', 0, STYLES['string']),
            # Single-quoted string, possibly containing escape sequences
            (r"'[^'\\]*(\\.[^'\\]*)*'", 0, STYLES['string']),

            # 'def' followed by an identifier
            (r'\bdef\b\s*(\w+)', 1, STYLES['defclass']),
            # 'class' followed by an identifier
            (r'\bclass\b\s*(\w+)', 1, STYLES['defclass']),

            # From '#' until a newline
            (r'#[^\n]*', 0, STYLES['comment']),

            # Numeric literals
            (r'\b[+-]?[0-9]+[lL]?\b', 0, STYLES['numbers']),
            (r'\b[+-]?0[xX][0-9A-Fa-f]+[lL]?\b', 0, STYLES['numbers']),
            (r'\b[+-]?[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?\b', 0,
             STYLES['numbers']),
        ]

        # Build a QRegExp for each pattern
        self.rules = [(QRegExp(pat), index, fmt)
                      for (pat, index, fmt) in rules]