Ejemplo n.º 1
0
 def __init__(self):
     SaveableType.__init__(self)
     Observable.__init__(self)
     self.values = []
     self.signal_add = Signal()
     self.signal_remove = Signal()
     self.array_type = array_type
     self.signal_changed = Signal()
Ejemplo n.º 2
0
 def __init__(self):
     """
     Creates an instance attribute for each type in the class attribute '__ordered__'.
     """
     SaveableType.__init__(self)
     self.signal_changed = Signal()
     self.__current__ = self.__typemap__[self.__ordered__[0]]()
     self.__current__.signal_changed.connect(self.signal_changed)
Ejemplo n.º 3
0
 def __setattr__(self, key, value):
     """
     Catches all attribute setting. Only allows the setting if the attribute being set has a 'set' method. If it does
     calls attribute.set(value). Otherwise setting is disallowed
     """
     if key in type(self).__ordered__:
         saveable_type = self.__dict__[key]
         if not callable(getattr(saveable_type, 'set', None)):
             raise ValueError("Cannot assign directly to '{}' ({})".format(
                 key, type(saveable_type)))
         saveable_type.set(value)
     else:
         SaveableType.__setattr__(self, key, value)
Ejemplo n.º 4
0
 def __setattr__(self, key, value):
     """
     Catches all attribute setting. Only allows the setting if the attribute being set has a 'set' method. If it does
     calls attribute.set(value). Otherwise setting is disallowed
     """
     if key in self.__typemap__:
         Type = self.__typemap__[key]
         if not callable(getattr(Type, 'set', None)):
             raise ValueError("Cannot assign directly to '{}' ({})".format(key, type(Type)))
         if key != self.__revtypemap__[type(self.__current__)]:
             self.set(Type)
         self.__current__.set(value)
     else:
         SaveableType.__setattr__(self, key, value)
Ejemplo n.º 5
0
 def __init__(self):
     """
     Creates an instance attribute for each type in the class attribute '__ordered__'.
     """
     SaveableType.__init__(self)
     self.saveables = SaveableViewer(self)
     self.signal_changed = Signal()
     self.__typemap__ = {
         key: type(self).__dict__[key]
         for key in self.__ordered__
     }
     for key, Type in self.__typemap__.items():
         item = Type()
         if callable(getattr(item, 'signal_changed', None)):
             item.signal_changed.connect(self.signal_changed)
         self.__dict__[key] = item
Ejemplo n.º 6
0
 def __getattribute__(self, item):
     """
     Catches all attribute getting. If the attribute defines a 'get' method returns that instead, otherwise just
     returns the attribute
     """
     get_attribute = lambda item: SaveableType.__getattribute__(self, item)
     _dict = get_attribute('__dict__')
     if item not in type(self).__ordered__:
         return get_attribute(item)
     saveable_type = _dict[item]
     return saveable_type
Ejemplo n.º 7
0
 def __getattribute__(self, item):
     """
     Catches all attribute getting. If the attribute defines a 'get' method returns that instead, otherwise just
     returns the attribute
     """
     get_attr_self = lambda item: object.__getattribute__(self, item)
     get_attribute = lambda item: SaveableType.__getattribute__(
         get_attr_self('parent'), item)
     _dict = get_attribute('__dict__')
     if item not in type(get_attr_self('parent')).__ordered__:
         raise ValueError('Saveable ' + item + " does not exist")
     saveable_type = _dict[item]
     return saveable_type
Ejemplo n.º 8
0
 def __getattribute__(self, item):
     """
     Catches all attribute getting. If the attribute defines a 'get' method returns that instead, otherwise just
     returns the attribute
     """
     get_attribute = lambda item: SaveableType.__getattribute__(self, item)
     if item not in get_attribute('__typemap__'):
         return get_attribute(item)
     current = get_attribute('__dict__')['__current__']
     SetType = get_attribute('__typemap__')[item]
     if type(current) != SetType:
         return None
     return current