add property api
This commit is contained in:
parent
7c19ec7689
commit
3e8d16ece6
1 changed files with 17 additions and 10 deletions
|
@ -24,25 +24,32 @@
|
||||||
class BaseType(object):
|
class BaseType(object):
|
||||||
def has_properties(self):
|
def has_properties(self):
|
||||||
return bool(len(self.properties))
|
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):
|
class HiddenBaseType(BaseType):
|
||||||
def hide(self):
|
def hide(self):
|
||||||
if not 'hidden' in self.properties:
|
self.add_property('hidden')
|
||||||
self.properties.append('hidden')
|
|
||||||
def show(self):
|
def show(self):
|
||||||
if 'hidden' in self.properties:
|
self.del_property('hidden')
|
||||||
self.properties.remove('hidden')
|
|
||||||
def _is_hidden(self):
|
def _is_hidden(self):
|
||||||
# dangerous method: how an Option() can determine its status by itself ?
|
# dangerous method: how an Option() can determine its status by itself ?
|
||||||
return 'hidden' in self.properties
|
return self.has_property('hidden')
|
||||||
|
|
||||||
class DisabledBaseType(BaseType):
|
class DisabledBaseType(BaseType):
|
||||||
def disable(self):
|
def disable(self):
|
||||||
if not 'disabled' in self.properties:
|
self.add_property('disabled')
|
||||||
self.properties.append('disabled')
|
|
||||||
def enable(self):
|
def enable(self):
|
||||||
if 'disabled' in self.properties:
|
self.del_property('disabled')
|
||||||
self.properties.remove('disabled')
|
|
||||||
def _is_disabled(self):
|
def _is_disabled(self):
|
||||||
return 'disabled' in self.properties
|
return self.has_property('disabled')
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue