Ejemplo n.º 1
0
    def __init__(self):
        """
        Initializes variables and registers the 'attribute_changed' signal.

        It is neccessary for each subclass to call CONObject's __init__, failing to do so
        will prevent the subclass to use signals and attributes.
        """
        # register our class, if not registered before
        if self.__class__ not in CONObject._class_registry:
            CONObject._register_class(self.__class__)

        # init signal callback lists
        if "_callbacks" not in self.__class__.__dict__:
            self.__class__._callbacks = {}
            for signal in CONObject._class_registry[self.__class__]["callbacks"]:
                self.__class__._callbacks[signal] = []

        # init attribute list
        if "_attributes" not in self.__class__.__dict__:
            self.__class__._attributes = CONObject._class_registry[self.__class__]["attributes"].copy()
Ejemplo n.º 2
0
            # try calling any _on_..._changed method
            mname = "_on_" + name + "_changed"
            if hasattr(self, mname):
                method = getattr(self, mname)
                method(oldvalue, value)

            self.raise_signal("attribute_changed", name, oldvalue, value)

    def __getattr__(self, name):
        """
        Return the value of the attribute.

        When the object's uuid is requested but the object has no uuid yet, the uuid is created.
        """
        if name[0:1] == "_":
            return self.__class__.__dict__[name]
        else:
            if (name == "uuid") and (self.__class__.__dict__["_attributes"]["uuid"] == None):
                self.__class__.__dict__["_attributes"]["uuid"] = uuid.uuid4()
            return self.__class__.__dict__["_attributes"][name]

    def get_attribute_list(self):
        """
        Returns the list of attributes that are managed by CONObject.
        """
        return self.__class__._attributes.keys()


CONObject.register_attribute_type("CONBorg", CONBorg.object_serializer, CONBorg.object_deserializer)