add property api
authorgwen <gremond@cadoles.com>
Fri, 7 Sep 2012 14:10:52 +0000 (16:10 +0200)
committergwen <gremond@cadoles.com>
Fri, 7 Sep 2012 14:10:52 +0000 (16:10 +0200)
tiramisu/basetype.py

index 6c3eb51..22639d9 100644 (file)
 class BaseType(object):
     def has_properties(self):
         return bool(len(self.properties))
+    def has_property(self, propname):\r
+        return propname in self.properties\r
+    def get_properties(self):\r
+        return self.properties\r
+    def add_property(self, propname):\r
+        if not propname in self.properties:\r
+            self.properties.append(propname)\r
+    def del_property(self, propname):\r
+        if not self.has_property(propname):\r
+            raise TypeError("option has no property " + propname)\r
+        self.properties.remove(propname)\r
 
 class HiddenBaseType(BaseType):
     def hide(self):
-        if not 'hidden' in self.properties:
-            self.properties.append('hidden')
+        self.add_property('hidden')\r
     def show(self):
-        if 'hidden' in self.properties:
-            self.properties.remove('hidden')
+        self.del_property('hidden')\r
     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')\r
 
 class DisabledBaseType(BaseType):
     def disable(self):
-        if not 'disabled' in self.properties:
-            self.properties.append('disabled')
+        self.add_property('disabled')\r
     def enable(self):
-        if 'disabled' in self.properties:
-            self.properties.remove('disabled')
+        self.del_property('disabled')\r
     def _is_disabled(self):
-        return 'disabled' in self.properties
+        return self.has_property('disabled')\r