Source code for ooodev.adapter.frame.component_loader_partial

from __future__ import annotations
from typing import Any, TYPE_CHECKING, Tuple
import uno

from import XComponentLoader

from ooodev.exceptions import ex as mEx
from ooodev.loader import lo as mLo
from ooodev.utils.type_var import UnoInterface

    from import PropertyValue  # struct
    from import XComponent

[docs]class ComponentLoaderPartial: """ Partial class for XComponentLoader. """
[docs] def __init__(self, component: XComponentLoader, interface: UnoInterface | None = XComponentLoader) -> None: """ Constructor Args: component (XComponentLoader): UNO Component that implements ```` interface. interface (UnoInterface, optional): The interface to be validated. Defaults to ``XComponentLoader``. """ self.__interface = interface self.__validate(component) self.__component = component
def __validate(self, component: Any) -> None: """ Validates the component. Args: component (Any): The component to be validated. """ if self.__interface is None: return if not mLo.Lo.is_uno_interfaces(component, self.__interface): raise mEx.MissingInterfaceError(self.__interface) # region XComponentLoader
[docs] def load_component_from_url( self, url: str, target_frame_name: str, search_flags: int, args: Tuple[PropertyValue, ...] ) -> XComponent: """ Loads a component specified by a URL into the specified new or existing frame. To create new documents, use ``private:factory/scalc``, ``private:factory/swriter``, etc. Other special protocols (e.g. ``slot:``, ``.uno``) are not allowed and raise a ````. If a frame with the specified name already exists, it is used, otherwise it is created. There exist some special targets which never can be used as real frame names: Flags are optional ones and will be used for non special target names only. For example, ``ReadOnly`` with a boolean value specifies whether the document is opened read-only. ``FilterName`` specifies the component type to create and the filter to use, for example: ``Text - CSV``. For more information see ````. This interface is a generic one and can be used to start further requests on loaded document or control the lifetime of it (means dispose() it after using). The real document service behind this interface can be one of follow three ones: Args: url (str): Specifies the URL of the document to load. target_frame_name (str): Specifies the name of the frame to view the document in. search_flags (int): Use the values of ``FrameSearchFlag`` to specify how to find the specified TargetFrameName args (Tuple[PropertyValue, ...]): The arguments. Raises: ``IOException`` ``IllegalArgumentException`` Returns: XComponent: The loaded component. Note: ``target_frame_name`` specifies the name of the frame to view the document in. - ``_blank``: Always creates a new frame. - ``_default``: Special UI functionality/ - ``_self``: Always uses the same frame. - ``_parent``: Address direct parent of frame - ``_top``: Indicates top frame of current path in tree. - ``_beamer``: Means special sub frame. See Also: - `FrameSearchFlag <>`__ - `XComponentLoader <>`__ """ return self.__component.loadComponentFromURL(url, target_frame_name, search_flags, args)
# endregion XComponentLoader