本文整理汇总了Python中PyQt5.QtCore.QRegExp.setPatternSyntax方法的典型用法代码示例。如果您正苦于以下问题:Python QRegExp.setPatternSyntax方法的具体用法?Python QRegExp.setPatternSyntax怎么用?Python QRegExp.setPatternSyntax使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtCore.QRegExp
的用法示例。
在下文中一共展示了QRegExp.setPatternSyntax方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: refresh
# 需要导入模块: from PyQt5.QtCore import QRegExp [as 别名]
# 或者: from PyQt5.QtCore.QRegExp import setPatternSyntax [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 setPatternSyntax [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: TaskFilter
# 需要导入模块: from PyQt5.QtCore import QRegExp [as 别名]
# 或者: from PyQt5.QtCore.QRegExp import setPatternSyntax [as 别名]
class TaskFilter(object):
"""
Class implementing a filter for tasks.
"""
def __init__(self):
"""
Constructor
"""
self.active = False
self.summaryFilter = None
self.filenameFilter = None
self.typeFilter = Task.TypeNone
# task type
self.scopeFilter = None
# global (False) or project (True)
self.statusFilter = None
# uncompleted (False) or completed (True)
self.prioritiesFilter = None
# list of priorities [0 (high), 1 (normal), 2 (low)]
def setActive(self, enabled):
"""
Public method to activate the filter.
@param enabled flag indicating the activation state (boolean)
"""
self.active = enabled
def setSummaryFilter(self, filter):
"""
Public method to set the description filter.
@param filter a regular expression for the description filter
to set (string) or None
"""
if not filter:
self.summaryFilter = None
else:
self.summaryFilter = QRegExp(filter)
def setFileNameFilter(self, filter):
"""
Public method to set the filename filter.
@param filter a wildcard expression for the filename filter
to set (string) or None
"""
if not filter:
self.filenameFilter = None
else:
self.filenameFilter = QRegExp(filter)
self.filenameFilter.setPatternSyntax(QRegExp.Wildcard)
def setTypeFilter(self, taskType):
"""
Public method to set the type filter.
@param taskType type of the task (one of Task.TypeNone, Task.TypeFixme,
Task.TypeTodo, Task.TypeWarning, Task.TypeNote)
"""
self.typeFilter = taskType
def setScopeFilter(self, scope):
"""
Public method to set the scope filter.
@param scope flag indicating a project task (boolean) or None
"""
self.scopeFilter = scope
def setStatusFilter(self, status):
"""
Public method to set the status filter.
@param status flag indicating a completed task (boolean) or None
"""
self.statusFilter = status
def setPrioritiesFilter(self, priorities):
"""
Public method to set the priorities filter.
@param priorities list of task priorities (list of integer) or None
"""
self.prioritiesFilter = priorities
def hasActiveFilter(self):
"""
Public method to check for active filters.
@return flag indicating an active filter was found (boolean)
"""
return self.summaryFilter is not None or \
self.filenameFilter is not None or \
self.typeFilter != Task.TypeNone or \
self.scopeFilter is not None or \
#.........这里部分代码省略.........
示例4: regexp
# 需要导入模块: from PyQt5.QtCore import QRegExp [as 别名]
# 或者: from PyQt5.QtCore.QRegExp import setPatternSyntax [as 别名]
def regexp(self):
re = QRegExp(self.exprEdit.text())
re.setCaseSensitivity(csToQtEnum(self.optionsButton.caseSensitive()))
re.setPatternSyntax(self.optionsButton.reFormat())
return re
示例5: on_executeButton_clicked
# 需要导入模块: from PyQt5.QtCore import QRegExp [as 别名]
# 或者: from PyQt5.QtCore.QRegExp import setPatternSyntax [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:
#.........这里部分代码省略.........