diff options
-rw-r--r-- | addons/bubblemessage.py | 4 | ||||
-rw-r--r-- | tutorius/constraints.py | 22 | ||||
-rw-r--r-- | tutorius/properties.py | 27 |
3 files changed, 31 insertions, 22 deletions
diff --git a/addons/bubblemessage.py b/addons/bubblemessage.py index b61a356..42a2e7e 100644 --- a/addons/bubblemessage.py +++ b/addons/bubblemessage.py @@ -25,6 +25,10 @@ class BubbleMessage(Action): # ?:;:.? # test = TPositionProperty((0,0)) + test2 = TArrayOneTypeProperty([position,tail_pos], 2, 2) + # + # + def __init__(self, message=None, pos=None, speaker=None, tailpos=None): """ Shows a dialog with a given text, at the given position on the screen. diff --git a/tutorius/constraints.py b/tutorius/constraints.py index f2e324f..455ede3 100644 --- a/tutorius/constraints.py +++ b/tutorius/constraints.py @@ -205,13 +205,21 @@ class FileConstraint(Constraint): raise FileConstraintError("Non-existing file : %s"%value) return -class SameTypeConstraint(Exception): + +class SameTypeConstraintError(Exception): pass -class SameTypeConstraint(ValueConstraint): - pass - #def validate(self, typePropertie): - # if self.limit != typePropertie: - # raise SameTypeConstraint("Value with a diffferent type") - #return +class SameTypeConstraint(Constraint): + """ + Ensures that the list is not empty and that properties of the list have the same type. + """ + + def validate(self, value): + if len(value)==0: + raise SameTypeConstraintError("The list is empty") + for i in value: + if i.type != value[0].type: + raise SameTypeConstraintError("Properties have diffferent type") + return + diff --git a/tutorius/properties.py b/tutorius/properties.py index 9db600e..62a7605 100644 --- a/tutorius/properties.py +++ b/tutorius/properties.py @@ -20,10 +20,7 @@ also use the TPropContainer), with the added benefit of having builtin dialog prompts and constraint validation. """ -from sugar.tutorius.constraints import Constraint, \ - UpperLimitConstraint, LowerLimitConstraint, \ - MaxSizeConstraint, MinSizeConstraint, \ - ColorConstraint, FileConstraint, BooleanConstraint, EnumConstraint +from sugar.tutorius.constraints import * from copy import copy class TPropContainer(object): @@ -326,15 +323,15 @@ class TPositionProperty(TutoriusProperty): #voir les contraintes ou créer x en TintProperty -#class TArrayOneTypeProperty(TutoriusProperty): -# """ -# Represents an array list of properties. Can have a maximum number of element -# limit. All the elements in the list must have the same type. -# """ -# def __init__(self, value, min_size_limit=None, max_size_limit=None): -# TutoriusProperty.__init__(self) -# self.max_size_limit = MaxSizeConstraint(max_size_limit) -# self.min_size_limit = MinSizeConstraint(min_size_limit) -# self.type = SameTypeConstraint(self.type) -# self.default = self.validate(value) +class TArrayOneTypeProperty(TArrayProperty): + """ + Represents an array list of properties. Can have a maximum (and/or minimum) number of element + limit. All the elements in the list must have the same type. The list must not be empty + """ + def __init__(self, value, min_size_limit=None, max_size_limit=None): + TArrayProperty.__init__(self, value, min_size_limit, max_size_limit) + self.type = "typedlist" + self.required_type = SameTypeConstraint() + self.default = self.validate(value) + |