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


Python QRegExp.captureCount方法代码示例

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


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

示例1: refresh

# 需要导入模块: from PyQt5.QtCore import QRegExp [as 别名]
# 或者: from PyQt5.QtCore.QRegExp import captureCount [as 别名]
    def refresh(self):
        self.setUpdatesEnabled(False)

        pattern = self.patternComboBox.currentText()
        text = self.textComboBox.currentText()

        escaped = str(pattern)
        escaped.replace('\\', '\\\\')
        escaped.replace('"', '\\"')
        self.escapedPatternLineEdit.setText('"' + escaped + '"')

        rx = QRegExp(pattern)
        cs = Qt.CaseSensitive if self.caseSensitiveCheckBox.isChecked() else Qt.CaseInsensitive
        rx.setCaseSensitivity(cs)
        rx.setMinimal(self.minimalCheckBox.isChecked())
        syntax = self.syntaxComboBox.itemData(self.syntaxComboBox.currentIndex())
        rx.setPatternSyntax(syntax)

        palette = self.patternComboBox.palette()
        if rx.isValid():
            palette.setColor(QPalette.Text,
                    self.textComboBox.palette().color(QPalette.Text))
        else:
            palette.setColor(QPalette.Text, Qt.red)
        self.patternComboBox.setPalette(palette)

        self.indexEdit.setText(str(rx.indexIn(text)))
        self.matchedLengthEdit.setText(str(rx.matchedLength()))

        for i in range(self.MaxCaptures):
            self.captureLabels[i].setEnabled(i <= rx.captureCount())
            self.captureEdits[i].setEnabled(i <= rx.captureCount())
            self.captureEdits[i].setText(rx.cap(i))

        self.setUpdatesEnabled(True)
开发者ID:Axel-Erfurt,项目名称:pyqt5,代码行数:37,代码来源:regexp.py

示例2: __scriptDownloaded

# 需要导入模块: from PyQt5.QtCore import QRegExp [as 别名]
# 或者: from PyQt5.QtCore.QRegExp import captureCount [as 别名]
 def __scriptDownloaded(self):
     """
     Private slot to handle the finished download of a script.
     """
     if self.sender() != self.__reply:
         self.finished.emit()
         return
     
     response = bytes(self.__reply.readAll()).decode()
     
     if self.__reply.error() == QNetworkReply.NoError and \
        "// ==UserScript==" in response:
         from Helpviewer import HelpUtilities
         filePath = os.path.join(
             self.__manager.scriptsDirectory(),
             HelpUtilities.getFileNameFromUrl(self.__reply.url()))
         self.__fileName = HelpUtilities.ensureUniqueFilename(filePath)
         
         try:
             f = open(self.__fileName, "w", encoding="utf-8")
         except (IOError, OSError) as err:
             E5MessageBox.critical(
                 None,
                 self.tr("GreaseMonkey Download"),
                 self.tr(
                     """<p>The file <b>{0}</b> could not be opened"""
                     """ for writing.<br/>Reason: {1}</p>""").format(
                     self.__fileName, str(err)))
             self.finished.emit()
             return
         f.write(response)
         f.close()
         
         settings = QSettings(
             os.path.join(self.__manager.requireScriptsDirectory(),
                          "requires.ini"),
             QSettings.IniFormat)
         settings.beginGroup("Files")
         
         rx = QRegExp("@require(.*)\\n")
         rx.setMinimal(True)
         rx.indexIn(response)
         
         for i in range(1, rx.captureCount() + 1):
             url = rx.cap(i).strip()
             if url and not settings.contains(url):
                 self.__requireUrls.append(QUrl(url))
     
     self.__reply.deleteLater()
     self.__reply = None
     
     self.__downloadRequires()
开发者ID:pycom,项目名称:EricShort,代码行数:54,代码来源:GreaseMonkeyDownloader.py

示例3: on_executeButton_clicked

# 需要导入模块: from PyQt5.QtCore import QRegExp [as 别名]
# 或者: from PyQt5.QtCore.QRegExp import captureCount [as 别名]
 def on_executeButton_clicked(self, startpos=0):
     """
     Private slot to execute the entered regexp on the test text.
     
     This slot will execute the entered regexp on the entered test
     data and will display the result in the table part of the dialog.
     
     @param startpos starting position for the regexp matching
     """
     regex = self.regexpLineEdit.text()
     text = self.textTextEdit.toPlainText()
     if regex and text:
         re = QRegExp(regex)
         if self.caseSensitiveCheckBox.isChecked():
             re.setCaseSensitivity(Qt.CaseSensitive)
         else:
             re.setCaseSensitivity(Qt.CaseInsensitive)
         re.setMinimal(self.minimalCheckBox.isChecked())
         syntax = self.syntaxCombo.itemData(self.syntaxCombo.currentIndex())
         wildcard = syntax in [QRegExp.Wildcard, QRegExp.WildcardUnix]
         re.setPatternSyntax(syntax)
         if not re.isValid():
             E5MessageBox.critical(
                 self,
                 self.tr("Error"),
                 self.tr("""Invalid regular expression: {0}""")
                 .format(re.errorString()))
             return
         offset = re.indexIn(text, startpos)
         captures = re.captureCount()
         row = 0
         OFFSET = 5
         
         self.resultTable.setColumnCount(0)
         self.resultTable.setColumnCount(3)
         self.resultTable.setRowCount(0)
         self.resultTable.setRowCount(OFFSET)
         self.resultTable.setItem(
             row, 0, QTableWidgetItem(self.tr("Regexp")))
         self.resultTable.setItem(row, 1, QTableWidgetItem(regex))
         
         if offset != -1:
             self.lastMatchEnd = offset + re.matchedLength()
             self.nextButton.setEnabled(True)
             row += 1
             self.resultTable.setItem(
                 row, 0, QTableWidgetItem(self.tr("Offset")))
             self.resultTable.setItem(
                 row, 1, QTableWidgetItem("{0:d}".format(offset)))
             
             if not wildcard:
                 row += 1
                 self.resultTable.setItem(
                     row, 0, QTableWidgetItem(self.tr("Captures")))
                 self.resultTable.setItem(
                     row, 1, QTableWidgetItem("{0:d}".format(captures)))
                 row += 1
                 self.resultTable.setItem(
                     row, 1, QTableWidgetItem(self.tr("Text")))
                 self.resultTable.setItem(
                     row, 2, QTableWidgetItem(self.tr("Characters")))
                 
             row += 1
             self.resultTable.setItem(
                 row, 0, QTableWidgetItem(self.tr("Match")))
             self.resultTable.setItem(
                 row, 1, QTableWidgetItem(re.cap(0)))
             self.resultTable.setItem(
                 row, 2,
                 QTableWidgetItem("{0:d}".format(re.matchedLength())))
             
             if not wildcard:
                 for i in range(1, captures + 1):
                     if len(re.cap(i)) > 0:
                         row += 1
                         self.resultTable.insertRow(row)
                         self.resultTable.setItem(
                             row, 0,
                             QTableWidgetItem(
                                 self.tr("Capture #{0}").format(i)))
                         self.resultTable.setItem(
                             row, 1,
                             QTableWidgetItem(re.cap(i)))
                         self.resultTable.setItem(
                             row, 2,
                             QTableWidgetItem(
                                 "{0:d}".format(len(re.cap(i)))))
             else:
                 self.resultTable.setRowCount(3)
             
             # highlight the matched text
             tc = self.textTextEdit.textCursor()
             tc.setPosition(offset)
             tc.setPosition(self.lastMatchEnd, QTextCursor.KeepAnchor)
             self.textTextEdit.setTextCursor(tc)
         else:
             self.nextButton.setEnabled(False)
             self.resultTable.setRowCount(2)
             row += 1
             if startpos > 0:
#.........这里部分代码省略.........
开发者ID:pycom,项目名称:EricShort,代码行数:103,代码来源:QRegExpWizardDialog.py


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