Source code for ooodev.adapter.awt.uno_control_formatted_field_model_partial
from __future__ import annotations
import contextlib
from typing import Any, cast, TYPE_CHECKING
from ooo.dyn.text.font_emphasis import FontEmphasisEnum
from ooo.dyn.text.font_relief import FontReliefEnum
from ooo.dyn.style.vertical_alignment import VerticalAlignment
from ooo.dyn.awt.mouse_wheel_behavior import MouseWheelBehaviorEnum
from ooodev.utils import info as mInfo
from ooodev.events.events import Events
from ooodev.utils.kind.border_kind import BorderKind
from ooodev.utils.color import Color
from ooodev.utils.kind.align_kind import AlignKind
from ooodev.adapter.awt.uno_control_model_partial import UnoControlModelPartial
from ooodev.adapter.awt.font_descriptor_struct_comp import FontDescriptorStructComp
if TYPE_CHECKING:
from com.sun.star.util import XNumberFormatsSupplier
from com.sun.star.awt import UnoControlFormattedFieldModel # Service
from com.sun.star.awt import FontDescriptor # struct
from ooodev.events.args.key_val_args import KeyValArgs
[docs]class UnoControlFormattedFieldModelPartial(UnoControlModelPartial):
"""Partial class for UnoControlFormattedFieldModel."""
[docs] def __init__(self, component: UnoControlFormattedFieldModel):
"""
Constructor
Args:
component (Any): Component that implements ``com.sun.star.awt.UnoControlFormattedFieldModel`` service.
"""
# pylint: disable=unused-argument
self.__component = component
UnoControlModelPartial.__init__(self, component=component)
self.__event_provider = Events(self)
self.__props = {}
def on_comp_struct_changed(src: Any, event_args: KeyValArgs) -> None:
prop_name = str(event_args.event_data["prop_name"])
if hasattr(self.__component, prop_name):
setattr(self.__component, prop_name, event_args.source.component)
self.__fn_on_comp_struct_changed = on_comp_struct_changed
self.__event_provider.subscribe_event(
"com_sun_star_awt_FontDescriptor_changed", self.__fn_on_comp_struct_changed
)
[docs] def set_font_descriptor(self, font_descriptor: FontDescriptor | FontDescriptorStructComp) -> None:
"""
Sets the font descriptor of the control.
Args:
font_descriptor (FontDescriptor, FontDescriptorStructComp): UNO Struct - Font descriptor to set.
Note:
The ``font_descriptor`` property can also be used to set the font descriptor.
Hint:
- ``FontDescriptor`` can be imported from ``ooo.dyn.awt.font_descriptor``.
"""
self.font_descriptor = font_descriptor
# region Properties
@property
def font_descriptor(self) -> FontDescriptorStructComp:
"""
Gets/Sets the Font Descriptor.
Setting value can be done with a ``FontDescriptor`` or ``FontDescriptorStructComp`` object.
Returns:
~ooodev.adapter.awt.font_descriptor_struct_comp.FontDescriptorStructComp: Font Descriptor
Hint:
- ``FontDescriptor`` can be imported from ``ooo.dyn.awt.font_descriptor``.
"""
key = "FontDescriptor"
prop = self.__props.get(key, None)
if prop is None:
prop = FontDescriptorStructComp(self.__component.FontDescriptor, key, self.__event_provider)
self.__props[key] = prop
return cast(FontDescriptorStructComp, prop)
@font_descriptor.setter
def font_descriptor(self, value: FontDescriptor | FontDescriptorStructComp) -> None:
key = "FontDescriptor"
if mInfo.Info.is_instance(value, FontDescriptorStructComp):
self.__component.FontDescriptor = value.copy()
else:
self.__component.FontDescriptor = cast("FontDescriptor", value)
if key in self.__props:
del self.__props[key]
@property
def align(self) -> AlignKind:
"""
Get/Sets the horizontal alignment of the text in the control.
Hint:
- ``AlignKind`` can be imported from ``ooodev.utils.kind.align_kind``.
"""
return AlignKind(self.__component.Align)
@align.setter
def align(self, value: AlignKind | int) -> None:
kind = AlignKind(int(value))
self.__component.Align = kind.value
@property
def background_color(self) -> Color:
"""
Gets/Set the background color of the control.
Returns:
~ooodev.utils.color.Color: Color
"""
return Color(self.__component.BackgroundColor)
@background_color.setter
def background_color(self, value: Color) -> None:
self.__component.BackgroundColor = value # type: ignore
@property
def border(self) -> BorderKind:
"""
Gets/Sets the border style of the control.
Note:
Value can be set with ``BorderKind`` or ``int``.
Hint:
- ``BorderKind`` can be imported from ``ooodev.utils.kind.border_kind``.
"""
return BorderKind(self.__component.Border)
@border.setter
def border(self, value: int | BorderKind) -> None:
kind = BorderKind(int(value))
self.__component.Border = kind.value
@property
def border_color(self) -> Color | None:
"""
Gets/Sets the color of the border, if present
Not every border style (see Border) may support coloring.
For instance, usually a border with 3D effect will ignore the border_color setting.
**optional**
Returns:
~ooodev.utils.color.Color | None: Color or None if not set.
"""
with contextlib.suppress(AttributeError):
return Color(self.__component.BorderColor)
return None
@border_color.setter
def border_color(self, value: Color) -> None:
with contextlib.suppress(AttributeError):
self.__component.BorderColor = value
@property
def effective_default(self) -> Any:
"""
Gets the default value of the formatted field.
This may be a numeric value (double) or a string, depending on the formatting of the field.
"""
return self.__component.EffectiveDefault
@effective_default.setter
def effective_default(self, value: Any) -> None:
self.__component.EffectiveDefault = value
@property
def effective_max(self) -> float:
"""
Gets/Sets the maximum value that can be entered.
This property is ignored if the format of the field is no numeric format.
"""
return self.__component.EffectiveMax
@effective_max.setter
def effective_max(self, value: float) -> None:
self.__component.EffectiveMax = value
@property
def effective_min(self) -> float:
"""
Gets/Sets the minimum value that can be entered.
This property is ignored if the format of the field is no numeric format.
"""
return self.__component.EffectiveMin
@effective_min.setter
def effective_min(self, value: float) -> None:
self.__component.EffectiveMin = value
@property
def effective_value(self) -> Any:
"""
Gets/Sets specifies the current value of the formatted field.
This may be a numeric value (float) or a string, depending on the formatting of the field.
"""
# not sure why but UnoControlFormattedFieldModel does not have EffectiveValue property.
# however, it is documented in the API.
return self.__component.EffectiveValue # type: ignore
@effective_value.setter
def effective_value(self, value: Any) -> None:
self.__component.EffectiveValue = value # type: ignore
@property
def enabled(self) -> bool:
"""
Gets/Sets whether the control is enabled or disabled.
"""
return self.__component.Enabled
@enabled.setter
def enabled(self, value: bool) -> None:
self.__component.Enabled = value
@property
def font_emphasis_mark(self) -> FontEmphasisEnum:
"""
Gets/Sets the ``FontEmphasis`` value of the text in the control.
Note:
Value can be set with ``FontEmphasisEnum`` or ``int``.
Hint:
- ``FontEmphasisEnum`` can be imported from ``ooo.dyn.text.font_emphasis``.
"""
return FontEmphasisEnum(self.__component.FontEmphasisMark)
@font_emphasis_mark.setter
def font_emphasis_mark(self, value: int | FontEmphasisEnum) -> None:
self.__component.FontEmphasisMark = int(value)
@property
def font_relief(self) -> FontReliefEnum:
"""
Gets/Sets ``FontRelief`` value of the text in the control.
Note:
Value can be set with ``FontReliefEnum`` or ``int``.
Hint:
- ``FontReliefEnum`` can be imported from ``ooo.dyn.text.font_relief``.
"""
return FontReliefEnum(self.__component.FontRelief)
@property
def format_key(self) -> int:
"""
Gets/Sets the format to be used when formatting the field input and output.
This value is meaningful relative to the ``formats_supplier`` property only.
"""
return self.__component.FormatKey
@format_key.setter
def format_key(self, value: int) -> None:
self.__component.FormatKey = value
@font_relief.setter
def font_relief(self, value: int | FontReliefEnum) -> None:
self.__component.FontRelief = int(value)
@property
def formats_supplier(self) -> XNumberFormatsSupplier:
"""
Gets/Sets - supplies the formats the field should work with.
"""
return self.__component.FormatsSupplier
@formats_supplier.setter
def formats_supplier(self, value: XNumberFormatsSupplier) -> None:
self.__component.FormatsSupplier = value
@property
def help_text(self) -> str:
"""
Get/Sets the help text of the control.
"""
return self.__component.HelpText
@help_text.setter
def help_text(self, value: str) -> None:
self.__component.HelpText = value
@property
def help_url(self) -> str:
"""
Gets/Sets the help URL of the control.
"""
return self.__component.HelpURL
@help_url.setter
def help_url(self, value: str) -> None:
self.__component.HelpURL = value
@property
def hide_inactive_selection(self) -> bool | None:
"""
Gets/Sets whether the selection in the control should be hidden when the control is not active (focused).
**optional**
"""
with contextlib.suppress(AttributeError):
return self.__component.HideInactiveSelection
return None
@hide_inactive_selection.setter
def hide_inactive_selection(self, value: bool) -> None:
with contextlib.suppress(AttributeError):
self.__component.HideInactiveSelection = value
@property
def max_text_len(self) -> int:
"""
Gets/Sets the maximum character count.
There's no limitation, if set to 0.
"""
return self.__component.MaxTextLen
@max_text_len.setter
def max_text_len(self, value: int) -> None:
self.__component.MaxTextLen = value
@property
def mouse_wheel_behavior(self) -> MouseWheelBehaviorEnum | None:
"""
Gets/Sets how the mouse wheel can be used to scroll through the control's content.
Usually, the mouse wheel scroll through the control's entry list.
Using this property,you can control under which circumstances this is possible.
**optional**
Note:
Value can be set with ``MouseWheelBehaviorEnum`` or ``int``.
Hint:
- ``MouseWheelBehaviorEnum`` can be imported from ``ooo.dyn.awt.mouse_wheel_behavior``
"""
with contextlib.suppress(AttributeError):
return MouseWheelBehaviorEnum(self.__component.MouseWheelBehavior)
return None
@mouse_wheel_behavior.setter
def mouse_wheel_behavior(self, value: int | MouseWheelBehaviorEnum) -> None:
with contextlib.suppress(AttributeError):
self.__component.MouseWheelBehavior = int(value)
@property
def printable(self) -> bool:
"""
Gets/Sets that the control will be printed with the document.
"""
return self.__component.Printable
@printable.setter
def printable(self, value: bool) -> None:
self.__component.Printable = value
@property
def read_only(self) -> bool:
"""
Gets/Sets if the content of the control cannot be modified by the user.
"""
return self.__component.ReadOnly
@read_only.setter
def read_only(self, value: bool) -> None:
self.__component.ReadOnly = value
@property
def repeat(self) -> bool | None:
"""
Gets/Sets whether the mouse should show repeating behavior, i.e.
repeatedly trigger an action when keeping pressed.
**optional**
"""
with contextlib.suppress(AttributeError):
return self.__component.Repeat
return None
@repeat.setter
def repeat(self, value: bool) -> None:
with contextlib.suppress(AttributeError):
self.__component.Repeat = value
@property
def repeat_delay(self) -> int | None:
"""
Gets/Sets the mouse repeat delay, in milliseconds.
When the user presses a mouse in a control area where this triggers an action (such as spinning the value), then usual control implementations allow to repeatedly trigger this action, without the need to release the mouse button and to press it again.
The delay between two such triggers is specified with this property.
**optional**
"""
with contextlib.suppress(AttributeError):
return self.__component.RepeatDelay
return None
@repeat_delay.setter
def repeat_delay(self, value: int) -> None:
with contextlib.suppress(AttributeError):
self.__component.RepeatDelay = value
@property
def spin(self) -> bool:
"""
Gets/Sets if the control has a spin button.
"""
return self.__component.Spin
@spin.setter
def spin(self, value: bool) -> None:
self.__component.Spin = value
@property
def strict_format(self) -> bool:
"""
Gets/Sets if the value is checked during the user input.
"""
return self.__component.StrictFormat
@strict_format.setter
def strict_format(self, value: bool) -> None:
self.__component.StrictFormat = value
@property
def tabstop(self) -> bool:
"""
Gets/Sets that the control can be reached with the TAB key.
"""
return self.__component.Tabstop
@tabstop.setter
def tabstop(self, value: bool) -> None:
self.__component.Tabstop = value
@property
def text(self) -> str:
"""
Gets/Sets the text displayed in the control.
"""
return self.__component.Text
@text.setter
def text(self, value: str) -> None:
self.__component.Text = value
@property
def text_color(self) -> Color:
"""
Gets/Sets the text color of the control.
Returns:
~ooodev.utils.color.Color: Color
"""
return Color(self.__component.TextColor)
@text_color.setter
def text_color(self, value: Color) -> None:
self.__component.TextColor = value # type: ignore
@property
def text_line_color(self) -> Color:
"""
Gets/Sets the text line color of the control.
Returns:
~ooodev.utils.color.Color: Color
"""
return Color(self.__component.TextLineColor)
@text_line_color.setter
def text_line_color(self, value: Color) -> None:
self.__component.TextLineColor = value # type: ignore
@property
def treat_as_number(self) -> bool:
"""
Gets/Sets if the text is treated as a number.
"""
return self.__component.TreatAsNumber
@treat_as_number.setter
def treat_as_number(self, value: bool) -> None:
self.__component.TreatAsNumber = value
@property
def vertical_align(self) -> VerticalAlignment | None:
"""
Gets/Sets the vertical alignment of the text in the control.
**optional**
Hint:
- ``VerticalAlignment`` can be imported from ``ooo.dyn.style.vertical_alignment``
"""
with contextlib.suppress(AttributeError):
return self.__component.VerticalAlign # type: ignore
return None
@vertical_align.setter
def vertical_align(self, value: VerticalAlignment) -> None:
with contextlib.suppress(AttributeError):
self.__component.VerticalAlign = value # type: ignore
@property
def writing_mode(self) -> int | None:
"""
Denotes the writing mode used in the control, as specified in the ``com.sun.star.text.WritingMode2`` constants group.
Only LR_TB (``0``) and RL_TB (``1``) are supported at the moment.
**optional**
"""
with contextlib.suppress(AttributeError):
return self.__component.WritingMode
return None
@writing_mode.setter
def writing_mode(self, value: int) -> None:
with contextlib.suppress(AttributeError):
self.__component.WritingMode = value
# endregion Properties