Python PyQt5.QtCore.QRegExp() Examples

The following are 30 code examples for showing how to use PyQt5.QtCore.QRegExp(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module PyQt5.QtCore , or try the search function .

Example 1
Project: Hydra   Author: CountryTk   File: Content.py    License: GNU General Public License v3.0 6 votes vote down vote up
def searchFor(self, searchCommand: str):

        regex = QRegExp(searchCommand)

        index = find_all(self.editor.toPlainText(), searchCommand)
        a = list(index)

        textCursor = self.editor.textCursor()
        try:
            textCursor.setPosition(a[0])
            textCursor.movePosition(
                textCursor.Right, textCursor.KeepAnchor, regex.matchedLength()
            )
            self.editor.setTextCursor(textCursor)

        except Exception as E:
            pass 
Example 2
Project: face_recognition_py   Author: winterssy   File: dataRecord.py    License: GNU General Public License v3.0 6 votes vote down vote up
def __init__(self):
        super(UserInfoDialog, self).__init__()
        loadUi('./ui/UserInfoDialog.ui', self)
        self.setWindowIcon(QIcon('./icons/icon.png'))
        self.setFixedSize(425, 300)

        # 使用正则表达式限制用户输入
        stu_id_regx = QRegExp('^[0-9]{12}$')
        stu_id_validator = QRegExpValidator(stu_id_regx, self.stuIDLineEdit)
        self.stuIDLineEdit.setValidator(stu_id_validator)

        cn_name_regx = QRegExp('^[\u4e00-\u9fa5]{1,10}$')
        cn_name_validator = QRegExpValidator(cn_name_regx, self.cnNameLineEdit)
        self.cnNameLineEdit.setValidator(cn_name_validator)

        en_name_regx = QRegExp('^[ A-Za-z]{1,16}$')
        en_name_validator = QRegExpValidator(en_name_regx, self.enNameLineEdit)
        self.enNameLineEdit.setValidator(en_name_validator) 
Example 3
Project: pbtk   Author: marin-m   File: fuzzer.py    License: GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, min_, max_, float_=False):
        super(QwordSpinBox, self).__init__()

        self._minimum = min_
        self._maximum = max_
        self.int_ = float if float_ else int

        rx = QRegExp('-?\d{0,20}(?:\.\d{0,20})?' if float_ else '-?\d{0,20}')
        validator = QRegExpValidator(rx, self)

        self._lineEdit = QLineEdit(self)
        self._lineEdit.setText(str(self.int_(0)))
        self._lineEdit.setValidator(validator)
        self._lineEdit.textEdited.connect(partial(self.setValue, change=False))
        self.editingFinished.connect(lambda: self.setValue(self.value(), update=False) or True)
        self.setLineEdit(self._lineEdit) 
Example 4
Project: Pythonic   Author: hANSIc99   File: basic_sched.py    License: GNU General Public License v3.0 6 votes vote down vote up
def at_time(self):

        logging.debug('at_time() called')

        self.at_time_input = QWidget()
        self.at_time_layout = QVBoxLayout(self.at_time_input)

        self.time_text = QLabel()
        self.time_text.setText(QC.translate('', 'At:'))

        self.time_input = QLineEdit()
        regexp_validator = QRegExp('^([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$')
        self.time_validator = QRegExpValidator(regexp_validator)
        self.time_input.setValidator(self.time_validator)
        self.time_input.setPlaceholderText(QC.translate('', 'hh:mm'))

        self.at_time_layout.addWidget(self.time_text)
        self.at_time_layout.addWidget(self.time_input)

        self.at_time_input.hide()
        self.options_box_layout.addWidget(self.at_time_input) 
Example 5
Project: urh   Author: jopohl   File: ChecksumWidget.py    License: GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, checksum_label: ChecksumLabel, message: Message, proto_view: int, parent=None):
        super().__init__(parent)
        self.ui = Ui_ChecksumOptions()
        self.ui.setupUi(self)
        self.checksum_label = checksum_label
        self.data_range_table_model = self.RangeTableModel(checksum_label, message, proto_view, parent=self)
        self.ui.tableViewDataRanges.setItemDelegateForColumn(0, SpinBoxDelegate(1, 999999, self))
        self.ui.tableViewDataRanges.setItemDelegateForColumn(1, SpinBoxDelegate(1, 999999, self))
        self.ui.tableViewDataRanges.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
        self.ui.tableViewDataRanges.setModel(self.data_range_table_model)
        self.ui.tableViewDataRanges.setEditTriggers(QAbstractItemView.AllEditTriggers)
        self.display_crc_data_ranges_in_table()
        self.ui.comboBoxCRCFunction.addItems([crc_name for crc_name in GenericCRC.DEFAULT_POLYNOMIALS])
        self.ui.comboBoxCRCFunction.addItems([special_crc_name for special_crc_name in self.SPECIAL_CRCS])
        self.ui.lineEditCRCPolynomial.setValidator(QRegExpValidator(QRegExp("[0-9,a-f]*")))
        self.ui.comboBoxCategory.clear()
        for _, member in self.checksum_label.Category.__members__.items():
            self.ui.comboBoxCategory.addItem(member.value)
        self.set_ui_for_category()
        self.setFocus()
        self.create_connects() 
Example 6
Project: tdm   Author: jziolkowski   File: Console.py    License: GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, document):
        QSyntaxHighlighter.__init__(self, document)

        rules = []

        rules += [
            (r'\[.*\] ', 0, self.STYLES['tstamp']),
            (r'\s.*(stat|tele).*\s', 0, self.STYLES['brace']),
            (r'\s.*cmnd.*\s', 0, self.STYLES['command']),
            (r'\"\w*\"(?=:)', 0, self.STYLES['keyword']),
            (r':\"\w*\"', 0, self.STYLES['error']),

            (r'\{\"Command\":\"Unknown\"\}', 0, self.STYLES['error']),
        ]

        rules += [(r'%s' % b, 0, self.STYLES['brace']) for b in self.braces]

        self.rules = [(QRegExp(pat), index, fmt) for (pat, index, fmt) in rules] 
Example 7
Project: dcc   Author: amimo   File: xrefwindow.py    License: Apache License 2.0 5 votes vote down vote up
def filterRegExpChanged(self, value):
        regExp = QtCore.QRegExp(value)
        self.xrefwindow.proxyModel.setFilterRegExp(regExp) 
Example 8
Project: dcc   Author: amimo   File: stringswindow.py    License: Apache License 2.0 5 votes vote down vote up
def filterRegExpChanged(self, value):
        regExp = QtCore.QRegExp(value)
        self.stringswindow.proxyModel.setFilterRegExp(regExp) 
Example 9
Project: dcc   Author: amimo   File: resourceswindow.py    License: Apache License 2.0 5 votes vote down vote up
def filterRegExpChanged(self, value):
        regExp = QtCore.QRegExp(value)
        self.resourceswindow.proxyModel.setFilterRegExp(regExp) 
Example 10
Project: dcc   Author: amimo   File: methodswindow.py    License: Apache License 2.0 5 votes vote down vote up
def filterRegExpChanged(self, value):
        regExp = QtCore.QRegExp(value)
        self.methodswindow.proxyModel.setFilterRegExp(regExp) 
Example 11
Project: dcc   Author: amimo   File: apiwindow.py    License: Apache License 2.0 5 votes vote down vote up
def filterRegExpChanged(self, value):
        regExp = QtCore.QRegExp(value)
        self.methodswindow.proxyModel.setFilterRegExp(regExp) 
Example 12
Project: easygui_qt   Author: aroberge   File: show_text_window.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def __init__(self, parent=None):
        super(Highlighter, self).__init__(parent)

        keywordFormat = QtGui.QTextCharFormat()
        keywordFormat.setForeground(QtCore.Qt.blue)
        keywordFormat.setFontWeight(QtGui.QFont.Bold)

        keywordPatterns = ["\\b{}\\b".format(k) for k in keyword.kwlist]

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

        classFormat = QtGui.QTextCharFormat()
        classFormat.setFontWeight(QtGui.QFont.Bold)
        self.highlightingRules.append((QtCore.QRegExp("\\bQ[A-Za-z]+\\b"),
                classFormat))

        singleLineCommentFormat = QtGui.QTextCharFormat()
        singleLineCommentFormat.setForeground(QtCore.Qt.gray)
        self.highlightingRules.append((QtCore.QRegExp("#[^\n]*"),
                singleLineCommentFormat))

        quotationFormat = QtGui.QTextCharFormat()
        quotationFormat.setForeground(QtCore.Qt.darkGreen)
        self.highlightingRules.append((QtCore.QRegExp("\".*\""),
                quotationFormat))
        self.highlightingRules.append((QtCore.QRegExp("'.*'"),
                quotationFormat)) 
Example 13
Project: easygui_qt   Author: aroberge   File: show_text_window.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def highlightBlock(self, text):
        for pattern, format in self.highlightingRules:
            expression = QtCore.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) 
Example 14
Project: qutebrowser   Author: qutebrowser   File: listcategory.py    License: GNU General Public License v3.0 5 votes vote down vote up
def set_pattern(self, val):
        """Setter for pattern.

        Args:
            val: The value to set.
        """
        self._pattern = val
        val = re.sub(r' +', r' ', val)  # See #1919
        val = re.escape(val)
        val = val.replace(r'\ ', '.*')
        rx = QRegExp(val, Qt.CaseInsensitive)
        self.setFilterRegExp(rx)
        self.invalidate()
        sortcol = 0
        self.sort(sortcol) 
Example 15
Project: dunya-desktop   Author: MTG   File: proxymodel.py    License: GNU General Public License v3.0 5 votes vote down vote up
def filter_table(self, text):
        reg_exp = QRegExp(text, Qt.CaseInsensitive)
        self.setFilterRegExp(reg_exp) 
Example 16
Project: biometric-attendance-sync-tool   Author: frappe   File: gui.py    License: GNU General Public License v3.0 5 votes vote down vote up
def validate_data(self, reg_exp, field_name):
        field = getattr(self, field_name)
        reg_ex = QRegExp(reg_exp)
        input_validator = QRegExpValidator(reg_ex, field)
        field.setValidator(input_validator) 
Example 17
Project: IDAngr   Author: andreafioraldi   File: syntax.py    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
def match_multiline(self, text, delimiter, in_state, style):
        """Do highlighting of multi-line strings. ``delimiter`` should be a
        ``QRegExp`` for triple-single-quotes or triple-double-quotes, and
        ``in_state`` should be a unique integer to represent the corresponding
        state changes when inside those strings. Returns True if we're still
        inside a multi-line string when this function is finished.
        """
        # If inside triple-single quotes, start at 0
        if self.previousBlockState() == in_state:
            start = 0
            add = 0
        # Otherwise, look for the delimiter on this line
        else:
            start = delimiter.indexIn(text)
            # Move past this match
            add = delimiter.matchedLength()

        # As long as there's a delimiter match on this line...
        while start >= 0:
            # Look for the ending delimiter
            end = delimiter.indexIn(text, start + add)
            # Ending delimiter on this line?
            if end >= add:
                length = end - start + add + delimiter.matchedLength()
                self.setCurrentBlockState(0)
            # No; multi-line string
            else:
                self.setCurrentBlockState(in_state)
                length = text.length() - start + add
            # Apply formatting
            self.setFormat(start, length, style)
            # Look for the next match
            start = delimiter.indexIn(text, start + length)

        # Return True if still inside a multi-line string, False otherwise
        if self.currentBlockState() == in_state:
            return True
        else:
            return False 
Example 18
Project: Cura   Author: Ultimaker   File: MachineNameValidator.py    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
def machineNameRegex(self):
        return QRegExp(self.machine_name_regex) 
Example 19
Project: pychemqt   Author: jjgomera   File: UI_spreadsheet.py    License: GNU General Public License v3.0 5 votes vote down vote up
def createEditor(self, parent, option, index):
        if index.column() < 4:
            self.editor = QtWidgets.QComboBox(parent)
            self.editor.addItems(self.items[index.column()])
        else:
            self.editor = QtWidgets.QLineEdit(parent)
            regExp = QtCore.QRegExp("[A-Z]{1,3}\\d{1,5}")
            validator = QtGui.QRegExpValidator(regExp)
            self.editor.setValidator(validator)
        return self.editor 
Example 20
Project: eddy   Author: danielepantaleone   File: log.py    License: GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, document):
        """
        Initialize the syntax highlighter.
        :type document: QTextDocument
        """
        super().__init__(document)
        self.rules = [
            (QtCore.QRegExp(r'^(.{10})\s(.{8})\s+CRITICAL\s+(.*)$'), 0, self.fmt('#8000FF')),
            (QtCore.QRegExp(r'^(.{10})\s(.{8})\s+ERROR\s+(.*)$'), 0, self.fmt('#FF0000')),
            (QtCore.QRegExp(r'^(.{10})\s(.{8})\s+WARNING\s+(.*)$'), 0, self.fmt('#FFAE00')),
        ] 
Example 21
Project: MARA_Framework   Author: xtiankisutsa   File: xrefwindow.py    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
def filterRegExpChanged(self, value):
        regExp = QtCore.QRegExp(value)
        self.xrefwindow.proxyModel.setFilterRegExp(regExp) 
Example 22
Project: MARA_Framework   Author: xtiankisutsa   File: stringswindow.py    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
def filterRegExpChanged(self, value):
        regExp = QtCore.QRegExp(value)
        self.stringswindow.proxyModel.setFilterRegExp(regExp) 
Example 23
Project: MARA_Framework   Author: xtiankisutsa   File: resourceswindow.py    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
def filterRegExpChanged(self, value):
        regExp = QtCore.QRegExp(value)
        self.resourceswindow.proxyModel.setFilterRegExp(regExp) 
Example 24
Project: MARA_Framework   Author: xtiankisutsa   File: methodswindow.py    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
def filterRegExpChanged(self, value):
        regExp = QtCore.QRegExp(value)
        self.methodswindow.proxyModel.setFilterRegExp(regExp) 
Example 25
Project: MARA_Framework   Author: xtiankisutsa   File: apiwindow.py    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
def filterRegExpChanged(self, value):
        regExp = QtCore.QRegExp(value)
        self.methodswindow.proxyModel.setFilterRegExp(regExp) 
Example 26
Project: Hydra   Author: CountryTk   File: Terminal.py    License: GNU General Public License v3.0 5 votes vote down vote up
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) 
Example 27
Project: Hydra   Author: CountryTk   File: Pythonhighlighter.py    License: GNU General Public License v3.0 5 votes vote down vote up
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)

        self.multiLineHighlight(text) 
Example 28
Project: Hydra   Author: CountryTk   File: Pythonhighlighter.py    License: GNU General Public License v3.0 5 votes vote down vote up
def multiLineHighlight(self, text):

        comment = QRegExp('"""')
        if self.previousBlockState() == 1:
            start_index = 0
            index_step = 0
        else:
            start_index = comment.indexIn(text)
            while (
                start_index >= 0
                and self.format(start_index + 2) in self.formats.values()
            ):
                start_index = comment.indexIn(text, start_index + 3)
            index_step = comment.matchedLength()

        while start_index >= 0:
            end = comment.indexIn(text, start_index + index_step)
            if end != -1:
                self.setCurrentBlockState(0)
                length = end - start_index + comment.matchedLength()
            else:
                self.setCurrentBlockState(1)
                length = len(text) - start_index

            self.setFormat(start_index, length, self.formats["multiLineComment"])
            start_index = comment.indexIn(text, start_index + length) 
Example 29
Project: Hydra   Author: CountryTk   File: Pythonhighlighter.py    License: GNU General Public License v3.0 5 votes vote down vote up
def highlightOneBlock(self, block):

        layout = block.layout()
        if not layout:
            return self.editor.blockCount()

        ranges = layout.formats()

        if len(ranges) > 0:
            ranges.clear()

        for pattern, format in self.highlightingRules:
            expression = QRegExp(pattern)
            index = expression.indexIn(block.text())

            while index >= 0:
                length = expression.matchedLength()
                formatrange = QTextLayout.FormatRange()

                formatrange.format = format
                formatrange.length = length
                formatrange.start = index

                ranges.append(formatrange)

                layout.setFormats(ranges)
                self.editor.document().markContentsDirty(
                    block.position(), block.length()
                )
                index = expression.indexIn(block.text(), index + length) 
Example 30
Project: face_recognition_py   Author: winterssy   File: core.py    License: GNU General Public License v3.0 5 votes vote down vote up
def __init__(self):
        super(TelegramBotDialog, self).__init__()
        loadUi('./ui/TelegramBotDialog.ui', self)
        self.setWindowIcon(QIcon('./icons/icon.png'))
        self.setFixedSize(550, 358)

        chat_id_regx = QRegExp('^\d+$')
        chat_id_validator = QRegExpValidator(chat_id_regx, self.telegramIDLineEdit)
        self.telegramIDLineEdit.setValidator(chat_id_validator)

        self.okButton.clicked.connect(self.telegramBotSettings)