add property api
This commit is contained in:
parent
7c19ec7689
commit
3e8d16ece6
@ -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')
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user