Module QFlow.hooks.navigate

Classes

class Navigator (instance: QFlow.modules.window.window.Window | QFlow.modules.screen.screen.Screen)
Expand source code
class Navigator:
    def __init__(self, instance: Window | Screen):
        """
        Navigates to a specified screen path, extracting embedded URL query 
        parameters and merging them with additional parameters.
        """
        self.cursor = None

        if isinstance(instance, (App, Window)):
            self.cursor = instance
        else:
            parent: Window = instance.parent()
            self.cursor = parent

        if not self.cursor:
            raise TypeError(f"'{instance}' is not Window or Screen.")

    def navigate(self, screen: str | int, params: dict = {}) -> None:
        """
        This function automatically resolves the correct navigation controller 
        (`setScreen`) depending on whether `self` is a `Window` or a `Screen`. It 
        then parses the `screen` string to separate the base path from any 
        embedded query parameters, merges them into `params`, and triggers the 
        navigation using the cleaned path.

        Args:
            self (Window | Screen): The current UI context (either a Window or 
                a Screen) initiating the navigation.
            screen (str): The target screen route, which can include URL-style 
                query parameters (e.g., "settings/profile?user_id=123&theme=dark").
            params (dict, optional): Additional parameters to pass to the target 
                screen. Defaults to {}. Query parameters extracted from the 
                `screen` string will overwrite or merge into this dictionary.
        """

        if type(screen) == int:
            index = 0
            while (index < -screen):
                self.cursor.goBack()
                index += 1
            return

        parse = urlparse(screen)

        params.update(
            parse_qsl(
                parse.query
            )
        )

        self.cursor.setScreen(parse.path, params)

Navigates to a specified screen path, extracting embedded URL query parameters and merging them with additional parameters.

Methods

def navigate(self, screen: str | int, params: dict = {}) ‑> None
Expand source code
def navigate(self, screen: str | int, params: dict = {}) -> None:
    """
    This function automatically resolves the correct navigation controller 
    (`setScreen`) depending on whether `self` is a `Window` or a `Screen`. It 
    then parses the `screen` string to separate the base path from any 
    embedded query parameters, merges them into `params`, and triggers the 
    navigation using the cleaned path.

    Args:
        self (Window | Screen): The current UI context (either a Window or 
            a Screen) initiating the navigation.
        screen (str): The target screen route, which can include URL-style 
            query parameters (e.g., "settings/profile?user_id=123&theme=dark").
        params (dict, optional): Additional parameters to pass to the target 
            screen. Defaults to {}. Query parameters extracted from the 
            `screen` string will overwrite or merge into this dictionary.
    """

    if type(screen) == int:
        index = 0
        while (index < -screen):
            self.cursor.goBack()
            index += 1
        return

    parse = urlparse(screen)

    params.update(
        parse_qsl(
            parse.query
        )
    )

    self.cursor.setScreen(parse.path, params)

This function automatically resolves the correct navigation controller (setScreen) depending on whether self is a Window or a Screen. It then parses the screen string to separate the base path from any embedded query parameters, merges them into params, and triggers the navigation using the cleaned path.

Args
-----=
self : Window | Screen
The current UI context (either a Window or a Screen) initiating the navigation.
screen : str
The target screen route, which can include URL-style query parameters (e.g., "settings/profile?user_id=123&theme=dark").
params : dict, optional
Additional parameters to pass to the target screen. Defaults to {}. Query parameters extracted from the screen string will overwrite or merge into this dictionary.