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


Python QtCore.QRegExp类代码示例

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


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

示例1: validate

 def validate(self, inpt: str, pos: int):
     if self.suffix().upper() in ("", "K", "M", "G"):
         rx = QRegExp("^(-?[0-9]+)[.]?[0-9]*[kKmMgG]?$")
     else:
         rx = QRegExp("^(-?[0-9]+)[.]?[0-9]*[{}]?$".format(self.suffix()))
     result = QValidator.Acceptable if rx.exactMatch(inpt.replace(",", ".")) else QValidator.Invalid
     return result, inpt, pos
开发者ID:jopohl,项目名称:urh,代码行数:7,代码来源:KillerDoubleSpinBox.py

示例2: __init__

    def __init__(self, parent=None):
        super(XmlSyntaxHighlighter, self).__init__(parent)

        self.highlightingRules = []

        # Tag format.
        format = QTextCharFormat()
        format.setForeground(Qt.darkBlue)
        format.setFontWeight(QFont.Bold)
        pattern = QRegExp("(<[a-zA-Z:]+\\b|<\\?[a-zA-Z:]+\\b|\\?>|>|/>|</[a-zA-Z:]+>)")
        self.highlightingRules.append((pattern, format))

        # Attribute format.
        format = QTextCharFormat()
        format.setForeground(Qt.darkGreen)
        pattern = QRegExp("[a-zA-Z:]+=")
        self.highlightingRules.append((pattern, format))

        # Attribute content format.
        format = QTextCharFormat()
        format.setForeground(Qt.red)
        pattern = QRegExp("(\"[^\"]*\"|'[^']*')")
        self.highlightingRules.append((pattern, format))

        # Comment format.
        self.commentFormat = QTextCharFormat()
        self.commentFormat.setForeground(Qt.lightGray)
        self.commentFormat.setFontItalic(True)

        self.commentStartExpression = QRegExp("<!--")
        self.commentEndExpression = QRegExp("-->")
开发者ID:death-finger,项目名称:Scripts,代码行数:31,代码来源:schema.py

示例3: __init__

    def __init__(self, parent=None):
        super(Highlighter, self).__init__(parent)

        keywordFormat = QTextCharFormat()
        keywordFormat.setForeground(Qt.darkBlue)
        keywordFormat.setFontWeight(QFont.Bold)

        keywordPatterns = ["""</?\w+\s+[^>]*>""","<[/]?(html|body|head|title|div|a|br|form|input|b|p|i|center|span|font|table|tr|td|h[1-6])[/]?>"]

        self.highlightingRules = [(QRegExp(pattern), keywordFormat)
                for pattern in keywordPatterns]


        self.multiLineCommentFormat = QTextCharFormat()
        self.multiLineCommentFormat.setForeground(Qt.red)

        quotationFormat = QTextCharFormat()
        quotationFormat.setForeground(Qt.darkGreen)
        self.highlightingRules.append((QRegExp("\".*\""),
                quotationFormat))

        functionFormat = QTextCharFormat()
        functionFormat.setFontItalic(True)
        functionFormat.setForeground(Qt.blue)
        self.highlightingRules.append((QRegExp("\\b[A-Za-z0-9_]+(?=\\()"),
                functionFormat))
        
        moreKeyWords = QTextCharFormat()
        moreKeyWords.setForeground(Qt.darkMagenta)
        moreKeyWords.setFontWeight(QFont.Bold)
        self.highlightingRules.append((QRegExp("(id|class|src|border|width|height|style|name|type|value)="),moreKeyWords))

        self.commentStartExpression = QRegExp("<!--")
        self.commentEndExpression = QRegExp("-->")
开发者ID:lycying,项目名称:seeking,代码行数:34,代码来源:syntax.py

示例4: __filterSignatures

 def __filterSignatures(self):
     """
     Private method to filter the log entries.
     """
     searchRxText = self.rxEdit.text()
     filterTop = self.categoryCombo.currentText() == self.tr("Revision")
     if filterTop and searchRxText.startswith("^"):
         searchRx = QRegExp(
             "^\s*{0}".format(searchRxText[1:]), Qt.CaseInsensitive)
     else:
         searchRx = QRegExp(searchRxText, Qt.CaseInsensitive)
     for topIndex in range(self.signaturesList.topLevelItemCount()):
         topLevelItem = self.signaturesList.topLevelItem(topIndex)
         if filterTop:
             topLevelItem.setHidden(
                 searchRx.indexIn(topLevelItem.text(0)) == -1)
         else:
             visibleChildren = topLevelItem.childCount()
             for childIndex in range(topLevelItem.childCount()):
                 childItem = topLevelItem.child(childIndex)
                 if searchRx.indexIn(childItem.text(0)) == -1:
                     childItem.setHidden(True)
                     visibleChildren -= 1
                 else:
                     childItem.setHidden(False)
             topLevelItem.setHidden(visibleChildren == 0)
开发者ID:Darriall,项目名称:eric,代码行数:26,代码来源:HgGpgSignaturesDialog.py

示例5: XmlSyntaxHighlighter

class XmlSyntaxHighlighter(QSyntaxHighlighter):

    def __init__(self, parent=None):
        super(XmlSyntaxHighlighter, self).__init__(parent)

        self.highlightingRules = []

        # Tag format.
        format = QTextCharFormat()
        format.setForeground(Qt.darkBlue)
        format.setFontWeight(QFont.Bold)
        pattern = QRegExp("(<[a-zA-Z:]+\\b|<\\?[a-zA-Z:]+\\b|\\?>|>|/>|</[a-zA-Z:]+>)")
        self.highlightingRules.append((pattern, format))

        # Attribute format.
        format = QTextCharFormat()
        format.setForeground(Qt.darkGreen)
        pattern = QRegExp("[a-zA-Z:]+=")
        self.highlightingRules.append((pattern, format))

        # Attribute content format.
        format = QTextCharFormat()
        format.setForeground(Qt.red)
        pattern = QRegExp("(\"[^\"]*\"|'[^']*')")
        self.highlightingRules.append((pattern, format))

        # Comment format.
        self.commentFormat = QTextCharFormat()
        self.commentFormat.setForeground(Qt.lightGray)
        self.commentFormat.setFontItalic(True)

        self.commentStartExpression = QRegExp("<!--")
        self.commentEndExpression = QRegExp("-->")

    def highlightBlock(self, text):
        for pattern, format in self.highlightingRules:
            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)

        startIndex = 0
        if self.previousBlockState() != 1:
            startIndex = self.commentStartExpression.indexIn(text)

        while startIndex >= 0:
            endIndex = self.commentEndExpression.indexIn(text, startIndex)
            if endIndex == -1:
                self.setCurrentBlockState(1)
                commentLength = text.length() - startIndex
            else:
                commentLength = endIndex - startIndex + self.commentEndExpression.matchedLength()

            self.setFormat(startIndex, commentLength, self.commentFormat)
            startIndex = self.commentStartExpression.indexIn(text,
                    startIndex + commentLength)
开发者ID:death-finger,项目名称:Scripts,代码行数:60,代码来源:schema.py

示例6: __init__

 def __init__(self):
     """
     Constructor
     """
     super(NsHtmlReader, self).__init__()
     
     self.__folderRx = QRegExp("<DT><H3(.*)>(.*)</H3>", Qt.CaseInsensitive)
     self.__folderRx.setMinimal(True)
     
     self.__endFolderRx = QRegExp("</DL>", Qt.CaseInsensitive)
     
     self.__bookmarkRx = QRegExp("<DT><A(.*)>(.*)</A>", Qt.CaseInsensitive)
     self.__bookmarkRx.setMinimal(True)
     
     self.__descRx = QRegExp("<DD>(.*)", Qt.CaseInsensitive)
     
     self.__separatorRx = QRegExp("<HR>", Qt.CaseInsensitive)
     
     self.__urlRx = QRegExp('HREF="(.*)"', Qt.CaseInsensitive)
     self.__urlRx.setMinimal(True)
     
     self.__addedRx = QRegExp('ADD_DATE="(\d*)"', Qt.CaseInsensitive)
     self.__addedRx.setMinimal(True)
     
     self.__modifiedRx = QRegExp(
         'LAST_MODIFIED="(\d*)"', Qt.CaseInsensitive)
     self.__modifiedRx.setMinimal(True)
     
     self.__visitedRx = QRegExp('LAST_VISIT="(\d*)"', Qt.CaseInsensitive)
     self.__visitedRx.setMinimal(True)
     
     self.__foldedRx = QRegExp("FOLDED", Qt.CaseInsensitive)
开发者ID:Darriall,项目名称:eric,代码行数:32,代码来源:NsHtmlReader.py

示例7: data_changed

 def data_changed(self, index1, index2, roles):
     if index1.column() in (1, 3):
         regexp1 = QRegExp("^-?\d+(\.\d+)?$")
         regexp2 = QRegExp("^\d+$")
         if len(str(index1.data())) == 0:
             QMessageBox.critical(None,
                                  "Invalid data",
                                  "Field cannot be empty.",
                                  QMessageBox.Ok)
             self.model.revertRow(index1.row())
         elif len(str(index1.data())) != len(str(index1.data()).strip()):
             QMessageBox.critical(None,
                                  "Invalid data",
                                  "Unwanted whitespace character.",
                                  QMessageBox.Ok)
             self.model.revertRow(index1.row())
         elif index1.column() == 1 and not regexp1.exactMatch(str(index1.data())):
             QMessageBox.critical(None,
                                  "Invalid data",
                                  "Field must be numeric.",
                                  QMessageBox.Ok)
             self.model.revertRow(index1.row())
         elif index1.column() == 3 and not regexp2.exactMatch(str(index1.data())):
             QMessageBox.critical(None,
                                  "Invalid data",
                                  "Field must be numeric.",
                                  QMessageBox.Ok)
             self.model.revertRow(index1.row())
开发者ID:komarEX,项目名称:Shinji,代码行数:28,代码来源:gametab.py

示例8: valueFromText

    def valueFromText(text):
        regExp = QRegExp("(\\d+)(\\s*[xx]\\s*\\d+)?")

        if regExp.exactMatch(text):
            return int(regExp.cap(1))
        else:
            return 0
开发者ID:Axel-Erfurt,项目名称:pyqt5,代码行数:7,代码来源:icons.py

示例9: setData

    def setData(self, index, value, role):
        """
        This function is called when a content in a row is edited by the user.

        :param index: Current selected index.
        :param value: New value from user
        :param role:
        :return:
        """

        if not index.isValid():
            return None

        row = index.row()
        col = index.column()

        if role == Qt.EditRole:
            if col == 1:
                index_sibling = index.sibling(row, col-1)
                dparameter = super(DParameterTreeModel, self).data(index_sibling, Qt.UserRole)

                if dparameter.regex is not None:
                    rx = QRegExp(dparameter.regex)
                    if rx.exactMatch(value):
                        dparameter.value = value
                        self.dataChanged.emit(index_sibling, index_sibling)
                else:
                    dparameter.value = value
                    self.dataChanged.emit(index_sibling, index_sibling)

                return True

        return False
开发者ID:dani-l,项目名称:PaPI,代码行数:33,代码来源:item.py

示例10: findCodecs

    def findCodecs(self):
        codecMap = []
        iso8859RegExp = QRegExp('ISO[- ]8859-([0-9]+).*')

        for mib in QTextCodec.availableMibs():
            codec = QTextCodec.codecForMib(mib)
            sortKey = codec_name(codec).upper()
            rank = 0

            if sortKey.startswith('UTF-8'):
                rank = 1
            elif sortKey.startswith('UTF-16'):
                rank = 2
            elif iso8859RegExp.exactMatch(sortKey):
                if len(iso8859RegExp.cap(1)) == 1:
                    rank = 3
                else:
                    rank = 4
            else:
                rank = 5

            codecMap.append((str(rank) + sortKey, codec))

        codecMap.sort()
        self.codecs = [item[-1] for item in codecMap]
开发者ID:Axel-Erfurt,项目名称:pyqt5,代码行数:25,代码来源:codecs.py

示例11: highlightBlock

    def highlightBlock(self, text):
        for pattern, format in self.highlightingRules:
            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)

        startIndex = 0
        if self.previousBlockState() != 1:
            startIndex = self.commentStartExpression.indexIn(text)

        while startIndex >= 0:
            endIndex = self.commentEndExpression.indexIn(text, startIndex)

            if endIndex == -1:
                self.setCurrentBlockState(1)
                commentLength = len(text) - startIndex
            else:
                commentLength = endIndex - startIndex + self.commentEndExpression.matchedLength()

            self.setFormat(startIndex, commentLength,
                    self.multiLineCommentFormat)
            startIndex = self.commentStartExpression.indexIn(text,
                    startIndex + commentLength);
开发者ID:Axel-Erfurt,项目名称:pyqt5,代码行数:28,代码来源:syntaxhighlighter.py

示例12: run

    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,代码行数:32,代码来源:highlighter.py

示例13: __init__

 def __init__(self, mergelist1, mergelist2, targetlist, force=False,
              parent=None):
     """
     Constructor
     
     @param mergelist1 list of previously entered URLs/revisions
         (list of strings)
     @param mergelist2 list of previously entered URLs/revisions
         (list of strings)
     @param targetlist list of previously entered targets (list of strings)
     @param force flag indicating a forced merge (boolean)
     @param parent parent widget (QWidget)
     """
     super(SvnMergeDialog, self).__init__(parent)
     self.setupUi(self)
    
     self.forceCheckBox.setChecked(force)
     
     self.rx_url = QRegExp('(?:file:|svn:|svn+ssh:|http:|https:)//.+')
     self.rx_rev = QRegExp('\\d+')
     
     self.tag1Combo.clear()
     self.tag1Combo.addItems(mergelist1)
     self.tag2Combo.clear()
     self.tag2Combo.addItems(mergelist2)
     self.targetCombo.clear()
     self.targetCombo.addItems(targetlist)
     
     self.okButton = self.buttonBox.button(QDialogButtonBox.Ok)
     self.okButton.setEnabled(False)
     
     msh = self.minimumSizeHint()
     self.resize(max(self.width(), msh.width()), msh.height())
开发者ID:pycom,项目名称:EricShort,代码行数:33,代码来源:SvnMergeDialog.py

示例14: __init__

 def __init__(self, vcs, parent=None):
     """
     Constructor
     
     @param vcs reference to the vcs object
     @param parent parent widget (QWidget)
     """
     super(SvnChangeListsDialog, self).__init__(parent)
     self.setupUi(self)
     self.setWindowFlags(Qt.Window)
     
     self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False)
     self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True)
     
     self.process = None
     self.vcs = vcs
     
     self.rx_status = QRegExp(
         '(.{8,9})\\s+([0-9-]+)\\s+([0-9?]+)\\s+(\\S+)\\s+(.+)\\s*')
     # flags (8 or 9 anything), revision, changed rev, author, path
     self.rx_status2 = \
         QRegExp('(.{8,9})\\s+(.+)\\s*')
     # flags (8 or 9 anything), path
     self.rx_changelist = \
         QRegExp('--- \\S+ .([\\w\\s]+).:\\s+')
开发者ID:paulmadore,项目名称:Eric-IDE,代码行数:25,代码来源:SvnChangeListsDialog.py

示例15: __init__

 def __init__(self, vcs, parent=None):
     """
     Constructor
     
     @param vcs reference to the vcs object
     @param parent parent widget (QWidget)
     """
     super(SvnPropListDialog, self).__init__(parent)
     self.setupUi(self)
     
     self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False)
     self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True)
     
     self.process = QProcess()
     env = QProcessEnvironment.systemEnvironment()
     env.insert("LANG", "C")
     self.process.setProcessEnvironment(env)
     self.vcs = vcs
     
     self.propsList.headerItem().setText(self.propsList.columnCount(), "")
     self.propsList.header().setSortIndicator(0, Qt.AscendingOrder)
     
     self.process.finished.connect(self.__procFinished)
     self.process.readyReadStandardOutput.connect(self.__readStdout)
     self.process.readyReadStandardError.connect(self.__readStderr)
     
     self.rx_path = QRegExp(r"Properties on '([^']+)':\s*")
     self.rx_prop = QRegExp(r"  (.*) *: *(.*)[\r\n]")
     self.lastPath = None
     self.lastProp = None
     self.propBuffer = ""
开发者ID:Darriall,项目名称:eric,代码行数:31,代码来源:SvnPropListDialog.py


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