本文整理汇总了Python中PyQt5.QtCore.QRegExp.isValid方法的典型用法代码示例。如果您正苦于以下问题:Python QRegExp.isValid方法的具体用法?Python QRegExp.isValid怎么用?Python QRegExp.isValid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtCore.QRegExp
的用法示例。
在下文中一共展示了QRegExp.isValid方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: refresh
# 需要导入模块: from PyQt5.QtCore import QRegExp [as 别名]
# 或者: from PyQt5.QtCore.QRegExp import isValid [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)
示例2: on_validateButton_clicked
# 需要导入模块: from PyQt5.QtCore import QRegExp [as 别名]
# 或者: from PyQt5.QtCore.QRegExp import isValid [as 别名]
def on_validateButton_clicked(self):
"""
Private slot to validate the entered regexp.
"""
regex = self.regexpLineEdit.text()
if regex:
re = QRegExp(regex)
if self.caseSensitiveCheckBox.isChecked():
re.setCaseSensitivity(Qt.CaseSensitive)
else:
re.setCaseSensitivity(Qt.CaseInsensitive)
re.setMinimal(self.minimalCheckBox.isChecked())
re.setPatternSyntax(
self.syntaxCombo.itemData(self.syntaxCombo.currentIndex()))
if re.isValid():
E5MessageBox.information(
self,
self.tr("Validation"),
self.tr("""The regular expression is valid."""))
else:
E5MessageBox.critical(
self,
self.tr("Error"),
self.tr("""Invalid regular expression: {0}""")
.format(re.errorString()))
return
else:
E5MessageBox.critical(
self,
self.tr("Error"),
self.tr("""A regular expression must be given."""))
示例3: on_executeButton_clicked
# 需要导入模块: from PyQt5.QtCore import QRegExp [as 别名]
# 或者: from PyQt5.QtCore.QRegExp import isValid [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:
#.........这里部分代码省略.........