From 3e8d16ece6e8177be60561710ca490e8d8f9b7b9 Mon Sep 17 00:00:00 2001 From: gwen Date: Fri, 7 Sep 2012 16:10:52 +0200 Subject: [PATCH] add property api --- tiramisu/basetype.py | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/tiramisu/basetype.py b/tiramisu/basetype.py index 6c3eb51..22639d9 100644 --- a/tiramisu/basetype.py +++ b/tiramisu/basetype.py @@ -24,25 +24,32 @@ class BaseType(object): def has_properties(self): return bool(len(self.properties)) + def has_property(self, propname): + return propname in self.properties + def get_properties(self): + return self.properties + def add_property(self, propname): + if not propname in self.properties: + self.properties.append(propname) + def del_property(self, propname): + if not self.has_property(propname): + raise TypeError("option has no property " + propname) + self.properties.remove(propname) class HiddenBaseType(BaseType): def hide(self): - if not 'hidden' in self.properties: - self.properties.append('hidden') + self.add_property('hidden') def show(self): - if 'hidden' in self.properties: - self.properties.remove('hidden') + self.del_property('hidden') def _is_hidden(self): # dangerous method: how an Option() can determine its status by itself ? - return 'hidden' in self.properties + return self.has_property('hidden') class DisabledBaseType(BaseType): def disable(self): - if not 'disabled' in self.properties: - self.properties.append('disabled') + self.add_property('disabled') def enable(self): - if 'disabled' in self.properties: - self.properties.remove('disabled') + self.del_property('disabled') def _is_disabled(self): - return 'disabled' in self.properties + return self.has_property('disabled')