Module QFlow.extensions

Classes

class QWebEngineViewBridge
Expand source code
class QWebEngineViewBridge(QObject):
    """
    Planned for package use only.

    A QObject subclass that acts as a bridge between JavaScript and Python.

    This class stores callable Python functions and allows them to be executed
    dynamically by name, typically from JavaScript using QWebChannel.
    """

    def __init__(self):
        """
        Initializes a QWebEngineViewBridge instance.

        Attributes:
            functions (dict): A dictionary mapping function names (str)
                              to callable Python functions.
        """
        super().__init__()

        self.functions = {}

    def add(self, name: str, callable: Callable):
        """
        Registers a function in the QWebEngineViewBridge.

        Args:
            name (str): The name used to identify the function.
            callable (Callable): The function to be executed.
        """
        self.functions[name] = callable
    
    def delete(self, name: str):
        """
        Removes a function from the QWebEngineViewBridge.

        Args:
            name (str): The name of the function to remove.
        """
        del self.functions[name]

    @Slot(str)
    def execute(self, name: str, *args):
        """
        Executes a registered function by name.

        Args:
            name (str): The name of the function to execute.
            *args: Arguments passed to the function.

        Note:
            This method is exposed to JavaScript via QWebChannel.
        """
        if name in self.functions:
            self.functions[name](*args)

Planned for package use only.

A QObject subclass that acts as a bridge between JavaScript and Python.

This class stores callable Python functions and allows them to be executed dynamically by name, typically from JavaScript using QWebChannel.

Initializes a QWebEngineViewBridge instance.

Attributes

functions : dict
A dictionary mapping function names (str) to callable Python functions.

Ancestors

  • PyQt6.QtCore.QObject
  • PyQt6.sip.wrapper
  • PyQt6.sip.simplewrapper

Methods

def add(self, name: str, callable: Callable)
Expand source code
def add(self, name: str, callable: Callable):
    """
    Registers a function in the QWebEngineViewBridge.

    Args:
        name (str): The name used to identify the function.
        callable (Callable): The function to be executed.
    """
    self.functions[name] = callable

Registers a function in the QWebEngineViewBridge.

Args

name : str
The name used to identify the function.
callable : Callable
The function to be executed.
def delete(self, name: str)
Expand source code
def delete(self, name: str):
    """
    Removes a function from the QWebEngineViewBridge.

    Args:
        name (str): The name of the function to remove.
    """
    del self.functions[name]

Removes a function from the QWebEngineViewBridge.

Args

name : str
The name of the function to remove.
def execute(self, name: str, *args)
Expand source code
@Slot(str)
def execute(self, name: str, *args):
    """
    Executes a registered function by name.

    Args:
        name (str): The name of the function to execute.
        *args: Arguments passed to the function.

    Note:
        This method is exposed to JavaScript via QWebChannel.
    """
    if name in self.functions:
        self.functions[name](*args)

Executes a registered function by name.

Args

name : str
The name of the function to execute.
*args
Arguments passed to the function.

Note

This method is exposed to JavaScript via QWebChannel.

class QWidgetEventFilter
Expand source code
class QWidgetEventFilter(QObject):
    """
    Planned for package use only.

    A QObject subclass that provides a simple way to listen for Qt events on widgets.

    This class allows you to register event types and associate them with callback
    functions. When an event occurs, the corresponding function is executed with
    the widget as an argument.
    """

    def __init__(self):
        """
        Initializes a QWidgetEventFilter instance.

        Attributes:
            events (dict): A dictionary mapping event types (QEvent.Type)
                           to their associated callback functions.
        """
        super().__init__()
        self.events = {}

    def addEventToListen(self, event, action):
        """
        Registers an event and its associated callback function.

        Args:
            event (QEvent.Type): The Qt event type to listen for.
            action (callable): The function to execute when the event occurs.
                               The function must accept one argument (the widget).
        """
        self.events[event] = action

    def eventFilter(self, obj, event):
        """
        Intercepts events sent to the filtered object.

        Args:
            obj (QObject): The object receiving the event.
            event (QEvent): The event being processed.

        Returns:
            bool: Returns the base implementation result, allowing the event
                  to continue its normal processing.
        """
        for key, value in self.events.items():
            if event.type() == key:
                value(obj)

        return super().eventFilter(obj, event)

Planned for package use only.

A QObject subclass that provides a simple way to listen for Qt events on widgets.

This class allows you to register event types and associate them with callback functions. When an event occurs, the corresponding function is executed with the widget as an argument.

Initializes a QWidgetEventFilter instance.

Attributes

events : dict
A dictionary mapping event types (QEvent.Type) to their associated callback functions.

Ancestors

  • PyQt6.QtCore.QObject
  • PyQt6.sip.wrapper
  • PyQt6.sip.simplewrapper

Methods

def addEventToListen(self, event, action)
Expand source code
def addEventToListen(self, event, action):
    """
    Registers an event and its associated callback function.

    Args:
        event (QEvent.Type): The Qt event type to listen for.
        action (callable): The function to execute when the event occurs.
                           The function must accept one argument (the widget).
    """
    self.events[event] = action

Registers an event and its associated callback function.

Args

event : QEvent.Type
The Qt event type to listen for.
action : callable
The function to execute when the event occurs. The function must accept one argument (the widget).
def eventFilter(self, obj, event)
Expand source code
def eventFilter(self, obj, event):
    """
    Intercepts events sent to the filtered object.

    Args:
        obj (QObject): The object receiving the event.
        event (QEvent): The event being processed.

    Returns:
        bool: Returns the base implementation result, allowing the event
              to continue its normal processing.
    """
    for key, value in self.events.items():
        if event.type() == key:
            value(obj)

    return super().eventFilter(obj, event)

Intercepts events sent to the filtered object.

Args

obj : QObject
The object receiving the event.
event : QEvent
The event being processed.

Returns

bool
Returns the base implementation result, allowing the event to continue its normal processing.