Source code for ooodev.adapter.script.library_container_partial

from __future__ import annotations
from typing import Any, overload, TYPE_CHECKING
from com.sun.star.script import XLibraryContainer

from ooodev.exceptions import ex as mEx
from ooodev.loader import lo as mLo
from ooodev.adapter.container.name_container_comp import NameContainerComp
from ooodev.adapter.container.name_access_comp import NameAccessComp

if TYPE_CHECKING:
    from typing_extensions import Literal
    from ooodev.utils.type_var import UnoInterface


[docs]class LibraryContainerPartial: """ Partial class for XLibraryContainer. """
[docs] def __init__(self, component: XLibraryContainer, interface: UnoInterface | None = XLibraryContainer) -> None: """ Constructor Args: component (XLibraryContainer): UNO Component that implements ``com.sun.star.script.XLibraryContainer`` interface. interface (UnoInterface, optional): The interface to be validated. Defaults to ``XLibraryContainer``. """ def validate(comp: Any, obj_type: Any) -> None: if obj_type is None: return if not mLo.Lo.is_uno_interfaces(comp, obj_type): raise mEx.MissingInterfaceError(obj_type) validate(component, interface) self.__component = component
# region XLibraryContainer
[docs] def create_library(self, name: str) -> NameContainerComp: """ Creates a new library. Args: name (str): The name of the library. Raises: com.sun.star.lang.IllegalArgumentException: ``IllegalArgumentException`` com.sun.star.container.ElementExistException: ``ElementExistException`` """ return NameContainerComp(self.__component.createLibrary(name))
@overload def create_library_link(self, name: str, storage_url: str, read_only: Literal[True]) -> NameAccessComp: ... @overload def create_library_link(self, name: str, storage_url: str, read_only: Literal[False]) -> NameContainerComp: ...
[docs] def is_library_loaded(self, name: str) -> bool: """ returns true if the accessed library is already loaded from the storage, otherwise false. Raises: com.sun.star.container.NoSuchElementException: ``NoSuchElementException`` """ return self.__component.isLibraryLoaded(name)
[docs] def load_library(self, name: str) -> None: """ Causes the accessed library to be loaded from its storage if it hasn't already been loaded. Raises: com.sun.star.container.NoSuchElementException: ``NoSuchElementException`` com.sun.star.lang.WrappedTargetException: ``WrappedTargetException`` """ self.__component.loadLibrary(name)
[docs] def remove_library(self, name: str) -> None: """ removes the library item with the specified name. If the accessed library item is a link only the link is removed, not the target library. Raises: com.sun.star.container.NoSuchElementException: ``NoSuchElementException`` com.sun.star.lang.WrappedTargetException: ``WrappedTargetException`` """ self.__component.removeLibrary(name)
# endregion XLibraryContainer