Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
clive
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hive
clive
Commits
a75c1416
Commit
a75c1416
authored
1 year ago
by
Jakub Ziebinski
Browse files
Options
Downloads
Patches
Plain Diff
Implementation of the PercentInput
parent
6c463a09
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
clive/__private/ui/widgets/inputs/percent_input.py
+45
-0
45 additions, 0 deletions
clive/__private/ui/widgets/inputs/percent_input.py
clive/__private/validators/percent_validator.py
+21
-0
21 additions, 0 deletions
clive/__private/validators/percent_validator.py
with
66 additions
and
0 deletions
clive/__private/ui/widgets/inputs/percent_input.py
0 → 100644
+
45
−
0
View file @
a75c1416
from
__future__
import
annotations
from
typing
import
TYPE_CHECKING
from
clive.__private.ui.widgets.inputs.integer_input
import
IntegerInput
from
clive.__private.validators.percent_validator
import
PercentValidator
if
TYPE_CHECKING
:
from
collections.abc
import
Iterable
from
textual.widgets._input
import
InputValidationOn
class
PercentInput
(
IntegerInput
):
"""
An input for a values between 1 and 100.
"""
def
__init__
(
self
,
title
:
str
,
value
:
str
|
int
|
None
=
None
,
*
,
always_show_title
:
bool
=
False
,
include_title_in_placeholder_when_blurred
:
bool
=
True
,
show_invalid_reasons
:
bool
=
True
,
required
:
bool
=
True
,
validate_on
:
Iterable
[
InputValidationOn
]
|
None
=
None
,
valid_empty
:
bool
=
False
,
id
:
str
|
None
=
None
,
# noqa: A002
classes
:
str
|
None
=
None
,
disabled
:
bool
=
False
,
)
->
None
:
super
().
__init__
(
title
=
title
,
value
=
str
(
value
)
if
value
is
not
None
else
None
,
always_show_title
=
always_show_title
,
include_title_in_placeholder_when_blurred
=
include_title_in_placeholder_when_blurred
,
show_invalid_reasons
=
show_invalid_reasons
,
required
=
required
,
validators
=
PercentValidator
(),
validate_on
=
validate_on
,
valid_empty
=
valid_empty
,
id
=
id
,
classes
=
classes
,
disabled
=
disabled
,
)
This diff is collapsed.
Click to expand it.
clive/__private/validators/percent_validator.py
0 → 100644
+
21
−
0
View file @
a75c1416
from
__future__
import
annotations
from
typing
import
Final
from
textual.validation
import
ValidationResult
,
Validator
class
PercentValidator
(
Validator
):
INVALID_PERCENT_FAILURE_DESCRIPTION
:
str
=
"
Invalid percent value.
"
MIN_PERCENT_VALUE
:
Final
[
int
]
=
1
MAX_PERCENT_VALUE
:
Final
[
int
]
=
100
def
validate
(
self
,
value
:
str
)
->
ValidationResult
:
if
not
value
:
return
self
.
failure
(
self
.
INVALID_PERCENT_FAILURE_DESCRIPTION
,
value
)
if
self
.
MIN_PERCENT_VALUE
<=
int
(
value
)
<=
self
.
MAX_PERCENT_VALUE
:
return
self
.
success
()
return
self
.
failure
(
self
.
INVALID_PERCENT_FAILURE_DESCRIPTION
,
value
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment