diff options
Diffstat (limited to 'tutorius/properties.py')
-rw-r--r-- | tutorius/properties.py | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/tutorius/properties.py b/tutorius/properties.py index bfdb32c..a0d63bb 100644 --- a/tutorius/properties.py +++ b/tutorius/properties.py @@ -49,12 +49,14 @@ class TPropContainer(object): at the cost of needing a mapping between container instances, and property values. This is what TPropContainer does. """ - def __init__(self): + def __init__(self, **kwargs): """ Prepares the instance for property value storage. This is done at object initialization, thus allowing initial mapping of properties declared on the class. Properties won't work correctly without this call. + + Keyword arguments will be evaluated as properties """ # create property value storage object.__setattr__(self, "_props", {}) @@ -74,6 +76,10 @@ class TPropContainer(object): # to the creator to update its action edition dialog. self._diff_dict = {} + #Set attribute values that were supplied + for key, value in kwargs.items(): + setattr(self, key, value) + def __getattribute__(self, name): """ Process the 'fake' read of properties in the appropriate instance @@ -254,11 +260,15 @@ class TStringProperty(TutoriusProperty): Represents a string. Can have a maximum size limit. """ widget_class = StringPropWidget - def __init__(self, value, size_limit=None): + def __init__(self, value, size_limit=None, null=False): TutoriusProperty.__init__(self) self.type = "string" - self.size_limit = MaxSizeConstraint(size_limit) - self.string_type = StringTypeConstraint() + if size_limit: + self.size_limit = MaxSizeConstraint(size_limit) + if null: + self.string_type = TypeConstraint((str, type(None))) + else: + self.string_type = StringTypeConstraint() self.default = self.validate(value) |