def addon_property(name, desc, default=None, fire_event=True): """ Use this function to declare class variables, that will be exposed as :class:`AddonInfo`. It works similar to the @property function. You declare the variable like `state = addon_property(...)` and use it as any other variable. :param name: display name :param desc: verbose description :param default: the default value :param fire_event: Fire `addon:property:change` event, when modified """ # generated name for the attribute h = "__Property{0}".format(hash(name) ^ hash(desc)) ADDONMANAGER.add_info_property(h, name, desc) def _get(self): if not hasattr(self, h): return default return getattr(self, h) def _set(self, value): if fire_event: self.manager.fire("addon:property:change", value) return setattr(self, h, value) def _del(self): return delattr(self, h) return property(_get, _set, _del)
def __new__(cls, func, *args, **kwargs): ADDONMANAGER.add_addon_handler(class_name(func.__module__), func.__name__, label, desc, func.__code__.co_varnames[1:], package, media) return func
def __new__(cls, func, *args, **kwargs): for ev in to_list(event, []): ADDONMANAGER.add_event_listener(class_name(func.__module__), func.__name__, ev) return func
def run(*args, **kwargs): ADDONMANAGER.start_thread(f, *args, **kwargs)
def __new__(cls, f, *args, **kwargs): ADDONMANAGER.add_addon_handler(class_name(f.__module__), f.__name__, label, desc, f.__code__.co_varnames[1:], package, media) return f
def __new__(cls, f, *args, **kwargs): for ev in to_list(event, []): ADDONMANAGER.add_event_listener( class_name(f.__module__), f.__name__, ev) return f