Source code for ooodev.format.inner.partial.write.table.write_table_properties_partial

from __future__ import annotations
from typing import Any, Dict, TYPE_CHECKING
import contextlib
import uno

from ooodev.mock import mock_g
from import CancelEventArgs
from import EventArgs
from import GblNamedEvent
from import EventsPartial
from import StyleNameEvent
from ooodev.exceptions import ex as mEx
from ooodev.loader import lo as mLo
from ooodev.utils.context.lo_context import LoContext
from ooodev.utils.partial.lo_inst_props_partial import LoInstPropsPartial

    from import (

[docs]class WriteTablePropertiesPartial: """ Partial class for Write Table Properties. """
[docs] def __init__(self, component: Any) -> None: self.__component = component
[docs] def style_table_props( self, *, width: TblAbsUnit | TblRelUnit | None = None, left: TblAbsUnit | TblRelUnit | None = None, right: TblAbsUnit | TblRelUnit | None = None, above: TblAbsUnit | TblRelUnit | None = None, below: TblAbsUnit | TblRelUnit | None = None, align: TableAlignKind | None = None, relative: bool = False, ) -> TableProperties | None: """ Style Write Table Properties. Args: width (TblAbsUnit, TblRelUnit, optional): Specifies table Width. left (TblAbsUnit, TblRelUnit, optional): Specifies table Left. right (TblAbsUnit, TblRelUnit, optional): Specifies table Right. above (TblAbsUnit, TblRelUnit, optional): Specifies table spacing above. below (TblAbsUnit, TblRelUnit, optional): Specifies table spacing below. align (TableAlignKind, optional): Specifies table alignment. relative (bool, optional): Specifies if table horizontal values are in percentages or ``mm`` units. Raises: CancelEventError: If the event ``before_style_table_properties`` is cancelled and not handled. Returns: TableProperties | None: Table Properties Style instance or ``None`` if cancelled. Hint: - ``TblAbsUnit`` can be imported from ```` - ``TblRelUnit`` can be imported from ```` - ``TableAlignKind`` can be imported from ```` """ # pylint: disable=import-outside-toplevel # from import table_properties as tp from import TableProperties comp = self.__component has_events = False cargs = None # name = if isinstance(self, EventsPartial): has_events = True cargs = CancelEventArgs(self.style_table_props.__qualname__) event_data: Dict[str, Any] = { "width": width, "left": left, "right": right, "above": above, "below": below, "align": align, "relative": relative, "this_component": comp, } cargs.event_data = event_data self.trigger_event(StyleNameEvent.STYLE_APPLYING, cargs) self.trigger_event("before_style_table_properties", cargs) if cargs.cancel is True: if cargs.handled is True: return None cargs.set("initial_event", "before_style_table_properties") self.trigger_event(GblNamedEvent.EVENT_CANCELED, cargs) if cargs.handled is False: raise mEx.CancelEventError(cargs, "Style has been cancelled.") else: return None width = cargs.event_data.get("width", width) left = cargs.event_data.get("left", left) right = cargs.event_data.get("right", right) above = cargs.event_data.get("above", above) below = cargs.event_data.get("below", below) align = cargs.event_data.get("align", align) relative = cargs.event_data.get("relative", relative) comp = cargs.event_data.get("this_component", comp) fe = TableProperties( width=width, left=left, right=right, above=above, below=below, align=align, relative=relative, ) if has_events: fe.add_event_observer(self.event_observer) # type: ignore if isinstance(self, LoInstPropsPartial): lo_inst = self.lo_inst else: lo_inst = mLo.Lo.current_lo with LoContext(lo_inst): fe.apply(comp) fe.set_update_obj(comp) if cargs is not None: # pylint: disable=no-member event_args = EventArgs.from_args(cargs) event_args.event_data["styler_object"] = fe self.trigger_event("after_style_table_properties", event_args) # type: ignore self.trigger_event(StyleNameEvent.STYLE_APPLIED, event_args) # type: ignore return fe
[docs] def style_table_props_get(self) -> TableProperties | None: """ Gets the Table Properties Style. Returns: TableProperties | None: Table Properties Style instance or ``None`` if not available. """ # pylint: disable=import-outside-toplevel from import TableProperties with contextlib.suppress(Exception): return TableProperties.from_obj(self.__component) return None
if mock_g.FULL_IMPORT: from import TableAlignKind, TableProperties