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


Python QRegExp.setMinimal方法代码示例

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


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

示例1: refresh

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

# 需要导入模块: from PyQt5.QtCore import QRegExp [as 别名]
# 或者: from PyQt5.QtCore.QRegExp import setMinimal [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."""))
开发者ID:pycom,项目名称:EricShort,代码行数:33,代码来源:QRegExpWizardDialog.py

示例3: __init__

# 需要导入模块: from PyQt5.QtCore import QRegExp [as 别名]
# 或者: from PyQt5.QtCore.QRegExp import setMinimal [as 别名]
    def __init__(self, editor):
        super(Highlighter, self).__init__(editor)
        # Keywords format
        keyword_format = QTextCharFormat()
        keyword_format.setForeground(Qt.darkBlue)
        keyword_format.setFontWeight(QFont.Bold)

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

        # Number format
        number_format = QTextCharFormat()
        number_pattern = QRegExp(r"\b([A-Z0-9]+)(?:[ _-](\d+))?\b")
        number_pattern.setMinimal(True)
        number_format.setForeground(Qt.darkCyan)
        self._rules.append((number_pattern, number_format))

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

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

        # Paren
        self.paren = QRegExp('\(|\)')
开发者ID:centaurialpha,项目名称:pireal,代码行数:35,代码来源:highlighter.py

示例4: __scriptDownloaded

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

示例5: __init__

# 需要导入模块: from PyQt5.QtCore import QRegExp [as 别名]
# 或者: from PyQt5.QtCore.QRegExp import setMinimal [as 别名]
    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('\(|\)')
开发者ID:yoshitomimaehara,项目名称:pireal,代码行数:49,代码来源:highlighter.py

示例6: highlightBlock

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

#.........这里部分代码省略.........

        # Inline formatting
        if state not in [
            # State.COMMENT_AREA,
            # State.COMMENT_LINE,
            State.RAW_AREA,
            State.RAW_LINE,
            State.CODE_AREA,
            State.CODE_LINE,
            State.TAGGED_AREA,
            State.TAGGED_LINE,
            State.SETTINGS_LINE,
            State.HORIZONTAL_LINE,
        ] and state not in State.TITLES:
            formatArray = textToFormatArray(text)

            # InDocRules
            for (r, c) in self.inDocRules:
                i = re.finditer(r.decode('utf8'), text, re.UNICODE)
                for m in i:
                    f = self.format(m.start())
                    l = m.end() - m.start()
                    if "," in c:
                        c1, c2 = c.split(",")
                        self.setFormat(m.start(), l,
                                       self.style.makeFormat(color=c1, bgcolor=c2, base=f))
                    else:
                        self.setFormat(m.start(), l,
                                       self.style.makeFormat(color=c, base=f))

            # Links 
            if state not in [State.COMMENT_LINE, State.COMMENT_AREA]:
                r = QRegExp(r'\[(\[[^\]]*\])?[^\]]*\s*([^\s]+)\]')
                r.setMinimal(False)
                pos = r.indexIn(text)
                links = []
                while pos >= 0:
                    # TODO: The text should not be formatted if [**not bold**]
                    # if max([k[pos] for k in formatArray]) == 0 or 1 == 1:
                    self.setFormat(pos, 1,
                                   self.style.format(State.MARKUP))
                    self.setFormat(pos + 1, len(r.cap(0)) - 1,
                                   self.style.format(State.LINKS))
                    self.setFormat(pos + len(r.cap(0)) - 1, 1,
                                   self.style.format(State.MARKUP))
                    if r.pos(2) > 0:
                        _f = QTextCharFormat(self.style.format(State.LINKS))
                        _f.setForeground(QBrush(_f.foreground()
                                                .color().lighter()))
                        _f.setFontUnderline(True)
                        self.setFormat(r.pos(2), len(r.cap(2)), _f)

                    links.append([pos, len(r.cap(0))])  # To remember for the next highlighter (single links)
                    pos = r.indexIn(text, pos + 1)

                # Links like www.theologeek.ch, http://www.fsf.org, ...
                # FIXME: - "http://adresse et http://adresse" is detected also as italic
                #        - some error, like "http://adress.htm." also color the final "."
                #        - also: [email protected], ftp://, www2, www3, etc.
                #        - But for now, does the job
                r = QRegExp(r'http://[^\s]*|www\.[a-zA-Z0-9-_]+\.[a-zA-Z0-9-_]+[^\s]*')
                # r.setMinimal(True)
                pos = r.indexIn(text)
                while pos >= 0:
                    for k in links:
                        # print pos, k[0], k[1]
开发者ID:georgehank,项目名称:manuskript,代码行数:70,代码来源:t2tHighlighter.py

示例7: on_executeButton_clicked

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

示例8: NsHtmlReader

# 需要导入模块: from PyQt5.QtCore import QRegExp [as 别名]
# 或者: from PyQt5.QtCore.QRegExp import setMinimal [as 别名]
class NsHtmlReader(QObject):
    """
    Class implementing a reader object for Netscape HTML bookmark files.
    """
    indentSize = 4
    
    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)
    
    def read(self, fileNameOrDevice):
        """
        Public method to read a Netscape HTML bookmark file.
        
        @param fileNameOrDevice name of the file to read (string)
            or reference to the device to read (QIODevice)
        @return reference to the root node (BookmarkNode)
        """
        if isinstance(fileNameOrDevice, QIODevice):
            dev = fileNameOrDevice
        else:
            f = QFile(fileNameOrDevice)
            if not f.exists():
                return BookmarkNode(BookmarkNode.Root)
            f.open(QFile.ReadOnly)
            dev = f
        
        folders = []
        lastNode = None
        
        root = BookmarkNode(BookmarkNode.Root)
        folders.append(root)
        
        while not dev.atEnd():
            line = str(dev.readLine(), encoding="utf-8").rstrip()
            if self.__folderRx.indexIn(line) != -1:
                # folder definition
                arguments = self.__folderRx.cap(1)
                name = self.__folderRx.cap(2)
                node = BookmarkNode(BookmarkNode.Folder, folders[-1])
                node.title = Utilities.html_udecode(name)
                node.expanded = self.__foldedRx.indexIn(arguments) == -1
                if self.__addedRx.indexIn(arguments) != -1:
                    node.added = QDateTime.fromTime_t(
                        int(self.__addedRx.cap(1)))
                folders.append(node)
                lastNode = node
            
            elif self.__endFolderRx.indexIn(line) != -1:
                # end of folder definition
                folders.pop()
            
            elif self.__bookmarkRx.indexIn(line) != -1:
                # bookmark definition
                arguments = self.__bookmarkRx.cap(1)
                name = self.__bookmarkRx.cap(2)
                node = BookmarkNode(BookmarkNode.Bookmark, folders[-1])
                node.title = Utilities.html_udecode(name)
                if self.__urlRx.indexIn(arguments) != -1:
                    node.url = self.__urlRx.cap(1)
                if self.__addedRx.indexIn(arguments) != -1:
                    node.added = QDateTime.fromTime_t(
                        int(self.__addedRx.cap(1)))
                if self.__modifiedRx.indexIn(arguments) != -1:
                    node.modified = QDateTime.fromTime_t(
                        int(self.__modifiedRx.cap(1)))
                if self.__visitedRx.indexIn(arguments) != -1:
                    node.visited = QDateTime.fromTime_t(
                        int(self.__visitedRx.cap(1)))
                lastNode = node
            
#.........这里部分代码省略.........
开发者ID:Darriall,项目名称:eric,代码行数:103,代码来源:NsHtmlReader.py


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