Python PyQt5.QtGui.QValidator() Examples

The following are 5 code examples for showing how to use PyQt5.QtGui.QValidator(). 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.QtGui , or try the search function .

Example 1
Project: Mastering-GUI-Programming-with-Python   Author: PacktPublishing   File: inventory_validator.py    License: MIT License 6 votes vote down vote up
def validate(self, string, index):
        # one approach is to break the string into segments
        # and test each segment for proper content
        state = qtg.QValidator.Acceptable
        seg1 = string[0:2]
        dash1 = string[2:3]
        seg2 = string[3:6]
        dash2 = string[6:7]
        seg3 = string[7:11]
        seg4 = string[11:12]

        if not all([char in self.valid_letters for char in seg1 + seg4]):
            state = qtg.QValidator.Invalid
        elif not all([char.isdigit() for char in seg2 + seg3]):
            state = qtg.QValidator.Invalid
        elif not all([char == '-' for char in dash1 + dash2]):
            state = qtg.QValidator.Invalid
        elif len(string) > 12:
            state = qtg.QValidator.Invalid
        elif not all([seg1, dash1, seg2, dash2, seg3, seg4]):
            state = qtg.QValidator.Intermediate

        return (state, string, index) 
Example 2
Project: awesometts-anki-addon   Author: AwesomeTTS   File: configurator.py    License: GNU General Public License v3.0 5 votes vote down vote up
def validate(self, original, offset):  # pylint:disable=W0613
            """Fixes original text and resets cursor to end of line."""

            filtered = self.fixup(original)
            return QtGui.QValidator.Acceptable, filtered, len(filtered) 
Example 3
Project: Mastering-GUI-Programming-with-Python   Author: PacktPublishing   File: widget_demo.py    License: MIT License 5 votes vote down vote up
def validate(self, string, index):
        if string in self.choices:
            state = qtg.QValidator.Acceptable
        elif any([v.startswith(string) for v in self.choices]):
            state = qtg.QValidator.Intermediate
        else:
            state = qtg.QValidator.Invalid
        return (state, string, index) 
Example 4
Project: Mastering-GUI-Programming-with-Python   Author: PacktPublishing   File: widget_demo.py    License: MIT License 5 votes vote down vote up
def validate(self, string, index):
        octets = string.split('.')
        if len(octets) > 4:
            state = qtg.QValidator.Invalid
        elif not all([x.isdigit() for x in octets if x != '']):
            state = qtg.QValidator.Invalid
        elif not all([0 <= int(x) <= 255 for x in octets if x != '']):
            state = qtg.QValidator.Invalid
        elif len(octets) < 4:
            state = qtg.QValidator.Intermediate
        elif any([x == '' for x in octets]):
            state = qtg.QValidator.Intermediate
        else:
            state = qtg.QValidator.Acceptable
        return (state, string, index) 
Example 5
Project: quick   Author: szsdk   File: quick.py    License: GNU General Public License v3.0 5 votes vote down vote up
def select_type_validator(tp: click.types.ParamType)-> QtGui.QValidator:
    """ select the right validator for `tp`"""
    if isinstance(tp, click.types.IntParamType):
        return QtGui.QIntValidator()
    elif isinstance(tp, click.types.FloatParamType):
        return QtGui.QDoubleValidator()
    return None