Python PyQt4.QtGui.QRegExpValidator() Examples

The following are 9 code examples of PyQt4.QtGui.QRegExpValidator(). 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.QtGui , or try the search function .
Example #1
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 #2
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 #3
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 #4
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 #5
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 #6
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 #7
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 #8
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) 
Example #9
Source File: create_lookup.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
        locale = QSettings().value("locale/userLocale")[0:2]
        last_character = text[-1:]
        if locale == 'en':
            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()

            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, underscores, 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)