From f00c6abdf5804a82eb6d94f427de5d2609a2314c Mon Sep 17 00:00:00 2001 From: mike Date: Sat, 05 Dec 2009 19:22:28 +0000 Subject: BoyScout2.0 : Adding type objects support inside the TypeConstraint --- (limited to 'tutorius/properties.py') 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") - -- cgit v0.9.1