import warnings from functools import partial from pycs.frontend.notifications.NotificationManager import NotificationManager class NotificationList: """ stores notifications to fire them later in the correct thread """ def __init__(self): self.__list = [] def add(self, name: str, suffix: str, *args, **kwargs): """ add a function and parameters to be executed later :param fun: function :param params: parameters """ func = NotificationManager()._new_signal(name, suffix, *args, **kwargs) self.__list.append(func) def fire(self, *args, **kwargs): """ fire all stored events and reset the list """ for func in self.__list: try: func(*args, **kwargs) except Exception as e: warnings.warn(f"{func} failed with arguments {args} and {kwargs}: {e}!") self.__list.clear()