Пример #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)))
 def _included_files(self, path):
     '''
     Returns all included files in the given file.
     '''
     result = []
     with open(path, 'r') as f:
         data = f.read()
         reg = QRegExp("=[\s\t]*\".*\"")
         reg.setMinimal(True)
         pos = reg.indexIn(data)
         while pos != -1 and self._isrunning:
             try:
                 pp = interpret_path(reg.cap(0).strip('"'))
                 f = QFile(pp)
                 ext = os.path.splitext(pp)
                 if f.exists() and ext[1] in nm.settings().SEARCH_IN_EXT:
                     result.append(pp)
             except Exception as exp:
                 parsed_text = pp
                 try:
                     parsed_text = reg.cap(0).strip('"')
                 except:
                     pass
                 self.warning_signal.emit("Error while parse '%s': %s" %
                                          (parsed_text, exp))
             pos += reg.matchedLength()
             pos = reg.indexIn(data, pos)
     return result
Пример #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 _included_files(self, path):
     '''
     Returns all included files in the given file.
     '''
     result = []
     with open(path, 'r') as f:
         data = f.read()
         reg = QRegExp("=[\s\t]*\".*\"")
         reg.setMinimal(True)
         pos = reg.indexIn(data)
         while pos != -1 and self._isrunning:
             try:
                 pp = interpret_path(reg.cap(0).strip('"'))
                 f = QFile(pp)
                 ext = os.path.splitext(pp)
                 if f.exists() and ext[1] in nm.settings().SEARCH_IN_EXT:
                     result.append(pp)
             except Exception as exp:
                 parsed_text = pp
                 try:
                     parsed_text = reg.cap(0).strip('"')
                 except:
                     pass
                 self.warning_signal.emit("Error while parse '%s': %s" % (parsed_text, exp))
             pos += reg.matchedLength()
             pos = reg.indexIn(data, pos)
     return result
 def _create_regexp(self,
                    pattern='',
                    cs=Qt.CaseInsensitive,
                    syntax=QRegExp.Wildcard,
                    minimal=False):
     _regexp = QRegExp(pattern, cs, syntax)
     _regexp.setMinimal(minimal)
     return _regexp
Пример #6
0
 def _create_regexp(self, pattern=''):
     _regexp = QRegExp()
     _regexp.setMinimal(True)
     _regexp.setPattern(pattern)
     return _regexp
Пример #7
0
 def mark_block(self, block, position):
     text = block.text()
     word, idx_word = self._get_current_word(text, position)
     for hlblock in self._tag_hl_last:
         self.rehighlightBlock(hlblock)
     del self._tag_hl_last[:]
     self._tag_hl_range = [(idx_word, len(word))]
     next_block = block
     open_braces = 0
     closed_braces = 0
     idx_search = idx_word
     rindex = -1
     loop = 0
     tag_len = 0
     if self._isclosetag(word):
         # we are at the close tag: search for the open tag
         opentag = '<%s' % self._get_tag(word)
         tag_len = len(opentag)
         while rindex == -1 and next_block.isValid():
             rindex = text.rfind(opentag, 0, idx_search)
             obr, cbr = self._get_braces_count(
                 text[rindex if rindex != -1 else 0:idx_search])
             open_braces += obr
             closed_braces += cbr
             loop += 1
             if loop > 50000:
                 rindex = -1
                 break
             if rindex == -1:
                 next_block = next_block.previous()
                 text = next_block.text()
                 idx_search = len(text)
             elif open_braces <= closed_braces:
                 idx_search = rindex
                 rindex = -1
     elif self._isopentag(word):
         # we are at the open tag: search for the close tag
         closetag = QRegExp("</%s>|/>" % self._get_tag(word))
         closetag.setMinimal(True)
         while rindex == -1 and next_block.isValid():
             rindex = closetag.indexIn(text, idx_search)
             max_search_idx = rindex + closetag.matchedLength(
             ) if rindex != -1 else len(text)
             obr, cbr = self._get_braces_count(
                 text[idx_search:max_search_idx])
             open_braces += obr
             closed_braces += cbr
             loop += 1
             if loop > 50000:
                 rindex = -1
                 break
             if rindex == -1:
                 next_block = next_block.next()
                 text = next_block.text()
                 idx_search = 0
             elif open_braces > closed_braces:
                 idx_search = rindex + closetag.matchedLength()
                 rindex = -1
             tag_len = closetag.matchedLength()
     else:
         self._tag_hl_range = []
     self._end_tag_found = rindex != -1
     if self._tag_hl_range and block != next_block:
         self.rehighlightBlock(block)
         self._tag_hl_last.append(block)
     if rindex != -1:
         self._tag_hl_range.append((rindex, tag_len))
         self.rehighlightBlock(next_block)
         self._tag_hl_last.append(next_block)
Пример #8
0
 def mark_block(self, block, position):
     text = block.text()
     word, idx_word = self._get_current_word(text, position)
     for hlblock in self._tag_hl_last:
         self.rehighlightBlock(hlblock)
     self._tag_hl_last.clear()
     self._tag_hl_range = [(idx_word, len(word))]
     next_block = block
     open_braces = 0
     closed_braces = 0
     idx_search = idx_word
     rindex = -1
     loop = 0
     tag_len = 0
     if self._isclosetag(word):
         # we are at the close tag: search for the open tag
         opentag = '<%s' % self._get_tag(word)
         tag_len = len(opentag)
         while rindex == -1 and next_block.isValid():
             rindex = text.rfind(opentag, 0, idx_search)
             obr, cbr = self._get_braces_count(text[rindex if rindex != -1 else 0:idx_search])
             open_braces += obr
             closed_braces += cbr
             loop += 1
             if loop > 50000:
                 rindex = -1
                 break
             if rindex == -1:
                 next_block = next_block.previous()
                 text = next_block.text()
                 idx_search = len(text)
             elif open_braces <= closed_braces:
                 idx_search = rindex
                 rindex = -1
     elif self._isopentag(word):
         # we are at the open tag: search for the close tag
         closetag = QRegExp("</%s>|/>" % self._get_tag(word))
         closetag.setMinimal(True)
         while rindex == -1 and next_block.isValid():
             rindex = closetag.indexIn(text, idx_search)
             max_search_idx = rindex + closetag.matchedLength() if rindex != -1 else len(text)
             obr, cbr = self._get_braces_count(text[idx_search:max_search_idx])
             open_braces += obr
             closed_braces += cbr
             loop += 1
             if loop > 50000:
                 rindex = -1
                 break
             if rindex == -1:
                 next_block = next_block.next()
                 text = next_block.text()
                 idx_search = 0
             elif open_braces > closed_braces:
                 idx_search = rindex + closetag.matchedLength()
                 rindex = -1
             tag_len = closetag.matchedLength()
     else:
         self._tag_hl_range = []
     self._end_tag_found = rindex != -1
     if self._tag_hl_range and block != next_block:
         self.rehighlightBlock(block)
         self._tag_hl_last.add(block)
     if rindex != -1:
         self._tag_hl_range.append((rindex, tag_len))
         self.rehighlightBlock(next_block)
         self._tag_hl_last.add(next_block)
Пример #9
0
 def _create_regexp(self, pattern=''):
     _regexp = QRegExp()
     _regexp.setMinimal(True)
     _regexp.setPattern(pattern)
     return _regexp