Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/tutorius/properties.py
diff options
context:
space:
mode:
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 4a80e9c..bfdb32c 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, \
@@ -424,6 +424,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.)
@@ -438,13 +442,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.
@@ -456,6 +456,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.
@@ -464,13 +478,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")
-