当前位置: 首页>>代码示例>>Python>>正文


Python QRegExp.pos方法代码示例

本文整理汇总了Python中PyQt5.QtCore.QRegExp.pos方法的典型用法代码示例。如果您正苦于以下问题:Python QRegExp.pos方法的具体用法?Python QRegExp.pos怎么用?Python QRegExp.pos使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyQt5.QtCore.QRegExp的用法示例。


在下文中一共展示了QRegExp.pos方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: highlightBlock

# 需要导入模块: from PyQt5.QtCore import QRegExp [as 别名]
# 或者: from PyQt5.QtCore.QRegExp import pos [as 别名]
    def highlightBlock(self, text):
        for pattern, format in self.rules:
            exp = QRegExp(pattern)
            index = exp.indexIn(text)
            while index >= 0:
                length = exp.matchedLength()
                if exp.numCaptures() > 0:
                    self.setFormat(exp.pos(1), len(str(exp.cap(1))), format)
                else:
                    self.setFormat(exp.pos(0), len(str(exp.cap(0))), format)
                index = exp.indexIn(text, index + length)

        # Multi line strings
        start = self.multilineStart
        end = self.multilineEnd

        self.setCurrentBlockState(0)
        startIndex, skip = 0, 0
        if self.previousBlockState() != 1:
            startIndex, skip = start.indexIn(text), 3
        while startIndex >= 0:
            endIndex = end.indexIn(text, startIndex + skip)
            if endIndex == -1:
                self.setCurrentBlockState(1)
                commentLen = len(text) - startIndex
            else:
                commentLen = endIndex - startIndex + 3
            self.setFormat(startIndex, commentLen, self.stringFormat)
            startIndex, skip = (start.indexIn(text,
                                              startIndex + commentLen + 3),
                                3)
开发者ID:srio,项目名称:Orange-XOPPY,代码行数:33,代码来源:python_script.py

示例2: run

# 需要导入模块: from PyQt5.QtCore import QRegExp [as 别名]
# 或者: from PyQt5.QtCore.QRegExp import pos [as 别名]
    def run(self):
        """Execute this rules in another thread to avoid blocking the ui."""
        styles = {}
        self.msleep(300)
        block = self._highlighter.document().begin()
        while block.blockNumber() != -1:
            text = block.text()
            formats = []

            for expression, nth, char_format in self._highlighter.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))

                    formats.append((index, length, char_format))
                    index = expression.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))
                formats.append((index, length, STYLES['spaces']))
                index = expression.indexIn(text, index + length)

            styles[block.blockNumber()] = formats
            block = block.next()# block = next(block)
        self.highlightingDetected.emit(styles)
开发者ID:Salmista-94,项目名称:Ninja_PyQt5,代码行数:34,代码来源:highlighter.py

示例3: __autoIncFilename

# 需要导入模块: from PyQt5.QtCore import QRegExp [as 别名]
# 或者: from PyQt5.QtCore.QRegExp import pos [as 别名]
 def __autoIncFilename(self):
     """
     Private method to auto-increment the file name.
     """
     # Extract the file name
     name = os.path.basename(self.__filename)
     
     # If the name contains a number, then increment it.
     numSearch = QRegExp("(^|[^\\d])(\\d+)")
     # We want to match as far left as possible, and when the number is
     # at the start of the name.
     
     # Does it have a number?
     start = numSearch.lastIndexIn(name)
     if start != -1:
         # It has a number, increment it.
         start = numSearch.pos(2)    # Only the second group is of interest.
         numAsStr = numSearch.capturedTexts()[2]
         number = "{0:0{width}d}".format(
             int(numAsStr) + 1, width=len(numAsStr))
         name = name[:start] + number + name[start + len(numAsStr):]
     else:
         # no number
         start = name.rfind('.')
         if start != -1:
             # has a '.' somewhere, e.g. it has an extension
             name = name[:start] + '1' + name[start:]
         else:
             # no extension, just tack it on to the end
             name += '1'
     
     self.__filename = os.path.join(os.path.dirname(self.__filename), name)
     self.__updateCaption()
开发者ID:pycom,项目名称:EricShort,代码行数:35,代码来源:SnapWidget.py

示例4: Highlighter

# 需要导入模块: from PyQt5.QtCore import QRegExp [as 别名]
# 或者: from PyQt5.QtCore.QRegExp import pos [as 别名]

#.........这里部分代码省略.........
        char_format.setUnderlineColor(QColor(
            resources.CUSTOM_SCHEME.get('pep8-underline',
                resources.COLOR_SCHEME['pep8-underline'])))
        char_format.setUnderlineStyle(
            QTextCharFormat.WaveUnderline)
        return char_format

    def __highlight_lint(self, char_format, user_data):
        """Highlight the lines with lint errors."""
        user_data.error = True
        char_format = char_format.toCharFormat()
        char_format.setUnderlineColor(QColor(
            resources.CUSTOM_SCHEME.get('error-underline',
                resources.COLOR_SCHEME['error-underline'])))
        char_format.setUnderlineStyle(
            QTextCharFormat.WaveUnderline)
        return char_format

    def __highlight_migration(self, char_format, user_data):
        """Highlight the lines with lint errors."""
        user_data.error = True
        char_format = char_format.toCharFormat()
        char_format.setUnderlineColor(QColor(
            resources.CUSTOM_SCHEME.get('migration-underline',
                resources.COLOR_SCHEME['migration-underline'])))
        char_format.setUnderlineStyle(
            QTextCharFormat.WaveUnderline)
        return char_format

    def highlightBlock(self, text):
        """Apply syntax highlighting to the given block of text."""
        self.highlight_function(text)

    def set_open_visible_area(self, is_line, position):
        """Set the range of lines that should be highlighted on open."""
        if is_line:
            self.visible_limits = (position - 50, position + 50)

    def open_highlight(self, text):
        """Only highlight the lines inside the accepted range."""
        if self.visible_limits[0] <= self.currentBlock().blockNumber() <= \
           self.visible_limits[1]:
            self.realtime_highlight(text)
        else:
            self.setCurrentBlockState(0)

    def async_highlight(self):
        """Execute a thread to collect the info of the things to highlight.

        The thread will collect the data from where to where to highlight,
        and which kind of highlight to use for those sections, and return
        that info to the main thread after it process all the file."""
        self.thread_highlight = HighlightParserThread(self)
        self.thread_highlight.highlightingDetected.connect(self._execute_threaded_highlight)
        self.thread_highlight.start()

    def _execute_threaded_highlight(self, styles=None):
        """Function called with the info collected when the thread ends."""
        self.highlight_function = self.threaded_highlight
        if styles:
            self._styles = styles
            lines = list(set(styles.keys()) -
                set(range(self.visible_limits[0], self.visible_limits[1])))
            # Highlight the rest of the lines that weren't highlighted on open
            self.rehighlight_lines(lines, False)
        else:
开发者ID:Salmista-94,项目名称:Ninja_PyQt5,代码行数:70,代码来源:highlighter.py

示例5: realtime_highlight

# 需要导入模块: from PyQt5.QtCore import QRegExp [as 别名]
# 或者: from PyQt5.QtCore.QRegExp import pos [as 别名]
    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)
开发者ID:Salmista-94,项目名称:Ninja_PyQt5,代码行数:86,代码来源:highlighter.py

示例6: highlightBlock

# 需要导入模块: from PyQt5.QtCore import QRegExp [as 别名]
# 或者: from PyQt5.QtCore.QRegExp import pos [as 别名]
    def highlightBlock(self, text):
        """Apply syntax highlighting to the given block of text.
        """
        basicHighlighter.highlightBlockBefore(self, text)

        # Check if syntax highlighting is enabled
        if self.style is None:
            default = QTextBlockFormat()
            QTextCursor(self.currentBlock()).setBlockFormat(default)
            print("t2tHighlighter.py: is style supposed to be None?")
            return

        block = self.currentBlock()
        oldState = blockUserData.getUserState(block)
        self.identifyBlock(block)
        # formatBlock prevent undo/redo from working
        # TODO: find a todo/undo compatible way of formatting block
        # self.formatBlock(block)

        state = blockUserData.getUserState(block)
        data = blockUserData.getUserData(block)
        inList = self.isList(block)

        op = self.style.format(State.MARKUP)

        # self.setFormat(0, len(text), self.style.format(State.DEFAULT))

        # InDocRules: is it a settings which might have a specific rule,
        # a comment which contains color infos, or a include conf?
        # r'^%!p[or][se]t?proc[^\s]*\s*:\s*\'(.*)\'\s*\'.*\''
        rlist = [QRegExp(r'^%!p[or][se]t?proc[^\s]*\s*:\s*((\'[^\']*\'|\"[^\"]*\")\s*(\'[^\']*\'|\"[^\"]*\"))'),
                 # pre/postproc
                 QRegExp(r'^%.*\s\((.*)\)'),  # comment
                 QRegExp(r'^%!includeconf:\s*([^\s]*)\s*')]  # includeconf
        for r in rlist:
            if r.indexIn(text) != -1:
                self.parseInDocRules()

        # Format the whole line:
        for lineState in [
            State.BLOCKQUOTE_LINE,
            State.HORIZONTAL_LINE,
            State.HEADER_LINE,
        ]:
            if not inList and state == lineState:
                self.setFormat(0, len(text), self.style.format(lineState))

        for (lineState, marker) in [
            (State.COMMENT_LINE, "%"),
            (State.CODE_LINE, "```"),
            (State.RAW_LINE, "\"\"\""),
            (State.TAGGED_LINE, "'''"),
            (State.SETTINGS_LINE, "%!")
        ]:
            if state == lineState and \
                    not (inList and state == State.SETTINGS_LINE):
                n = 0
                # If it's a comment, we want to highlight all '%'.
                if state == State.COMMENT_LINE:
                    while text[n:n + 1] == "%":
                        n += 1
                    n -= 1

                # Apply Format
                self.setFormat(0, len(marker) + n, op)
                self.setFormat(len(marker) + n,
                               len(text) - len(marker) - n,
                               self.style.format(lineState))

                # If it's a setting, we might do something
                if state == State.SETTINGS_LINE:
                    # Target
                    r = QRegExp(r'^%!([^\s]+)\s*:\s*(\b\w*\b)$')
                    if r.indexIn(text) != -1:
                        setting = r.cap(1)
                        val = r.cap(2)
                        if setting == "target" and \
                                        val in self.editor.main.targetsNames:
                            self.editor.fileWidget.preview.setPreferredTarget(val)

                    # Pre/postproc
                    r = QRegExp(r'^%!p[or][se]t?proc[^\s]*\s*:\s*((\'[^\']*\'|\"[^\"]*\")\s*(\'[^\']*\'|\"[^\"]*\"))')
                    if r.indexIn(text) != -1:
                        p = r.pos(1)
                        length = len(r.cap(1))
                        self.setFormat(p, length, self.style.makeFormat(base=self.format(p),
                                                                        fixedPitch=True))

        # Tables
        for lineState in [State.TABLE_LINE, State.TABLE_HEADER]:
            if state == lineState:
                for i, t in enumerate(text):
                    if t == "|":
                        self.setFormat(i, 1, op)
                    else:
                        self.setFormat(i, 1, self.style.format(lineState))

        # Lists
        # if text == "  p": print(data.isList())
        if data.isList():
#.........这里部分代码省略.........
开发者ID:georgehank,项目名称:manuskript,代码行数:103,代码来源:t2tHighlighter.py


注:本文中的PyQt5.QtCore.QRegExp.pos方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。