Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fslpy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
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
Michiel Cottaar
fslpy
Commits
b132bf57
Commit
b132bf57
authored
11 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
Changed error messages raised when properties set to invalid values
parent
01795b47
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
tkprop/properties.py
+8
-9
8 additions, 9 deletions
tkprop/properties.py
tkprop/properties_types.py
+17
-29
17 additions, 29 deletions
tkprop/properties_types.py
tkprop/widgets_list.py
+2
-2
2 additions, 2 deletions
tkprop/widgets_list.py
with
27 additions
and
40 deletions
tkprop/properties.py
+
8
−
9
View file @
b132bf57
...
...
@@ -462,13 +462,11 @@ class PropertyBase(object):
# required may either be a boolean value
if
isinstance
(
self
.
required
,
bool
)
and
self
.
required
:
raise
ValueError
(
'
A value is required for {}
'
.
format
(
self
.
label
))
raise
ValueError
(
'
A value is required
'
)
# or a function
elif
self
.
required
(
instance
):
raise
ValueError
(
'
A value is required for {}
'
.
format
(
self
.
label
))
raise
ValueError
(
'
A value is required
'
)
if
self
.
validateFunc
is
not
None
:
self
.
validateFunc
(
instance
,
value
)
...
...
@@ -584,10 +582,11 @@ class HasProperties(object):
def
validateAll
(
self
):
"""
Validates all of the properties of this HasProperties object.
A list of strings is returned, with each string containing
an error message about the property which failed validation.
If all property values are valid, the returned list will be
empty.
A list of tuples is returned, with each tuple containing a
property name, and an associated error string. The error
string is a message about the property which failed
validation. If all property values are valid, the returned
list will be empty.
"""
names
,
props
=
self
.
getAllProperties
()
...
...
@@ -601,7 +600,7 @@ class HasProperties(object):
prop
.
validate
(
self
,
val
)
except
ValueError
as
e
:
errors
.
append
(
e
.
message
)
errors
.
append
(
(
name
,
e
.
message
)
)
return
errors
...
...
This diff is collapsed.
Click to expand it.
tkprop/properties_types.py
+
17
−
29
View file @
b132bf57
...
...
@@ -57,12 +57,10 @@ class Number(props.PropertyBase):
props
.
PropertyBase
.
validate
(
self
,
instance
,
value
)
if
self
.
minval
is
not
None
and
value
<
self
.
minval
:
raise
ValueError
(
'
{} must be at least {}
'
.
format
(
self
.
label
,
self
.
minval
))
raise
ValueError
(
'
Must be at least {}
'
.
format
(
self
.
minval
))
if
self
.
maxval
is
not
None
and
value
>
self
.
maxval
:
raise
ValueError
(
'
{} must be at most {}
'
.
format
(
self
.
label
,
self
.
maxval
))
raise
ValueError
(
'
Must be at most {}
'
.
format
(
self
.
maxval
))
class
Int
(
Number
):
...
...
@@ -80,11 +78,9 @@ class Int(Number):
def
validate
(
self
,
instance
,
value
):
try
:
value
=
int
(
value
)
except
:
raise
ValueError
(
'
{} must be an integer ({})
'
.
format
(
self
.
label
,
value
))
try
:
value
=
int
(
value
)
except
:
raise
ValueError
(
'
Must be an integer ({})
'
.
format
(
value
))
Number
.
validate
(
self
,
instance
,
value
)
...
...
@@ -103,11 +99,9 @@ class Double(Number):
def
validate
(
self
,
instance
,
value
):
try
:
value
=
float
(
value
)
except
:
raise
ValueError
(
'
{} must be a floating point number ({})
'
.
format
(
self
.
label
,
value
))
try
:
value
=
float
(
value
)
except
:
raise
ValueError
(
'
Must be a number ({})
'
.
format
(
value
))
Number
.
validate
(
self
,
instance
,
value
)
...
...
@@ -157,12 +151,10 @@ class String(props.PropertyBase):
value
=
str
(
value
)
if
self
.
minlen
is
not
None
and
len
(
value
)
<
self
.
minlen
:
raise
ValueError
(
'
{} must have length at least {}
'
.
format
(
self
.
label
,
self
.
minlen
))
raise
ValueError
(
'
Must have length at least {}
'
.
format
(
self
.
minlen
))
if
self
.
maxlen
is
not
None
and
len
(
value
)
>
self
.
maxlen
:
raise
ValueError
(
'
{} must have length at most {}
'
.
format
(
self
.
label
,
self
.
maxlen
))
raise
ValueError
(
'
Must have length at most {}
'
.
format
(
self
.
maxlen
))
class
Choice
(
String
):
...
...
@@ -228,8 +220,7 @@ class Choice(String):
value
=
str
(
value
)
if
value
not
in
self
.
choices
:
raise
ValueError
(
'
Invalid choice for {}: {}
'
.
format
(
self
.
label
,
value
))
raise
ValueError
(
'
Invalid choice ({})
'
.
format
(
value
))
def
getLabelVar
(
self
,
instance
):
...
...
@@ -310,12 +301,10 @@ class FilePath(String):
if
self
.
exists
:
if
self
.
isFile
and
(
not
op
.
isfile
(
value
)):
raise
ValueError
(
'
{} must be a file ({})
'
.
format
(
self
.
label
,
value
))
raise
ValueError
(
'
Must be a file ({})
'
.
format
(
value
))
if
(
not
self
.
isFile
)
and
(
not
op
.
isdir
(
value
)):
raise
ValueError
(
'
{} must be a directory ({})
'
.
format
(
self
.
label
,
value
))
raise
ValueError
(
'
Must be a directory ({})
'
.
format
(
value
))
class
ListWrapper
(
object
):
...
...
@@ -666,6 +655,7 @@ class List(props.PropertyBase):
return
instval
def
validate
(
self
,
instance
,
values
):
props
.
PropertyBase
.
validate
(
self
,
instance
,
values
)
...
...
@@ -673,16 +663,14 @@ class List(props.PropertyBase):
return
if
(
self
.
minlen
is
not
None
)
and
(
len
(
values
)
<
self
.
minlen
):
raise
ValueError
(
'
{} m
ust have length at least {}
'
.
format
(
self
.
label
,
self
.
minlen
))
raise
ValueError
(
'
M
ust have length at least {}
'
.
format
(
self
.
minlen
))
if
(
self
.
maxlen
is
not
None
)
and
(
len
(
values
)
>
self
.
maxlen
):
raise
ValueError
(
'
{} must have length at most {}
'
.
format
(
self
.
label
,
self
.
maxlen
))
raise
ValueError
(
'
Must have length at most {}
'
.
format
(
self
.
maxlen
))
for
v
in
values
:
self
.
listType
.
validate
(
instance
,
v
)
def
__get__
(
self
,
instance
,
owner
):
"""
...
...
This diff is collapsed.
Click to expand it.
tkprop/widgets_list.py
+
2
−
2
View file @
b132bf57
...
...
@@ -2,8 +2,8 @@
#
# widgets_list.py - A widget for editing a tkprop.List property.
#
# This file really belongs in widgets.py, but it is
large and
# complex enough to warrent its own module.
# Th
e code in th
is file really belongs in widgets.py, but it is
#
large and
complex enough to warrent its own module.
#
# Author: Paul McCarthy <pauldmccarthy@gmail.com>
#
...
...
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