Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/tutorius/properties.py
diff options
context:
space:
mode:
authormike <michael.jmontcalm@gmail.com>2009-12-05 19:22:28 (GMT)
committer mike <michael.jmontcalm@gmail.com>2009-12-05 19:22:28 (GMT)
commitf00c6abdf5804a82eb6d94f427de5d2609a2314c (patch)
tree8ec6697c413fd5af59665bdeabefc1f561609525 /tutorius/properties.py
parent9500e288397de5710151f32ced2e9a2903766a2e (diff)
BoyScout2.0 : Adding type objects support inside the TypeConstraint
Diffstat (limited to 'tutorius/properties.py')
-rw-r--r--tutorius/properties.py35
1 files changed, 21 insertions, 14 deletions
diff --git a/tutorius/properties.py b/tutorius/properties.py
index 2258656..91bda77 100644
--- a/tutorius/properties.py
+++ b/tutorius/properties.py
@@ -28,7 +28,7 @@ from .constraints import Constraint, \
ColorConstraint, FileConstraint, BooleanConstraint, EnumConstraint, \
ResourceConstraint, IntTypeConstraint, FloatTypeConstraint, \
StringTypeConstraint, ArrayTypeConstraint, BoolTypeConstraint, \
- SequenceTypeConstraint
+ SequenceTypeConstraint, TypeConstraint, TypeConstraintError
from .propwidgets import PropWidget, \
StringPropWidget, \
@@ -402,6 +402,10 @@ class TUAMProperty(TutoriusProperty):
self.default = self.validate(value)
+class AddonTypeConstraint(TypeConstraint):
+ def __init__(self):
+ TypeConstraint.__init__(self, TPropContainer)
+
class TAddonProperty(TutoriusProperty):
"""
Reprensents an embedded tutorius Addon Component (action, trigger, etc.)
@@ -416,13 +420,9 @@ class TAddonProperty(TutoriusProperty):
def __init__(self):
super(TAddonProperty, self).__init__()
self.type = "addon"
+ self.addon_type = AddonTypeConstraint()
self.default = self.NullAction()
- def validate(self, value):
- if isinstance(value, TPropContainer):
- return super(TAddonProperty, self).validate(value)
- raise ValueError("Expected TPropContainer instance as TaddonProperty value")
-
class TEventType(TutoriusProperty):
"""
Represents an GUI signal for a widget.
@@ -434,6 +434,20 @@ class TEventType(TutoriusProperty):
self.default = self.validate(value)
+class ListOfAddonTypeConstraint(TypeConstraint):
+ """
+ Ensures that the value is a list of Addons.
+ """
+ def __init__(self):
+ TypeConstraint.__init__(self, 'list')
+
+ def validate(self, value):
+ value = TypeConstraint.validate(self, value)
+ for component in value:
+ if not (isinstance(component, TPropContainer)):
+ raise TypeConstraintError("Expected a list of TPropContainer instances inside ListOfAddonTypeConstraint, got a %s" % (str(type(component))))
+ return value
+
class TAddonListProperty(TutoriusProperty):
"""
Reprensents an embedded tutorius Addon List Component.
@@ -442,13 +456,6 @@ class TAddonListProperty(TutoriusProperty):
def __init__(self):
TutoriusProperty.__init__(self)
self.type = "addonlist"
+ self.list_of_addon_type = ListOfAddonTypeConstraint()
self.default = []
- def validate(self, value):
- if isinstance(value, list):
- for component in value:
- if not (isinstance(component, TPropContainer)):
- raise ValueError("Expected a list of TPropContainer instances inside TAddonListProperty value, got a %s" % (str(type(component))))
- return value
- raise ValueError("Value proposed to TAddonListProperty is not a list")
-