ooodev.format.inner.style_base module

Base Styles class

class ooodev.format.inner.style_base.StyleBase(**kwargs)[source]

Bases: object

Base Styles class

New in version 0.9.0.

__init__(**kwargs)[source]
Return type:

None

add_event_listener(event_name, callback)[source]

Add an event listener to current instance.

Parameters:
  • event_name (str) – Event Name.

  • callback (EventCallback) – Callback of the event listener.

Return type:

None

Note

This method is generally only used in the context of child classes.

add_event_observer(*args)[source]

Adds observers that gets their trigger method called when this class trigger method is called.

Parameters:

args (EventObserver) – One or more observers to add.

Return type:

None

Note

Observers are removed automatically when they are out of scope.

apply(obj, **kwargs)[source]

Applies styles to object

Parameters:
  • obj (Any) – UNO Object that styles are to be applied.

  • kwargs (Any, optional) – Expandable list of key value pairs that may be used in child classes.

Keyword Arguments:
  • override_dv (Dic[str, Any], optional) – if passed in this dictionary is used to set properties instead of internal dictionary of property values.

  • validate (bool, optional) – if False then obj is not validated. Defaults to True.

Events:
Return type:

None

Note

If Event data obj, data_values or allow_update are changed then the new values are used.

Add update object to instance if not already set and allow_update is True (default).

Changed in version 0.27.0: Event data is now a dictionary with keys source, obj, data_values and allow_update.

Changed in version 0.9.4: Added validate keyword arguments.

backup(obj)[source]

Backs up Attributes that are to be changed by apply.

If used method should be called before apply.

Parameters:

obj (Any) – Object to backup properties from.

Return type:

None

Events:

See also

restore()

copy()[source]
copy(**kwargs)
copy(**kwargs)

Gets a copy of instance as a new instance

Return type:

TypeVar(TStyleBase, bound= StyleBase)

Parameters:

self (TStyleBase) –

get_attrs()[source]

Gets the attributes that are slated for change in the current instance

Returns:

Tuple of attributes

Return type:

Tuple(str, …)

get_props()[source]

Gets instance properties

Returns:

Tuple of properties.

Return type:

Tuple[PropertyValue, …]

get_update_obj()[source]

Gets the update object for the style instance.

Returns:

The update object if set; Otherwise, None.

Return type:

Any

New in version 0.28.2.

has_update_obj()[source]

Gets if the update object is set for the style instance.

Returns:

True if the update object is set; Otherwise, False.

Return type:

bool

New in version 0.27.0.

on_applied(source, event_args)[source]

Triggers after style/format is applied.

Parameters:
  • source (Any) – Event Source.

  • event_args (KeyValArgs) – Event Args

Return type:

None

on_applying(source, event_args)[source]

Triggers before style/format is applied.

Parameters:
  • source (Any) – Event Source.

  • event_args (CancelEventArgs) – Event Args

Return type:

None

on_property_backed_up(source, event_args)[source]

Triggers before each property that is about to be set during backup.

Parameters:
  • source (Any) – Event Source.

  • event_args (KeyValArgs) – Event Args

Return type:

None

on_property_backing_up(source, event_args)[source]

Triggers before each property that is about to be backup up during backup.

Parameters:
  • source (Any) – Event Source.

  • event_args (KeyValueCancelArgs) – Event Args.

Return type:

None

on_property_restore_set(source, event_args)[source]

Triggers for each property that has been set during restore

Parameters:
  • source (Any) – Event Source.

  • event_args (KeyValArgs) – Event Args

Return type:

None

on_property_restore_setting(source, event_args)[source]

Triggers before each property that is about to be set during restore

Parameters:
  • source (Any) – Event Source.

  • event_args (KeyValueCancelArgs) – Event Args

Return type:

None

on_property_set(source, event_args)[source]

Triggers for each property that is set.

Parameters:
  • source (Any) – Event Source.

  • event_args (KeyValArgs) – Event Args

Return type:

None

on_property_set_error(source, event_args)[source]

Triggers for each property that fails to set.

Parameters:
  • source (Any) – Event Source.

  • event_args (KeyValArgs) – Event Args

Return type:

None

on_property_setting(source, event_args)[source]

Triggers for each property that is set

Parameters:
  • source (Any) – Event Source.

  • event_args (KeyValueCancelArgs) – Event Args

Return type:

None

remove_event_listener(event_name, callback)[source]

Remove an event listener from current instance.

Parameters:
  • event_name (str) – Event Name.

  • callback (EventCallback) – Callback of the event listener.

Return type:

None

Note

This method is generally only used in the context of child classes.

remove_event_observer(observer)[source]

Removes an observer.

Parameters:

observer (EventObserver) – Observers to remove.

Returns:

True if observer has been removed; Otherwise, False.

Return type:

bool

New in version 0.30.1.

restore(obj, clear=False)[source]

Restores obj properties from backed up setting if any exist.

Restore can only be effective if backup() has be run before calling this method.

Parameters:
  • obj (Any) – Object to restore properties on.

  • clear (bool) – Determines if backup is cleared after restore. Default False

Return type:

None

Events:

See also

backup()

set_update_obj(obj)[source]

Sets the update object for the style instance.

Parameters:

obj (Any) – Object used to apply style to when update is called.

Return type:

None

New in version 0.27.0.

support_service(*service)[source]

Gets if service is supported.

Parameters:

service (str) – expandable list of service names of UNO services such as com.sun.star.text.TextFrame.

Returns:

True if service is supported; Otherwise, False.

Return type:

bool

update()[source]
update(**kwargs: Any)
update(**kwargs)

Applies the style to the update object.

Returns:

Returns True if the update object is set and the style is applied; Otherwise, False. kwargs: Expandable list of key value pairs that may be used in child classes.

Return type:

bool

Parameters:

kwargs (Any) –

Note

If the apply() method has been called then usually the style will set the update object. For some style it may be necessary to set the update object manually using the set_update_obj() method. The has_update_obj() method can be used to get the update object as been set

New in version 0.27.0.

property prop_format_kind: FormatKind

Gets the kind of style

Return type:

FormatKind

property prop_has_attribs: bool

Gets If instance has any attributes set.

Return type:

bool

property prop_has_backup: bool

Gets If instance has backup data set.

Return type:

bool

property prop_parent: StyleBase | None

Gets Parent Class

Return type:

StyleBase | None

class ooodev.format.inner.style_base.StyleModifyMulti(**kwargs)[source]

Bases: StyleMulti

Para Style Base

New in version 0.9.0.

__init__(**kwargs)[source]
Return type:

None

apply(obj: Any)[source]
apply(obj: Any, **kwargs)
apply(obj, **kwargs)

Applies padding to obj

Parameters:

obj (Any) – UNO Object such as a Document, Spreadsheet, or XStyle

Return type:

None

copy()[source]
copy(**kwargs)
copy(**kwargs)

Gets a copy of instance as a new instance

Return type:

TypeVar(_TStyleModifyMulti, bound= StyleModifyMulti)

Parameters:

self (_TStyleModifyMulti) –

get_style_props(doc)[source]

Gets the Style Properties

Parameters:

doc (Any) – UNO Document Object.

Raises:

NotSupportedDocumentError – If document is not supported.

Returns:

Styles properties property set.

Return type:

XPropertySet

property prop_format_kind: FormatKind

Gets the kind of style

Return type:

FormatKind

property prop_style_family_name: str

Gets/Set Style Family Name

Return type:

str

property prop_style_name: str

Gets/Sets property Style Name.

Raises:

NotImplementedError

Return type:

str

class ooodev.format.inner.style_base.StyleMulti(**kwargs)[source]

Bases: StyleBase

Multi style class.

Supports appending styles via _append_style() (protected) method. When apply_style() is call all internal style instances are also applied.

New in version 0.9.0.

__init__(**kwargs)[source]
Return type:

None

apply(obj, **kwargs)[source]

Applies style of current instance and all other internal style instances.

Parameters:

obj (Any) – UNO Object that styles are to be applied.

Return type:

None

backup(obj)[source]

Backs up Attributes that are to be changed by apply.

If used method should be called before apply.

Parameters:

obj (Any) – Object to backup properties from.

Return type:

None

Events:

See also

restore()

copy()[source]
copy(**kwargs)
copy(**kwargs)

Gets a copy of instance as a new instance

Return type:

TypeVar(TStyleMulti, bound= StyleMulti)

Parameters:

self (TStyleMulti) –

get_attrs()[source]

Gets the attributes that are slated for change in the current instance

Returns:

Tuple of attributes

Return type:

Tuple(str, …)

restore(obj, clear=False)[source]

Restores obj properties from backed up setting if any exist.

Restore can only be effective if backup() has be run before calling this method.

Parameters:
  • obj (Any) – Object to restore properties on.

  • clear (bool) – Determines if backup is cleared after restore. Default False

Return type:

None

Events:

See also

backup()

set_update_obj(obj)[source]

Sets the update object for the styles instances.

Parameters:

obj (Any) – Object used to apply style to when update is called.

Return type:

None

update(**kwargs)[source]

Applies the styles to the update object.

Returns:

Returns True if the update object is set and the style is applied; Otherwise, False. kwargs: Expandable list of key value pairs that may be used in child classes.

Return type:

bool

Parameters:

kwargs (Any) –

property prop_has_attribs: bool

Gets If instance has any attributes set.

Return type:

bool

property prop_has_backup: bool

Gets If instance or any added style has backup data set.

Return type:

bool

class ooodev.format.inner.style_base.StyleName(name, **kwargs)[source]

Bases: StyleBase

Style Name Base Class

__init__(name, **kwargs)[source]

Constructor

Parameters:

name (Any) – Style Name.

Raises:

ValueError – If Name is None or empty string.

Return type:

None

classmethod from_obj(obj)[source]
classmethod from_obj(obj, **kwargs)
classmethod from_obj(obj, **kwargs)

Gets instance from object

Parameters:

obj (Any) – UNO object.

Raises:

NotSupportedError – If obj is not supported.

Returns:

TStyleName instance that represents obj style.

Return type:

TStyleName

get_style_props()[source]

Gets Style as XPropertySet that contains all style properties.

Returns:

Returns result also implements com.sun.star.style.XStyle

Return type:

XPropertySet

New in version 0.9.2.

property prop_format_kind: FormatKind

Gets the kind of style

Return type:

FormatKind

property prop_name: str

Gets/Sets style name

Return type:

str

ooodev.format.inner.style_base.TStyleBase = TypeVar(TStyleBase, bound=StyleBase)

Type:    TypeVar

Invariant TypeVar bound to ooodev.format.inner.style_base.StyleBase.

ooodev.format.inner.style_base.TStyleMulti = TypeVar(TStyleMulti, bound=StyleMulti)

Type:    TypeVar

Invariant TypeVar bound to ooodev.format.inner.style_base.StyleMulti.

ooodev.format.inner.style_base.TStyleName = TypeVar(TStyleName, bound=StyleName)

Type:    TypeVar

Invariant TypeVar bound to ooodev.format.inner.style_base.StyleName.