Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--addons/bubblemessage.py4
-rw-r--r--tutorius/constraints.py35
-rw-r--r--tutorius/properties.py42
3 files changed, 41 insertions, 40 deletions
diff --git a/addons/bubblemessage.py b/addons/bubblemessage.py
index 0ed5f7e..39bd94d 100644
--- a/addons/bubblemessage.py
+++ b/addons/bubblemessage.py
@@ -21,7 +21,7 @@ class BubbleMessage(Action):
position = TArrayProperty([0,0], 2, 2)
#position = TPositionProperty((0,0))
#Create a list of tail positions as an array of N element : N to be defined...
- tail_pos = TArrayOneTypeProperty([position, position, position],type(position))
+ tail_pos = TArrayOneTypeProperty([[0,0], [0,0], [0,0]],position)
#Bug quand je declare un TIntProperty. creator.py, index out of range
def __init__(self, message=None, pos=None, speaker=None, tailpos=None):
@@ -96,7 +96,7 @@ class BubbleMessage(Action):
def exit_editmode(self, *args):
x,y = self._drag.position
- self.position = [int(x), int(y)]#on perd la validation non ?
+ self.position = [int(x), int(y)]
if self._drag:
self._drag.draggable = False
self._drag = None
diff --git a/tutorius/constraints.py b/tutorius/constraints.py
index e6c942f..cfe7b5f 100644
--- a/tutorius/constraints.py
+++ b/tutorius/constraints.py
@@ -247,31 +247,32 @@ class ListIntCheckConstraint(Constraint):#######################################
for i in range(len(value)):
int(value[i])#la fonction int() ne peut convertir que des nombres ou des string sinon error (ex pas de int([0,0]))
except:
- raise IntCheckConstraintError("The value can't be converted into an int")
+ raise IntCheckConstraintError("The value: '" + str(value) + "' can't be converted into an int")
return
-class TypeConstraint(Constraint):################################################################
- """
- A Type constraint contains a OneType member that can be used in a children
- class as a basic string. ex : SameTypeConstraint
- """
- def __init__(self, one_type):
- self.one_type = one_type
-
class SameTypeConstraintError(Exception):########################################################
pass
-class SameTypeConstraint(TypeConstraint):########################################################
+class SameTypeConstraint(Constraint):########################################################
"""
Ensures that the list is not empty and that properties of the list have the same type.
"""
+ def __init__(self, tutoProp):
+ if tutoProp is not None:
+ self.tutoProp = tutoProp
+ else:
+ raise Exception("Property must exist")#ToDo
+
def validate(self, value):
- if self.one_type is not None:
- if len(value)==0:
- raise SameTypeConstraintError("The list is empty")
- for i in value:
- if type(i) != self.one_type:
- raise SameTypeConstraintError("Properties have diffferent type")
- return
+ if len(value)==0:
+ raise SameTypeConstraintError("The list is empty")
+
+ for i in value:
+ self.tutoProp.validate(i)
+ #raise SameTypeConstraintError("Properties have diffferent type")
+ return value
+ #faire pour une collection qui fait appel a une contrainte type sur une valeur
+
+
diff --git a/tutorius/properties.py b/tutorius/properties.py
index 28f0ed4..137e756 100644
--- a/tutorius/properties.py
+++ b/tutorius/properties.py
@@ -20,7 +20,8 @@ also use the TPropContainer), with the added benefit of having builtin dialog
prompts and constraint validation.
"""
-from sugar.tutorius.constraints import *
+#from sugar.tutorius.constraints import *
+from constraints import *
from copy import copy
class TPropContainer(object):
@@ -136,9 +137,10 @@ class TutoriusProperty(object):
def type(self,value):################################################
"""
- Allow to use type() in the same way for TutoriusProperty or Python elements
+ Allow to use type() for TutoriusProperty like for Python elements
"""
- if value != None :
+ if value != None :
+ print "salut"
return self.type
class TAddonListProperty(TutoriusProperty):
@@ -214,11 +216,11 @@ class TArrayProperty(TutoriusProperty):#########################################
self.min_size_limit = MinSizeConstraint(min_size_limit)
self.default = self.validate(value)
- def __getitem__(self, key): # obligation de redéfinir l'indexation pour le dessin dans overlayer
- return self.indexeur[key] #
+ def __getitem__(self, key): # TArrayProperty object now supports indexing
+ return self.indexeur[key] # used in overlayer.py
#def append(self, value) ?: #invalide
- #et enlever un élément ?
+ #et enlever un element ?
class TColorProperty(TutoriusProperty):
"""
@@ -228,7 +230,7 @@ class TColorProperty(TutoriusProperty):
"""
def __init__(self, red=None, green=None, blue=None):
TutoriusProperty.__init__(self)
- self.type = "color"
+ self.type = "color"#Forcer
self.color_constraint = ColorConstraint()
@@ -335,29 +337,27 @@ class TPositionProperty(TutoriusProperty):######################################
self.indexeur = [self._x, self._y]
self.default = self.validate((self._x,self._y))
- def __getitem__(self, key): # obligation de redéfinir l'indexation pour le dessin dans overlayer
- return self.indexeur[key]
+ #def __getitem__(self, key): # TPositionProperty object now supports indexing
+ #return self.indexeur[key] #use in overlayer.py
+
#fonctionnement obscur pour la modification des valeur a l'interieur du tuple position (par le clavier)
class TArrayOneTypeProperty(TutoriusProperty):######################################################
"""
Represents an array list of Tutorius_properties. All the elements in the list must have the same type. The list must not be empty
"""
- def __init__(self, value, OneType):
+ def __init__(self, value, tutoProp):
TutoriusProperty.__init__(self)
- self.type = OneType
- self.indexeur = value #stock la value, pour l'indexation
- self.required_type = SameTypeConstraint(self.type)
+ self.type = tutoProp.type
+ #self.indexeur = value #stock la value, pour l'indexation
+ self.required_type = SameTypeConstraint(tutoProp) #tutoProp doit etre instancie avant celle de TArrayOneType
self.default = self.validate(value)
# Tester
-
- #Ne comprends pas bien les traitements a faire et comment ils sont fait actuellement dans le creator
- #append
- #et enlever un élément
-
- #def __getitem__(self, key): # obligation de redéfinir l'indexation pour le dessin dans overlayer ou pas
- # return self.indexeur[key]
-
+ #une fonction pour ajouter de la forme t=t.default + value
+ #zqrning sur le append
+
+ #ToDo : Forcer l'utilisateur a utiliser des tuples (immuable). Bug : ((0,0)) = (0,0)
+ #ToDo : Forcer l'initialisation de la propriete a sa valeur par defaut (pour int fonctionnement ok pour TArray non)