Module QFlow.injectors
Functions
def config(config: object)-
Expand source code
def config(config: object): """ A decorator that injects a configuration object into a class. This decorator adds a `Config` attribute to the class, providing access to the given configuration object. Args: config (object): The configuration object to be added to the class. Returns: decorator: A class decorator that adds the `Config` attribute. """ def decorator(cls): """ Decorates the class to add the configuration object as the `Config` attribute. Args: cls: The class to decorate. Returns: cls: The decorated class with the `Config` attribute. """ originalInit = cls.__init__ def newInit(self, *args, **kwargs): """ Initializes the decorated class and adds the configuration. Args: *args: Positional arguments passed to the original class initializer. **kwargs: Keyword arguments passed to the original class initializer. """ originalInit(self, *args, **kwargs) self.Config = config cls.__init__ = newInit cls.Config = config return cls return decoratorA decorator that injects a configuration object into a class.
This decorator adds a
Configattribute to the class, providing access to the given configuration object.- Args
- -----=
config:object- The configuration object to be added to the class.
- Returns
- -----=
decorator- A class decorator that adds the
Configattribute.
def session()-
Expand source code
def session(): """ A decorator that injects session storage into a class. This decorator adds a `Session` attribute to the class, making it accessible from instances of the class. Returns: decorator: A class decorator that adds the `Session` attribute. """ def decorator(cls): """ Decorates a class to inject session storage. Args: cls: The class to decorate. Returns: cls: The decorated class with the `Session` attribute. """ originalInit = cls.__init__ def newInit(self, *args, **kwargs): """ Initializes the decorated class and adds session storage. Args: *args: Positional arguments passed to the original class initializer. **kwargs: Keyword arguments passed to the original class initializer. """ originalInit(self, *args, **kwargs) self.Session = SESSIONSTORAGE cls.__init__ = newInit cls.Session = SESSIONSTORAGE return cls return decoratorA decorator that injects session storage into a class.
This decorator adds a
Sessionattribute to the class, making it accessible from instances of the class.- Returns
- -----=
decorator- A class decorator that adds the
Sessionattribute.
def style(style: str, path: bool = False)-
Expand source code
def style(style: str, path: bool = False): """ A decorator that applies a stylesheet to a widget or window. This decorator either applies a style from a file path or directly as a string to the widget or window that the decorator is applied to. If `path` is set to `True`, the `style` is treated as a file path, and the stylesheet is read from the file. Otherwise, the `style` is applied directly as a string. Args: style (str): The stylesheet or the path to the stylesheet file. path (bool): Whether the `style` argument is a file path. Defaults to `False`. Returns: decorator: A class decorator that applies the given style to the widget/window. """ def decorator(cls): """ Decorates the class to apply the given stylesheet. Args: cls: The class to decorate. Returns: cls: The decorated class with the stylesheet applied. """ originalInit = cls.__init__ def newInit(self, *args, **kwargs): """ Initializes the decorated class and applies the stylesheet. Args: *args: Positional arguments passed to the original class initializer. **kwargs: Keyword arguments passed to the original class initializer. """ originalInit(self, *args, **kwargs) if path: styleSheet = File(style).readFile() try: self.setStyleSheet(styleSheet if path else style) except: raise TypeError(f"'{self}' is not a stylizable object") cls.__init__ = newInit return cls return decoratorA decorator that applies a stylesheet to a widget or window.
This decorator either applies a style from a file path or directly as a string to the widget or window that the decorator is applied to. If
pathis set toTrue, thestyle()is treated as a file path, and the stylesheet is read from the file. Otherwise, thestyle()is applied directly as a string.- Args
- -----=
style:str- The stylesheet or the path to the stylesheet file.
path:bool- Whether the
style()argument is a file path. Defaults toFalse. - Returns
- -----=
decorator- A class decorator that applies the given style to the widget/window.