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


Python QRegExp.capturedTexts方法代码示例

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


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

示例1: __autoIncFilename

# 需要导入模块: from PyQt5.QtCore import QRegExp [as 别名]
# 或者: from PyQt5.QtCore.QRegExp import capturedTexts [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

示例2: CallTraceViewer

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

#.........这里部分代码省略.........
                    f = open(fname, "w", encoding="utf-8")
                    itm = self.callTrace.topLevelItem(0)
                    while itm is not None:
                        isCall = itm.data(0, Qt.UserRole)
                        if isCall:
                            call = "->"
                        else:
                            call = "<-"
                        f.write("{0} {1} || {2}\n".format(
                            call,
                            itm.text(1), itm.text(2)))
                        itm = self.callTrace.itemBelow(itm)
                    f.close()
                except IOError as err:
                    E5MessageBox.critical(
                        self,
                        self.tr("Error saving Call Trace Info"),
                        self.tr("""<p>The call trace info could not"""
                                """ be written to <b>{0}</b></p>"""
                                """<p>Reason: {1}</p>""")
                        .format(fname, str(err)))
    
    @pyqtSlot(QTreeWidgetItem, int)
    def on_callTrace_itemDoubleClicked(self, item, column):
        """
        Private slot to open the double clicked file in an editor.
        
        @param item reference to the double clicked item (QTreeWidgetItem)
        @param column column that was double clicked (integer)
        """
        if item is not None and column > 0:
            columnStr = item.text(column)
            if self.__entryRe.exactMatch(columnStr.strip()):
                filename, lineno, func = self.__entryRe.capturedTexts()[1:]
                try:
                    lineno = int(lineno)
                except ValueError:
                    # do nothing, if the line info is not an integer
                    return
                if self.__projectMode:
                    filename = self.__project.getAbsolutePath(filename)
                self.sourceFile.emit(filename, lineno)
    
    def clear(self):
        """
        Public slot to clear the call trace info.
        """
        self.callTrace.clear()
        self.__callStack = []
    
    def setProjectMode(self, enabled):
        """
        Public slot to set the call trace viewer to project mode.
        
        In project mode the call trace info is shown with project relative
        path names.
        
        @param enabled flag indicating to enable the project mode (boolean)
        """
        self.__projectMode = enabled
        if enabled and self.__project is None:
            self.__project = e5App().getObject("Project")
    
    def __addCallTraceInfo(self, isCall, fromFile, fromLine, fromFunction,
                           toFile, toLine, toFunction):
        """
开发者ID:pycom,项目名称:EricShort,代码行数:70,代码来源:CallTraceViewer.py

示例3: Highlighter

# 需要导入模块: from PyQt5.QtCore import QRegExp [as 别名]
# 或者: from PyQt5.QtCore.QRegExp import capturedTexts [as 别名]
class Highlighter(QSyntaxHighlighter):
    """ Syntax Highlighting

    This class defines rules, a rule consists of a QRegExp pattern and a
    QTextCharFormat instance.
    """

    # Keywords
    KEYWORDS = [
        "select",
        "project",
        "rename",
        "product",
        "njoin",
        "louter",
        "router",
        "fouter",
        "difference",
        "intersect",
        "union",
        "and",
        "or"
    ]

    def __init__(self, editor):
        super(Highlighter, self).__init__(editor)
        # Keywords format
        keyword_format = QTextCharFormat()
        keyword_format.setForeground(QColor("#222"))
        keyword_format.setFontWeight(QFont.Bold)

        # Rules
        self._rules = [(QRegExp("\\b" + pattern + "\\b"), keyword_format)
                       for pattern in Highlighter.KEYWORDS]

        # vars
        var_format = QTextCharFormat()
        var_pattern = QRegExp("\w+\s*\:\=")
        var_format.setFontWeight(QFont.Bold)
        var_format.setForeground(QColor("#dd1144"))

        self._rules.append((var_pattern, var_format))

        op_format = QTextCharFormat()
        op_pattern = QRegExp("(\\:=|\\(|\\))|=|<|>")
        op_format.setForeground(QColor("#222"))
        op_format.setFontWeight(QFont.Bold)
        self._rules.append((op_pattern, op_format))
        # Number format
        number_format = QTextCharFormat()
        number_pattern = QRegExp(r"\b([A-Z0-9]+)(?:[ _-](\d+))?\b")
        number_pattern.setMinimal(True)
        number_format.setForeground(QColor("orange"))
        self._rules.append((number_pattern, number_format))

        # String format
        string_format = QTextCharFormat()
        string_pattern = QRegExp("\'.*\'")
        string_pattern.setMinimal(True)
        string_format.setForeground(Qt.darkGreen)
        self._rules.append((string_pattern, string_format))

        # Comment format
        comment_format = QTextCharFormat()
        comment_pattern = QRegExp("%[^\n]*")
        comment_format.setForeground(QColor("#999988"))
        comment_format.setFontItalic(True)
        self._rules.append((comment_pattern, comment_format))

        # Paren
        self.paren = QRegExp('\(|\)')

    def highlightBlock(self, text):
        """ Reimplementation """

        block_data = TextBlockData()
        # Paren
        index = self.paren.indexIn(text, 0)
        while index >= 0:
            matched_paren = str(self.paren.capturedTexts()[0])
            info = ParenInfo(matched_paren, index)
            block_data.insert_paren_info(info)
            index = self.paren.indexIn(text, index + 1)

        self.setCurrentBlockUserData(block_data)

        for pattern, _format in self._rules:
            expression = QRegExp(pattern)
            index = expression.indexIn(text)
            while index >= 0:
                length = expression.matchedLength()
                self.setFormat(index, length, _format)
                index = expression.indexIn(text, index + length)

        self.setCurrentBlockState(0)
开发者ID:yoshitomimaehara,项目名称:pireal,代码行数:97,代码来源:highlighter.py


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