Python PyQt5.QtCore.QRegExp() Examples

The following are 30 code examples of PyQt5.QtCore.QRegExp(). 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 also want to check out all available functions/classes of the module PyQt5.QtCore , or try the search function .
Example #1
Source File: dataRecord.py    From face_recognition_py with GNU General Public License v3.0 7 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 #2
Source File: Content.py    From Hydra with 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 #3
Source File: Console.py    From tdm with 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 #4
Source File: ChecksumWidget.py    From urh with 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 #5
Source File: basic_sched.py    From Pythonic with 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 #6
Source File: fuzzer.py    From pbtk with 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 #7
Source File: show_text_window.py    From easygui_qt with BSD 3-Clause "New" or "Revised" License 6 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 #8
Source File: pid_dialogs.py    From artisan with GNU General Public License v3.0 5 votes vote down vote up
def createsegmenttable(self):
        self.segmenttable.setRowCount(16)
        self.segmenttable.setColumnCount(4)
        self.segmenttable.setHorizontalHeaderLabels([QApplication.translate("StatusBar","SV",None),
                                                     QApplication.translate("StatusBar","Ramp (MM:SS)",None),
                                                     QApplication.translate("StatusBar","Soak (MM:SS)",None),""])
        self.segmenttable.setEditTriggers(QTableWidget.NoEditTriggers)
        self.segmenttable.setSelectionBehavior(QTableWidget.SelectRows)
        self.segmenttable.setSelectionMode(QTableWidget.SingleSelection)
        self.segmenttable.setShowGrid(True)
        self.segmenttable.verticalHeader().setSectionResizeMode(2)
        regextime = QRegExp(r"^-?[0-9]?[0-9]?[0-9]:[0-5][0-9]$")
        #populate table
        for i in range(16):
            #create widgets
            svkey = "segment" + str(i+1) + "sv"
            rampkey = "segment" + str(i+1) + "ramp"
            soakkey = "segment" + str(i+1) + "soak"
            svedit = QLineEdit(str(self.aw.fujipid.PXG4[svkey][0]))
            svedit.setValidator(self.aw.createCLocaleDoubleValidator(0., 999., 1, svedit))
            rampedit = QLineEdit(stringfromseconds(self.aw.fujipid.PXG4[rampkey][0]))
            rampedit.setValidator(QRegExpValidator(regextime,self))
            soakedit  = QLineEdit(stringfromseconds(self.aw.fujipid.PXG4[soakkey][0]))
            soakedit.setValidator(QRegExpValidator(regextime,self))
            setButton = QPushButton(QApplication.translate("Button","Set",None))
            setButton.setFocusPolicy(Qt.NoFocus)
            setButton.clicked.connect(self.setsegment)
            #add widgets to the table
            self.segmenttable.setCellWidget(i,0,svedit)
            self.segmenttable.setCellWidget(i,1,rampedit)
            self.segmenttable.setCellWidget(i,2,soakedit)
            self.segmenttable.setCellWidget(i,3,setButton)

    #idn = id number, sv = float set value, ramp = ramp value, soak = soak value 
Example #9
Source File: core.py    From face_recognition_py with 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) 
Example #10
Source File: apiwindow.py    From dcc with 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
Source File: methodswindow.py    From dcc with 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
Source File: basic_sched.py    From Pythonic with GNU General Public License v3.0 5 votes vote down vote up
def time_between(self):

        logging.debug('time_between() called')
        self.time_between_input = QWidget()
        self.time_between_layout = QVBoxLayout(self.time_between_input)

        self.time_between_txt = QLabel()
        self.time_between_txt.setText(QC.translate('', 'Between'))

        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_row = QWidget()
        self.time_row_layout = QHBoxLayout(self.time_row)

        self.start_time_input = QLineEdit()
        self.start_time_input.setValidator(self.time_validator)
        self.start_time_input.setPlaceholderText(QC.translate('', 'hh:mm (default 00:00)'))

        self.and_text = QLabel()
        self.and_text.setText(QC.translate('', 'and'))

        self.stop_time_input = QLineEdit()
        self.stop_time_input.setValidator(self.time_validator)
        self.stop_time_input.setPlaceholderText(QC.translate('', 'hh:mm (default 00:00)'))

        
        self.time_row_layout.addWidget(self.start_time_input)
        self.time_row_layout.addWidget(self.and_text)
        self.time_row_layout.addWidget(self.stop_time_input)


        self.time_between_layout.addWidget(self.time_between_txt)
        self.time_between_layout.addWidget(self.time_row)

        self.time_between_input.hide()

        self.options_box_layout.addWidget(self.time_between_input) 
Example #13
Source File: HighlightText.py    From PyQt with GNU General Public License v3.0 5 votes vote down vote up
def highlight(self):
        text = self.findText.text()  # 输入框中的文字
        if not text:
            return

        col = QColorDialog.getColor(self.textEdit.textColor(), self)
        if not col.isValid():
            return

        # 恢复默认的颜色
        cursor = self.textEdit.textCursor()
        cursor.select(QTextCursor.Document)
        cursor.setCharFormat(QTextCharFormat())
        cursor.clearSelection()
        self.textEdit.setTextCursor(cursor)

        # 文字颜色
        fmt = QTextCharFormat()
        fmt.setForeground(col)

        # 正则
        expression = QRegExp(text)
        self.textEdit.moveCursor(QTextCursor.Start)
        cursor = self.textEdit.textCursor()

        # 循环查找设置颜色
        pos = 0
        index = expression.indexIn(self.textEdit.toPlainText(), pos)
        while index >= 0:
            cursor.setPosition(index)
            cursor.movePosition(QTextCursor.Right,
                                QTextCursor.KeepAnchor, len(text))
            cursor.mergeCharFormat(fmt)
            pos = index + expression.matchedLength()
            index = expression.indexIn(self.textEdit.toPlainText(), pos) 
Example #14
Source File: CityLinkage.py    From PyQt with GNU General Public License v3.0 5 votes vote down vote up
def setFilter(self, _):
        # 过滤
        # self.sender()#发送者
        # 获取上一个下拉框中的item_code
        item_code = self.sender().currentData(Qt.ToolTipRole)
        if not item_code:
            return
        if item_code.endswith("0000"):  # 过滤市
            self.setFilterRegExp(QRegExp(item_code[:-4] + "\d\d00"))
        elif item_code.endswith("00"):  # 过滤市以下
            self.setFilterRegExp(QRegExp(item_code[:-2] + "\d\d")) 
Example #15
Source File: app.py    From liquid-swap with GNU General Public License v3.0 5 votes vote down vote up
def set_re_float(line_edit):
    line_edit.setValidator(QRegExpValidator(QRegExp('^\d*\.?\d+$'), line_edit))
# TODO: add regex also for asset id 
Example #16
Source File: designer.py    From artisan with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self,parent = None, aw = None, values = [0,0]):
        super(pointDlg,self).__init__(parent, aw)
        self.values = values
        self.setWindowTitle(QApplication.translate("Form Caption","Add Point",None))
        self.tempEdit = QLineEdit(str(int(round(self.values[1]))))
        self.tempEdit.setValidator(QIntValidator(0, 999, self.tempEdit))
        self.tempEdit.setFocus()
        self.tempEdit.setAlignment(Qt.AlignRight)
        templabel = QLabel(QApplication.translate("Label", "temp",None))
        regextime = QRegExp(r"^-?[0-9]?[0-9]?[0-9]:[0-5][0-9]$")
        self.timeEdit = QLineEdit(stringfromseconds(self.values[0],leadingzero=False))
        self.timeEdit.setAlignment(Qt.AlignRight)
        self.timeEdit.setValidator(QRegExpValidator(regextime,self))
        timelabel = QLabel(QApplication.translate("Label", "time",None))

        # connect the ArtisanDialog standard OK/Cancel buttons
        self.dialogbuttons.accepted.connect(self.return_values)
        self.dialogbuttons.rejected.connect(self.reject)
        
        buttonLayout = QHBoxLayout()
        buttonLayout.addStretch()
        buttonLayout.addWidget(self.dialogbuttons)
        grid = QGridLayout()
        grid.addWidget(timelabel,0,0)
        grid.addWidget(self.timeEdit,0,1)
        grid.addWidget(templabel,1,0)
        grid.addWidget(self.tempEdit,1,1)
        mainLayout = QVBoxLayout()
        mainLayout.addLayout(grid)
        mainLayout.addStretch()  
        mainLayout.addLayout(buttonLayout)
        self.setLayout(mainLayout)
        self.dialogbuttons.button(QDialogButtonBox.Ok).setFocus() 
Example #17
Source File: pid_dialogs.py    From artisan with GNU General Public License v3.0 5 votes vote down vote up
def createsegmenttable(self):
        self.segmenttable.setRowCount(8)
        self.segmenttable.setColumnCount(4)
        self.segmenttable.setHorizontalHeaderLabels([QApplication.translate("Table","SV",None),
                                                     QApplication.translate("Table","Ramp HH:MM",None),
                                                     QApplication.translate("Table","Soak HH:MM",None),""])
        self.segmenttable.setEditTriggers(QTableWidget.NoEditTriggers)
        self.segmenttable.setSelectionBehavior(QTableWidget.SelectRows)
        self.segmenttable.setSelectionMode(QTableWidget.SingleSelection)
        self.segmenttable.setShowGrid(True)
        self.segmenttable.verticalHeader().setSectionResizeMode(2)
        regextime = QRegExp(r"^-?[0-9]?[0-9]?[0-9]:[0-5][0-9]$")
        #populate table
        for i in range(8):
            #create widgets
            svkey = "segment" + str(i+1) + "sv"
            rampkey = "segment" + str(i+1) + "ramp"
            soakkey = "segment" + str(i+1) + "soak"
            
            svedit = QLineEdit(str(self.aw.fujipid.PXR[svkey][0]))
            svedit.setValidator(self.aw.createCLocaleDoubleValidator(0., 999., 1, svedit))
            rampedit = QLineEdit(stringfromseconds(self.aw.fujipid.PXR[rampkey][0]))
            rampedit.setValidator(QRegExpValidator(regextime,self))
            soakedit  = QLineEdit(stringfromseconds(self.aw.fujipid.PXR[soakkey][0]))
            soakedit.setValidator(QRegExpValidator(regextime,self))
            setButton = QPushButton(QApplication.translate("Button","Set",None))
            setButton.clicked.connect(self.setsegment)
            setButton.setFocusPolicy(Qt.NoFocus)
            #add widgets to the table
            self.segmenttable.setCellWidget(i,0,svedit)
            self.segmenttable.setCellWidget(i,1,rampedit)
            self.segmenttable.setCellWidget(i,2,soakedit)
            self.segmenttable.setCellWidget(i,3,setButton)

    #idn = id number, sv = float set value, ramp = ramp value, soak = soak value 
Example #18
Source File: Pythonhighlighter.py    From Hydra with 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 #19
Source File: IDAFunctionTagger.py    From IDA-Function-Tagger with GNU General Public License v2.0 5 votes vote down vote up
def _onFilterTextChanged(self, text):
        filter = QtCore.QRegExp(text, QtCore.Qt.CaseInsensitive, QtCore.QRegExp.Wildcard)

        self._function_list_model_filter.setFilterRegExp(filter)

        self._function_list_view.expandAll()
        self._tag_list_view.expandAll() 
Example #20
Source File: ModulatorDialog.py    From urh with GNU General Public License v3.0 5 votes vote down vote up
def update_modulation_parameters(self):
        n = len(self.current_modulator.parameters) - 1
        if self.current_modulator.is_amplitude_based:
            regex = r"(100|[0-9]{1,2})"
        elif self.current_modulator.is_frequency_based:
            regex = r"((-?[0-9]+)[.,]?[0-9]*[kKmMgG]?)"
        elif self.current_modulator.is_phase_based:
            regex = r"(-?(36[0]|3[0-5][0-9]|[12][0-9][0-9]|[1-9]?[0-9]))"
        else:
            raise ValueError("Unknown modulation type")

        full_regex = r"^(" + regex + r"/){" + str(n) + "}" + regex + r"$"
        self.ui.lineEditParameters.setValidator(QRegExpValidator(QRegExp(full_regex)))
        self.ui.lineEditParameters.setText(self.current_modulator.parameters_string) 
Example #21
Source File: DeviceSettingsWidget.py    From urh with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, project_manager: ProjectManager, is_tx: bool, backend_handler: BackendHandler = None,
                 continuous_send_mode=False, parent=None):
        super().__init__(parent)
        self.ui = Ui_FormDeviceSettings()
        self.ui.setupUi(self)

        self.__device = None  # type: VirtualDevice

        self.is_tx = is_tx
        self.is_rx = not is_tx
        if backend_handler is None:
            self.backend_handler = BackendHandler()
        else:
            self.backend_handler = backend_handler

        if self.is_rx:
            self.ui.spinBoxNRepeat.hide()
            self.ui.labelNRepeat.hide()
        else:
            self.ui.labelDCCorrection.hide()
            self.ui.checkBoxDCCorrection.hide()

        self.bw_sr_are_locked = settings.read("lock_bandwidth_sample_rate", True, bool)
        self.ui.cbDevice.clear()
        items = self.get_devices_for_combobox(continuous_send_mode)
        self.ui.cbDevice.addItems(items)
        self.bootstrap(project_manager.device_conf, enforce_default=True)

        self.ui.btnLockBWSR.setChecked(self.bw_sr_are_locked)
        self.on_btn_lock_bw_sr_clicked()

        ip_range = "(?:[0-1]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])"
        ip_regex = QRegExp("^" + ip_range
                           + "\\." + ip_range
                           + "\\." + ip_range
                           + "\\." + ip_range + "$")
        self.ui.lineEditIP.setValidator(QRegExpValidator(ip_regex))

        self.create_connects()
        self.sync_gain_sliders() 
Example #22
Source File: resourceswindow.py    From dcc with Apache License 2.0 5 votes vote down vote up
def filterRegExpChanged(self, value):
        regExp = QtCore.QRegExp(value)
        self.resourceswindow.proxyModel.setFilterRegExp(regExp) 
Example #23
Source File: KillerDoubleSpinBox.py    From urh with GNU General Public License v3.0 5 votes vote down vote up
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 
Example #24
Source File: hexspinbox.py    From crazyflie-clients-python with GNU General Public License v2.0 5 votes vote down vote up
def __init__(self, *args):
        QAbstractSpinBox.__init__(self, *args)
        regexp = QtCore.QRegExp('^0x[0-9A-Fa-f]{1,10}$')
        self.validator = QtGui.QRegExpValidator(regexp)
        self._value = 0 
Example #25
Source File: syntax.py    From hrdev with MIT License 5 votes vote down vote up
def highlightBlock(self, text):
        '''Highlight block.'''

        for pattern, hl_format in self._highlighting_rules:
            expression = QtCore.QRegExp(pattern)
            index = expression.indexIn(text)
            while index >= 0:
                length = expression.matchedLength()
                self.setFormat(index, length, hl_format)
                index = expression.indexIn(text, index + length)

        self.setCurrentBlockState(0)

        start_index = 0
        if self.previousBlockState() != 1:
            start_index = self.comment_start_expression.indexIn(text)

        while start_index >= 0:
            end_index = self.comment_end_expression.indexIn(text, start_index)

            if end_index == -1:
                self.setCurrentBlockState(1)
                comment_length = text.length() - start_index
            else:
                comment_length = end_index - \
                                 start_index + \
                                 self.comment_end_expression.matchedLength()

            multi_line_comment_format = QtGui.QTextCharFormat()
            multiline_color = self.config_theme.get('tokens_highlight',
                                                    'quotation_color')
            multi_line_comment_format.setForeground(QtGui.QColor(multiline_color))
            self.setFormat(start_index, comment_length,
                           multi_line_comment_format)
            start_index = self.comment_start_expression.indexIn(text,
                                                                start_index +
                                                                comment_length)
        return 
Example #26
Source File: gui.py    From hrdev with MIT License 5 votes vote down vote up
def _toggle_casts(self):
            '''TODO: feature to toggle casting.'''

            if self._casts_marked:
                for selection in self._casts_selections:
                    selection.cursor.clearSelection()
                self._casts_marked = False
                self._casts_selections = None
                return
            search_flag = QTextDocument.FindFlags(0)
            search_flag |= QTextDocument.FindWholeWords
            search_flag |= QTextDocument.FindCaseSensitively
            marker_color = self.config_theme.get('editor', 'hidden_color')

            self._casts_selections = []
            selection = QTextEdit.ExtraSelection()

            cursor = self.document().find(QtCore.QRegExp(r'\(\w+\s\*\)'))
            cursor.select(QTextCursor.WordUnderCursor)

            cursor.movePosition(QTextCursor.Start)

            selection.format.setBackground(QColor(marker_color))
            selection.cursor = cursor
            self._casts_selections.append(selection)

            while cursor:
                cursor = self.document().find(QtCore.QRegExp(r'\(\w+\s\*\)'),
                                              cursor, search_flag)
                if not cursor:
                    break
                selection = QTextEdit.ExtraSelection()
                selection.format.setBackground(QColor(marker_color))
                selection.cursor = cursor
                self._casts_selections.append(selection)
            self.setExtraSelections(self._casts_selections)
            self._casts_marked = True
            return 
Example #27
Source File: stringswindow.py    From dcc with Apache License 2.0 5 votes vote down vote up
def filterRegExpChanged(self, value):
        regExp = QtCore.QRegExp(value)
        self.stringswindow.proxyModel.setFilterRegExp(regExp) 
Example #28
Source File: log.py    From eddy with 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 #29
Source File: listcategory.py    From qutebrowser with 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 #30
Source File: proxymodel.py    From dunya-desktop with 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)