Пример #1
0
    def __create_prop_accessors__(cls, prop_name, default_val):
        """Private method that creates getter and setter, and the
        corresponding property"""
        getter_name = "get_prop_%s" % prop_name
        setter_name = "set_prop_%s" % prop_name

        members_names = cls.__dict__.keys()

        # checks if accessors are already defined:
        if getter_name not in members_names:
            src = type(cls).get_getter_source(cls, getter_name, prop_name)
            func = get_function_from_source(src)
            setattr(cls, getter_name, func)
        else:
            logger.debug("Custom member '%s' overloads generated getter of property '%s'", getter_name, prop_name)
            pass

        if setter_name not in members_names:
            src = type(cls).get_setter_source(cls, setter_name, prop_name)
            func = get_function_from_source(src)
            setattr(cls, setter_name, func)
        else:
            logger.warning("Custom member '%s' overloads generated setter of property '%s'", setter_name, prop_name)
            pass

        prop = property(getattr(cls, getter_name), getattr(cls, setter_name))
        setattr(cls, prop_name, prop)

        has_prop_variable = hasattr(cls, prop_name) or props.has_key(prop_name)
        if has_prop_variable:
            varname = PROP_NAME % {"prop_name": prop_name}
            if not varname in members_names:
                cls.__create_property(varname, default_val)
            else:
                logger.warning(
                    "In class %s.%s automatic property builder found a possible clashing with attribute '%s'",
                    cls.__module__,
                    cls.__name__,
                    varname,
                )
            pass

        return
Пример #2
0
    def _add_method(self, src):
        """Private service to add a new method to the instance,
        given method code"""

        from gtkmvc.support.utils import get_function_from_source
        import new

        func = get_function_from_source(src)
        meth = new.instancemethod(func, self, self.__class__)
        setattr(self, func.__name__, meth)
        return
Пример #3
0
 def _add_method(self, src):
     """Private service to add a new method to the instance,
     given method code"""
     
     from gtkmvc.support.utils import get_function_from_source
     import new
     
     func = get_function_from_source(src)
     meth = new.instancemethod(func, self, self.__class__)
     setattr(self, func.__name__, meth)
     return