# region Imports
from __future__ import annotations
from typing import cast
from ooodev.format.inner.modify.calc.cell_style_base_multi import CellStyleBaseMulti
from ooodev.format.calc.style.cell.kind.style_cell_kind import StyleCellKind
from ooodev.format.inner.direct.calc.background.color import Color as InnerColor
from ooodev.utils import color as mColor
from ooodev.utils.color import StandardColor
# endregion Imports
[docs]class Color(CellStyleBaseMulti):
"""
Cell Style Background Color.
.. seealso::
- :ref:`help_calc_format_modify_cell_background`
.. versionadded:: 0.9.0
"""
# region Init
[docs] def __init__(
self,
*,
color: mColor.Color = StandardColor.AUTO_COLOR,
style_name: StyleCellKind | str = StyleCellKind.DEFAULT,
style_family: str = "CellStyles",
) -> None:
"""
Constructor
Args:
color (:py:data:`~.utils.color.Color`, optional): Color such as ``CommonColor.LIGHT_BLUE``.
style_name (StyleCellKind, str, optional): Specifies the Cell Style that instance applies to.
Default is Default Cell Style.
style_family (str, optional): Style family. Default ``CellStyles``.
Returns:
None:
See Also:
- :ref:`help_calc_format_modify_cell_background`
"""
direct = InnerColor(color=color)
super().__init__()
self._style_name = str(style_name)
self._style_family_name = style_family
self._set_style("direct", direct)
# endregion Init
# region Static Methods
[docs] @classmethod
def from_style(
cls,
doc: object,
style_name: StyleCellKind | str = StyleCellKind.DEFAULT,
style_family: str = "CellStyles",
) -> Color:
"""
Gets instance from Document.
Args:
doc (object): UNO Document Object.
style_name (StyleCellKind, str, optional): Specifies the Cell Style that instance applies to.
Default is Default Cell Style.
style_family (str, optional): Style family. Default ``CellStyles``.
Returns:
Color: ``Color`` instance from style properties.
"""
inst = cls(style_name=style_name, style_family=style_family)
direct = InnerColor.from_obj(obj=inst.get_style_props(doc))
inst._set_style("direct", direct)
return inst
# endregion Static Methods
# region Properties
@property
def prop_style_name(self) -> str:
"""Gets/Sets property Style Name"""
return self._style_name
@prop_style_name.setter
def prop_style_name(self, value: str | StyleCellKind):
self._style_name = str(value)
@property
def prop_inner(self) -> InnerColor:
"""Gets/Sets Inner Color instance"""
try:
return self._direct_inner
except AttributeError:
self._direct_inner = cast(InnerColor, self._get_style_inst("direct"))
return self._direct_inner
@prop_inner.setter
def prop_inner(self, value: InnerColor) -> None:
if not isinstance(value, InnerColor):
raise TypeError(f'Expected type of InnerColor, got "{type(value).__name__}"')
self._del_attribs("_direct_inner")
self._set_style("direct", value)
# endregion Properties