-
-
Notifications
You must be signed in to change notification settings - Fork 131
ComplexField #181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
ComplexField #181
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -151,6 +151,57 @@ def validate(self, text): | |
| return True | ||
|
|
||
|
|
||
| class ComplexValidator(Validator): | ||
| """ A concrete Validator which handles complex floating point input. | ||
|
|
||
| This validator ensures that the text represents a complex floating point | ||
| number within a specified range. | ||
|
|
||
| """ | ||
| #: The minimum value allowed for the float, inclusive, or None if | ||
| #: there is no lower bound. | ||
| minimum = Typed(float) | ||
|
|
||
| #: The maximum value allowed for the float, inclusive, or None if | ||
| #: there is no upper bound. | ||
| maximum = Typed(float) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be |
||
|
|
||
| #: Whether or not to allow exponents like '1e6' in the input. | ||
| allow_exponent = Bool(True) | ||
|
|
||
| def validate(self, text): | ||
| """ Validates the given text matches the complex float range. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| text : unicode | ||
| The unicode text edited by the client widget. | ||
|
|
||
| Returns | ||
| ------- | ||
| result : bool | ||
| True if the text is valid, False otherwise. | ||
|
|
||
| """ | ||
| try: | ||
| value = complex(text) | ||
| except ValueError: | ||
| return False | ||
| minimum = self.minimum | ||
| if minimum is not None and (value.real < minimum or value.imag < minimum): | ||
| return False | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks like tabs for indentation on this line - should be 4 spaces |
||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no blank line |
||
| maximum = self.maximum | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no blank line |
||
| if maximum is not None and (value.real > maximum or value.imag > maximum): | ||
| return False | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no blank line |
||
| if not self.allow_exponent and 'e' in text.lower(): | ||
| return False | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no blank line |
||
| return True | ||
|
|
||
|
|
||
| class RegexValidator(Validator): | ||
| """ A concrete Validator which handles text input. | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be
Typed(complex)?