tiramisu/tiramisu/basetype.py
2012-09-11 15:18:38 +02:00

54 lines
2.1 KiB
Python

# -*- coding: utf-8 -*-
"base 'interface' types for option types"
# Copyright (C) 2012 Team tiramisu (see AUTHORS for all contributors)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# The original `Config` design model is unproudly borrowed from
# the rough gus of pypy: pypy: http://codespeak.net/svn/pypy/dist/pypy/config/
# the whole pypy projet is under MIT licence
# ____________________________________________________________
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 self.has_property(propname):
self.properties.remove(propname)
class HiddenBaseType(BaseType):
def hide(self):
self.add_property('hidden')
def show(self):
self.del_property('hidden')
def _is_hidden(self):
# dangerous method: how an Option() can determine its status by itself ?
return self.has_property('hidden')
class DisabledBaseType(BaseType):
def disable(self):
self.add_property('disabled')
def enable(self):
self.del_property('disabled')
def _is_disabled(self):
return self.has_property('disabled')