Python PyQt4.QtCore.QRegExp() Examples

The following are 12 code examples of PyQt4.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 PyQt4.QtCore , or try the search function .
Example #1
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 #2
Source File: projectview.py    From rexploit with GNU General Public License v3.0 6 votes vote down vote up
def startUi(self):
        """This function checks if ui file exists and then show the view"""
        try:
            self.load("project")

            self.lineEditLocation.setText(expanduser("~"))
            regex = QRegExp("\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}")
            self.__validator = QRegExpValidator(regex, self.lineEditIP)
            self.lineEditIP.setValidator(self.__validator)

            # Connect things
            self.buttonBox.rejected.connect(self.buttonBoxRejected)
            self.buttonBox.accepted.connect(self.buttonBoxAccepted)
            self.toolButton.clicked.connect(self.toolButtonClicked)
            return True
        except Exception as e:
            MessageBox.critical("Error", str(e))
            return False 
Example #3
Source File: settingsview.py    From rexploit with GNU General Public License v3.0 6 votes vote down vote up
def startUi(self):
        """This function checks if ui file exists and then show the view"""
        try:
            self.load("settings")

            regex = QRegExp("\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}")
            self.__validator = QRegExpValidator(regex, self.lineEditIP)
            self.lineEditIP.setValidator(self.__validator)

            # Connect things
            self.buttonBox.rejected.connect(self.buttonBoxRejected)
            self.buttonBox.accepted.connect(self.buttonBoxAccepted)
            self.toolButton.clicked.connect(self.toolButtonClicked)
            self.pushButtonPing.clicked.connect(self.pushButtonPingClicked)
            return True
        except Exception as e:
            MessageBox.critical("Error", str(e))
            return False 
Example #4
Source File: show_text_window.py    From easygui_qt with 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 #5
Source File: bruteforceview.py    From rexploit with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, parent):
        super(BruteForceView, self).__init__("bruteforce", parent)
        self.category = "bf"

        regex = QRegExp("\d{1,6}")
        self.__validator = QRegExpValidator(regex, self.lineEditPort)
        self.lineEditPort.setValidator(self.__validator)

        regex = QRegExp("\d{1,5}")

        self.__validator = QRegExpValidator(regex, self.lineEditPort)
        self.lineEditMaximum.setValidator(self.__validator)

        # Connect buttons
        self.pushButtonCancel.clicked.connect(self.pushButtonCancelClicked)
        self.pushButtonExploit.clicked.connect(self.pushButtonExploitClicked)
        self.toolButtonUsers.clicked.connect(self.toolButtonUsersClicked)
        self.toolButtonPasswords.clicked.connect(self.toolButtonPasswordsClicked)

        # Connect signal and thread
        self.__communicate = Communicate()
        self.__exploitThread = ExploitThread(self.__communicate)
        self.__communicate.finishExploit.connect(self.setResultExploit)

        # Button and progressbar
        self.setProgressBarState(0)
        self.pushButtonCancel.setEnabled(False)

        # Generator
        self.__generatorUsers = Generator()
        self.__generatorPasswords = Generator() 
Example #6
Source File: dialog_validation.py    From tutorials with MIT License 5 votes vote down vote up
def __init__(self, parent=None):
		super(SmartInfoDialog, self).__init__(parent)

		# Weak email validation regex: http://www.regular-expressions.info/email.html
		self._email_rx = QtCore.QRegExp(
			r'^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$', 
			QtCore.Qt.CaseInsensitive)

		self.email.setValidator(QtGui.QRegExpValidator(self._email_rx )) 
Example #7
Source File: item_formatter.py    From stdm with GNU General Public License v2.0 5 votes vote down vote up
def _configure_table_editor_properties(self, base_table_editor):
        qgis_version = QGis.QGIS_VERSION_INT
        #Get scroll area first
        scroll_area = base_table_editor.findChild(QScrollArea,"scrollArea")

        if not scroll_area is None:

            contents_widget = scroll_area.widget()
            object_names = ['^mRefreshPushButton$'] ##, '^mLayerLabel$', '^mLayerComboBox$', ]

            for object_name in object_names:
                name_regex = QRegExp(object_name)
                for widget in contents_widget.findChildren(QWidget, name_regex):
                    widget.setVisible(False)

                # main_properties_groupbox = contents_widget.findChild(QGroupBox, "groupBox")
                # #Version 2.4
                # if qgis_version >= 20400 and qgis_version <= 20600:
                #     self._hide_filter_controls(main_properties_groupbox)

            # if qgis_version >= 20600:
            #     feature_filter_groupbox = contents_widget.findChild(QGroupBox, "groupBox_5")
                # if not feature_filter_groupbox is None:
                #     self._hide_filter_controls(feature_filter_groupbox)
            appearance_groupbox = contents_widget.findChild(QGroupBox, "groupBox_6")
            appearance_groupbox.setVisible(True) 
Example #8
Source File: item_formatter.py    From stdm with GNU General Public License v2.0 5 votes vote down vote up
def _current_layer_name(self, base_table_editor):
        curr_text = ''
        scroll_area = base_table_editor.findChild(QScrollArea,"scrollArea")
        if not scroll_area is None:
            contents_widget = scroll_area.widget()
            object_names = ['^mLayerComboBox$']
            for object_name in object_names:
                name_regex = QRegExp(object_name)
                for widget in contents_widget.findChildren(QWidget, name_regex):
                    if isinstance(widget, QComboBox):
                        curr_text = widget.currentText()
                        break
        return curr_text 
Example #9
Source File: create_lookup_value.py    From stdm with GNU General Public License v2.0 5 votes vote down vote up
def validate_text(self, text):
        """
        Validates and updates the entered text if necessary.
        :param text: The text entered
        :type text: String
        """
        text_edit = self.sender()

        cursor_position = text_edit.cursorPosition()
        text_edit.setValidator(None)
        if len(text) == 0:
            return
        locale = QSettings().value("locale/userLocale")[0:2]

        if locale == 'en':
            name_regex = QtCore.QRegExp('^[ _0-9a-zA-Z][a-zA-Z0-9_/\\-()|.:,; ]*$')
            name_validator = QtGui.QRegExpValidator(name_regex)
            text_edit.setValidator(name_validator)
            QApplication.processEvents()
            last_character = text[-1:]
            state = name_validator.validate(text, text.index(last_character))[0]
            if state != QValidator.Acceptable:
                self.show_notification(u'"{}" is not allowed at this position.'.
                                       format(last_character)
                                       )
                text = text[:-1]

        if len(text) > 1:
            if text[0] == ' ' or text[0] == '_':
                text = text[1:]

        self.blockSignals(True)
        text_edit.setText(text)
        text_edit.setCursorPosition(cursor_position)
        self.blockSignals(False)
        text_edit.setValidator(None) 
Example #10
Source File: varchar_property.py    From stdm with GNU General Public License v2.0 5 votes vote down vote up
def init_gui(self):
        """
        Initializes form widgets
        """
        charlen_regex = QtCore.QRegExp('^[0-9]{1,3}$')
        charlen_validator = QtGui.QRegExpValidator(charlen_regex)
        self.edtCharLen.setValidator(charlen_validator)

        self.edtCharLen.setText(str(self._max_len))
        self.edtCharLen.setFocus()

        self.edtCharLen.setEnabled(not self.in_db) 
Example #11
Source File: parameters.py    From ddt4all with GNU General Public License v3.0 4 votes vote down vote up
def hexeditor(self):
        self.dialogbox = widgets.QWidget()
        wlayout = widgets.QVBoxLayout()
        diaglabel = widgets.QLabel(_("Diagnostic session"))
        inputlabel = widgets.QLabel(_("Input"))
        outputlabel = widgets.QLabel(_("Output"))

        diaglabel.setAlignment(core.Qt.AlignCenter)
        inputlabel.setAlignment(core.Qt.AlignCenter)
        outputlabel.setAlignment(core.Qt.AlignCenter)

        self.diagsession = widgets.QComboBox()
        rqsts = self.ecurequestsparser.requests.keys()
        self.request_editor_sds = {}

        self.diagsession.addItem(u"None")
        self.request_editor_sds[u'None'] = ""


        for diag in rqsts:
            if "start" in diag.lower() and "session" in diag.lower() and 'diag' in diag.lower():

                sds = self.ecurequestsparser.requests[diag]

                if u'Session Name' in sds.sendbyte_dataitems:
                    session_names = self.ecurequestsparser.data[u'Session Name']
                    for name in session_names.items.keys():
                        sds_stream = " ".join(sds.build_data_stream({u'Session Name': name}))
                        name = name + "[" + sds_stream + "]"
                        self.request_editor_sds[name] = sds_stream
                        self.diagsession.addItem(name)
                    print sds.sendbyte_dataitems[u'Session Name']

        if len(self.request_editor_sds) == 1:
            for k, v in self.sds.iteritems():
                self.diagsession.addItem(k)
                self.request_editor_sds[k] = v

        self.input = widgets.QLineEdit()
        self.input.returnPressed.connect(self.send_manual_cmd)
        self.output = widgets.QLineEdit()
        self.output.setReadOnly(True)
        hexvalidaor = core.QRegExp(("^[\s0-9a-fA-F]+"))
        rev = gui.QRegExpValidator(hexvalidaor, self)
        self.input.setValidator(rev)
        wlayout.addWidget(diaglabel)
        wlayout.addWidget(self.diagsession)
        wlayout.addWidget(inputlabel)
        wlayout.addWidget(self.input)
        wlayout.addWidget(outputlabel)
        wlayout.addWidget(self.output)
        self.dialogbox.setLayout(wlayout)
        self.dialogbox.show() 
Example #12
Source File: column_editor.py    From stdm with GNU General Public License v2.0 4 votes vote down vote up
def validate_text(self, text):
        """
        Validates and updates the entered text if necessary.
        Spaces are replaced by _ and capital letters are replaced by small.
        :param text: The text entered
        :type text: String
        """
        text_edit = self.sender()
        cursor_position = text_edit.cursorPosition()
        text_edit.setValidator(None)
        if len(text) == 0:
            return

        name_regex = QtCore.QRegExp('^(?=.{0,40}$)[ _a-zA-Z][a-zA-Z0-9_ ]*$')
        name_validator = QtGui.QRegExpValidator(name_regex)
        text_edit.setValidator(name_validator)
        QApplication.processEvents()
        last_character = text[-1:]
        locale = QSettings().value("locale/userLocale")[0:2]

        #if locale == 'en':
        state = name_validator.validate(text, text.index(last_character))[0]
        if state != QValidator.Acceptable:
            self.show_notification(u'"{}" is not allowed at this position.'.
                format(last_character)
            )
            text = text[:-1]

        # fix caps, _, and spaces
        if last_character.isupper():
            text = text.lower()
        if last_character == ' ':
            text = text.replace(' ', '_')
        if len(text) > 1:
            if text[0] == ' ' or text[0] == '_':
                text = text[1:]
            text = text.replace(' ', '_').lower()

        self.blockSignals(True)
        text_edit.setText(text)
        text_edit.setCursorPosition(cursor_position)
        self.blockSignals(False)
        text_edit.setValidator(None)