Source code for

Module for Page Style Fill Color Fill Color.

.. versionadded:: 0.9.0

# region Import
from __future__ import annotations
from typing import Any, Tuple, overload, TypeVar

from import XPropertySet

from ooodev.exceptions import ex as mEx
from ooodev.utils import info as mInfo
from ooodev.loader import lo as mLo
from ooodev.format.inner.kind.format_kind import FormatKind
from ooodev.format.inner.style_base import StyleBase
from import WriterStylePageKind
from import FormatNamedEvent
from import EventArgs
from import CancelEventArgs

# endregion Import

# LibreOffice seems to have an unresolved bug with Background color.
# see Also:
# The solution to these issues is to apply FillColor to Paragraph cursors TextParagraph.

_TPageStyleBase = TypeVar("_TPageStyleBase", bound="PageStyleBase")

[docs]class PageStyleBase(StyleBase): """ Page Style Base .. versionadded:: 0.9.0 """ def _supported_services(self) -> Tuple[str, ...]: return () def _is_valid_obj(self, obj: object) -> bool: return mInfo.Info.is_doc_type(obj, mLo.Lo.Service.WRITER)
[docs] def copy(self: _TPageStyleBase) -> _TPageStyleBase: """Gets a copy of instance as a new instance""" cp = super().copy() cp.prop_style_name = self.prop_style_name return cp
# region apply() @overload def apply(self, obj: Any) -> None: ... @overload def apply(self, obj: Any, **kwargs) -> None: ...
[docs] def apply(self, obj: Any, **kwargs) -> None: """ Applies padding to ``obj`` Args: obj (Any): UNO Writer Document Returns: None: """ cargs = CancelEventArgs(source=f"{self.apply.__qualname__}") cargs.event_data = self if cargs.cancel: return self._events.trigger(FormatNamedEvent.STYLE_APPLYING, cargs) if cargs.cancel: return try: if self._is_valid_obj(obj): p = self._get_style_props(obj) # Could call p.setPropertyValue() here instead of Props.set() # but by calling Props.set() events are triggered. self._props_set(p, **self._get_properties()) eargs = EventArgs.from_args(cargs) self._events.trigger(FormatNamedEvent.STYLE_APPLIED, eargs) else: mLo.Lo.print(f"{self.__class__.__name__}.apply(): Not a Writer Document. Unable to set Style Property") except mEx.MultiError as e: mLo.Lo.print(f"{self.__class__.__name__}.apply(): Unable to set Style Property") for err in e.errors: mLo.Lo.print(f" {err}")
# endregion apply() def _get_style_props(self, obj: object) -> XPropertySet: return mInfo.Info.get_style_props(obj, "PageStyles", self.prop_style_name) @property def prop_format_kind(self) -> FormatKind: """Gets the kind of style""" return FormatKind.PAGE | FormatKind.STYLE @property def prop_style_name(self) -> str: """ Gets/Sets property Style Name. Raises: NotImplementedError: """ raise NotImplementedError @prop_style_name.setter def prop_style_name(self, value: str | WriterStylePageKind): raise NotImplementedError