Class Props

class ooodev.utils.props.Props[source]

make/get/set properties in an array

static any(*elements)[source]

Gets a uno.Any object for elements.

Method is Lo Instance Safe for use with multiple documents.

The first element determines the type for the uno.Any object.

Raises:

ValueError – if unable to create uno.Any object.

Returns:

uno.Any Object

Return type:

uno.Any

Parameters:

elements (object) –

Note

uno.Any is usually constructed in the following manor.

uno.Any("[]com.sun.star.table.TableSortField", (sort_one, sort_two)

This method is a shortcut.

Props.any(sort_one, sort_two)

static data_to_dict(data)[source]

Convert tuples, list, PropertyValue, NamedValue to dictionary.

Method is Lo Instance Safe for use with multiple documents.

Parameters:

data (Sequence[Tuple[str, Any]] | Sequence[List[str]] | Sequence[PropertyValue] | Sequence[NamedValue]) – Data to convert to dictionary. If data is a sequence of tuples or list, the first element is the key and the second element is the value.

Returns:

Dictionary.

Return type:

Dict[str, Any]

New in version 0.40.0.

static dot_dict_to_props(dot_dict)[source]

Convert a DotDict to a list of PropertyValues.

Method is Lo Instance Safe for use with multiple documents.

Parameters:

dot_dict (DotDict) – DotDict to convert to PropertyValues.

Returns:

List of PropertyValues

Return type:

List[PropertyValue]

New in version 0.45.0.

classmethod get(obj, name)[source]
classmethod get(obj, name, default)
classmethod get(obj, name, default=<object object>)

Gets a property value from an object. obj must support XPropertySet interface.

Method is Lo Instance Safe for use with multiple documents.

Parameters:
  • obj (object) – Object to get property from.

  • name (str) – Property Name.

  • default (Any, optional) – Return value if property value is None.

Raises:
Returns:

Property value or default.

Return type:

Any

Note

If a default is not set then an error is raised if property is not found. Otherwise, the default value is returned if property is not found.

static get_bound_props(props_set)[source]

Gets bound Properties

Parameters:

props_set (XMultiPropertySet) – Multi Property Set

Returns:

Bound names

Return type:

Tuple[str, …]

static get_default(obj, prop_name, default=<object object>)[source]

Gets the default value of the property with the name Property Name.

Parameters:
  • obj (object) – object to set properties for. Must support XPropertyState

  • prop_name (str) – Property name to get default for.

  • default (Any, optional) – Return value if property value is None or obj does not support XPropertyState interface.

Raises:

MissingInterfaceError – If obj does not support XPropertyState interface and a default value is not provided.

Returns:

If no default exists, is not known or is None, then the return type is None.

Return type:

Any

static get_prop(props, name)[source]

Gets property value for property that matches name.

Method is Lo Instance Safe for use with multiple documents.

Parameters:
  • props (Iterable[PropertyValue]) – Properties to search

  • name (str) – Property name to find.

Raises:

TypeError – if props is None.

Returns:

Property value if found; Otherwise; None

Return type:

object | None

static get_prop_names(obj)[source]

Gets property names

Parameters:

obj (object) – Object that implements XPropertySet interface

Raises:

MissingInterfaceError – if obj dos not implement XPropertySet

Returns:

Property names of obj

Return type:

Tuple[str, …]

static get_properties(obj)[source]

Get properties

Parameters:

obj (object) – Object that implements XPropertySet interface

Raises:

MissingInterfaceError – if obj dos not implement XPropertySet

Returns:

Properties of obj

Return type:

Tuple[Property, …]

classmethod get_property(obj: object, name: str)[source]
classmethod get_property(prop_set: com.sun.star.beans.XPropertySet, name: str)
classmethod get_property(*args, **kwargs)

Gets a property value from property set

Parameters:
  • obj (object) – object that implements XPropertySet interface

  • xprops (XPropertySet) – property set

  • name (str) – property name

Raises:
Returns:

property value

Return type:

object

classmethod get_property_by_name(obj, name)[source]

Gets a property by name.

Method is Lo Instance Safe for use with multiple documents.

Property instances do not contain a value.

Parameters:
  • obj (object) – Object to get a property from

  • name (str) – Property name to lookup in obj.

Raises:

PropertyError – If error occurs

Returns:

Property instance.

Return type:

Property

classmethod get_property_set_info(obj)[source]

Gets property set info.

Method is Lo Instance Safe for use with multiple documents.

Parameters:

obj (object) – Object that implements XPropertySet.

Raises:

PropertyGeneralError – If error occurs

Returns:

Property Set Info

Return type:

XPropertySetInfo

static get_value(name, props)[source]

Get a property value from properties.

Method is Lo Instance Safe for use with multiple documents.

Parameters:
  • name (str) – property name

  • props (Iterable[PropertyValue]) – Properties to search

Raises:

PropertyError – If property name is not found.

Returns:

Property Value

Return type:

object

classmethod get_xproperty_fast_value(*, handle: int, fps: com.sun.star.beans.XFastPropertySet)[source]
classmethod get_xproperty_fast_value(*, prop: ooo.lo.beans.property.Property, fps: com.sun.star.beans.XFastPropertySet)
classmethod get_xproperty_fast_value(*, handle: int, obj: object)
classmethod get_xproperty_fast_value(*args, **kwargs)

Gets a fast property value via XFastPropertySet

Method is Lo Instance Safe for use with multiple documents.

Parameters:
  • handle (int) – handle of the property.

  • fps (XFastPropertySet) – property set that contains the property for matching handle.

  • prop (Property) – Property that handle can be obtained from.

  • obj (object) – an object that XFastPropertySet can be obtained from.

Raises:

PropertyGeneralError – If an error occurs.

Returns:

Property Value

Return type:

Any

static get_xproperty_set(obj)[source]

Gets Property Set.

Method is Lo Instance Safe for use with multiple documents.

Parameters:

obj (object) – object that implements XPropertySet

Raises:

MissingInterfaceError – if obj does not implement XPropertySet.

Returns:

Property Set

Return type:

XPropertySet

static get_xproperty_set_fast(obj)[source]

Gets Fast Property Set.

Method is Lo Instance Safe for use with multiple documents.

Parameters:

obj (object) – object that implements XFastPropertySet

Raises:

MissingInterfaceError – if obj does not implement XFastPropertySet.

Returns:

Property Set

Return type:

XFastPropertySet

classmethod has(obj, name)[source]

Gets if a object contains a property matching name

Parameters:
  • obj (object) – An object that implements XPropertySet

  • name (str) – Property Name

Returns:

True if obj contains Property that matches name; Otherwise, False

Return type:

bool

classmethod has_property(obj, name)[source]

Gets if a object contains a property matching name

Parameters:
  • obj (object) – An object that implements XPropertySet

  • name (str) – Property Name

Returns:

True if obj contains Property that matches name; Otherwise, False

Return type:

bool

classmethod make_bar_item(cmd, item_name)[source]

Properties for a toolbar item using a name and an image.

problem: image does not appear next to text on toolbar

Method is Lo Instance Safe for use with multiple documents.

Parameters:
  • cmd (str) – Value of CommandURL

  • item_name (str) – Label assigned to bar

Returns:

Tuple of properties. (CommandURL, Label, Type, Visible, Style)

Return type:

Tuple[PropertyValue, PropertyValue, PropertyValue, PropertyValue, PropertyValue]

static make_prop_value(name=None, value=None)[source]

Makes a Uno Property Value and assigns name and value if present.

Method is Lo Instance Safe for use with multiple documents.

Parameters:
  • name (Optional[str], optional) – Property name

  • value (Optional[Any], optional) – Property value

Returns:

com.sun.star.beans.PropertyValue

Return type:

PropertyValue

classmethod make_props(**kwargs)[source]

Make Properties.

Method is Lo Instance Safe for use with multiple documents.

Keyword Arguments:

kwargs (Dict[str, Any]) – Each key, value pair is assigned to a PropertyValue.

Returns:

Tuple of Properties

Return type:

Tuple[PropertyValue, …]

Parameters:

kwargs (Any) –

Note

String properties such as Zoom.Value can be pass by constructing a dictionary and passing dictionary via expansion.

Example Expansion

p_dic = {
    "Zoom.Value": 0,
    "Zoom.ValueSet": 28703,
    "Zoom.Type": 1
    }
props = Props.make_props(**p_dic)
classmethod make_props_any(**kwargs)[source]

Makes a uno.Any object for properties.

Keyword Arguments:

kwargs (Dict[str, Any]) – Each key, value pair is assigned to a PropertyValue.

Returns:

Array of []com.sun.star.beans.PropertyValue

Return type:

uno.Any

Parameters:

kwargs (Any) –

New in version 0.40.0.

static make_sting_pair(first='', second='')[source]

Makes a Uno String Pair and assigns first and second.

Method is Lo Instance Safe for use with multiple documents.

Parameters:
  • first (str, optional) – First string.

  • second (str, optional) – Second string.

Returns:

com.sun.star.beans.StringPair

Return type:

StringPair

New in version 0.40.0.

classmethod make_strings(**kwargs)[source]

Make String Pairs.

Method is Lo Instance Safe for use with multiple documents.

Keyword Arguments:

kwargs (Dict[str, str]) – Each key, value pair is assigned to a StringPair.

Returns:

Tuple of String Pairs

Return type:

Tuple[StringPair, …]

Parameters:

kwargs (str) –

New in version 0.40.0.

classmethod prop_value_to_string(val)[source]

Gets property values a a string.

Method is Lo Instance Safe for use with multiple documents.

Parameters:

val (object) – Values such as a iterable of iterable or object that implements XPropertySet or a string.

Returns:

A string representing properties.

Return type:

str

Example

>>> from ooodev.office.calc import Calc
>>> from ooodev.utils.props import Props
>>> from ooodev.loader.lo import Lo
>>> loader = Lo.load_office()
>>> doc = Calc.create_doc(loader)
>>> sheet = Calc.get_sheet(doc=doc, index=0)
>>> prop_str = Props.prop_value_to_string(sheet)
>>> print(prop_str)
[
    AbsoluteName = $Sheet1.$A$1:$AMJ$1048576
    AsianVerticalMode = False
    AutomaticPrintArea = True
    BorderColor = None
    BottomBorder = (com.sun.star.table.BorderLine2){ (com.sun.star.table.BorderLine){ Color = (long)0x0, InnerLineWidth = (short)0x0, OuterLineWidth = (short)0x0, LineDistance = (short)0x0 }, LineStyle = (short)0x0, LineWidth = (unsigned long)0x0 }
    BottomBorder2 = (com.sun.star.table.BorderLine2){ (com.sun.star.table.BorderLine){ Color = (long)0x0, InnerLineWidth = (short)0x0, OuterLineWidth = (short)0x0, LineDistance = (short)0x0 }, LineStyle = (short)0x0, LineWidth = (unsigned long)0x0 }
    CellBackColor = -1
    CellProtection = (com.sun.star.util.CellProtection){ IsLocked = (boolean)true, IsFormulaHidden = (boolean)false, IsHidden = (boolean)false, IsPrintHidden = (boolean)false }
    CellStyle = Default
    CharColor = -1
    ...
]
static props_set_to_array(xprops)

Converts Property Set to Tuple of Property

Parameters:

xprops (XPropertySet) – Property set

Returns:

Tuple of Property

Return type:

Tuple[Property, …]

static props_set_to_tuple(xprops)[source]

Converts Property Set to Tuple of Property

Parameters:

xprops (XPropertySet) – Property set

Returns:

Tuple of Property

Return type:

Tuple[Property, …]

static props_to_dot_dict(props)[source]

Convert a sequence of PropertyValues to a DotDict.

Method is Lo Instance Safe for use with multiple documents.

Parameters:

props (Sequence[PropertyValue]) – Properties to convert to DotDict.

Returns:

DotDict

Return type:

DotDict

New in version 0.45.0.

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

Set one or more properties.

Method is Lo Instance Safe for use with multiple documents.

Parameters:
  • obj (Any) – object to set properties for. Must support XPropertySet

  • **kwargs – Variable length Key value pairs used to set properties.

Raises:
Return type:

None

Events:

Note

If a Event is canceled then that property is not set. No error occurs.

If MultiError occurs only the properties that raised an error is part of the error object. The remaining properties will still be set.

If KeyValCancelArgs.default is set to true then property is set to Default

Note

If an error occurs a PROP_SET_ERROR is raised. If the event args are set to cancel or handled then the error is ignored.

See also

set_default()

Changed in version 0.9.0: Setting KeyValCancelArgs.default=False will set a property to its default.

Changed in version 0.9.4: Now event is raised if a property fails to set.

classmethod set_default(obj, *prop_names)[source]

Set one or more properties to default values.

Parameters:
  • obj (object) – object to set properties for. Must support XPropertyState

  • **prop_names (str) – Variable length of property names to set default.

Raises:
Return type:

None

Events:

Note

Event data is a dictionary of {"obj": obj, "name": name} with name being the property name currently being set.

If a Event is canceled then that property is not set. No error occurs.

If MultiError occurs only the properties that raised an error is part of the error object. The remaining properties will still be set to default.

New in version 0.9.0.

Changed in version 0.9.4: Now event is raised if a property fails to set default.

static set_prop(props, name, value)[source]

Sets property value for the first property that has matching name.

Method is Lo Instance Safe for use with multiple documents.

Parameters:
  • props (Iterable[PropertyValue]) – Property Values

  • name (str) – Property name

  • value (object) – Property Value

Raises:

TypeError – if props is None.

Returns:

True if property matching name has been updated; Otherwise, False

Return type:

bool

classmethod set_properties(obj: object, names: Sequence[str])[source]
classmethod set_properties(prop_set: com.sun.star.beans.XPropertySet, names: Sequence[str])
classmethod set_properties(obj: object, from_obj: object)
classmethod set_properties(prop_set: com.sun.star.beans.XPropertySet, from_props: com.sun.star.beans.XPropertySet)
classmethod set_properties(*args, **kwargs)

Set Properties

Parameters:
  • obj (object) – Object that implements XPropertySet interface

  • prop_set (XPropertySet) – Property set

  • from_props (XPropertySet) – Property set

  • from_obj (object) – Other object that implements XPropertySet interface

  • names (Sequence[str]) – Property Names

  • vals (Sequence[object]) – Property Values

Raises:
Return type:

None

Events:

Note

If a Event is canceled then that property is not set. No error occurs.

If MultiError occurs only the properties that raised an error is part of the error object. The remaining properties will still be set.

classmethod set_property(obj: object, name: str)[source]
classmethod set_property(prop_set: com.sun.star.beans.XPropertySet, name: str)
classmethod set_property(*args, **kwargs)

Sets the value of the property with the specified name.

Method is Lo Instance Safe for use with multiple documents.

Parameters:
  • obj (object) – object that implements XPropertySet interface

  • prop_set (XPropertySet) – Property set

  • name (str) – Name of property to set value of

  • value (object) – property value

Events:
Raises:
Return type:

None

Note

If a Event is canceled then property is not set. No error occurs.

classmethod show_doc_type_props(type)[source]

Prints doc type info to console

Parameters:

type (str) – doc type

Return type:

None

classmethod show_indexed_props(title, obj)[source]

Prints objects properties to console

Parameters:
  • title (str) – Title to print

  • obj (object) – object that implements XIndexAccess

Return type:

None

Example

>>> from ooodev.office.calc import Calc
>>> from ooodev.utils.props import Props
>>> from ooodev.loader.lo import Lo
>>> loader = Lo.load_office()
>>> doc = Calc.create_doc(loader)
>>> sheets = Calc.get_sheets(doc)
>>> Props.show_indexed_props("Sheets Property", sheets)
Indexed Properties for 'Sheets Property':
No. of elements: 1
Elem 0 Properties
  AbsoluteName: $Sheet1.$A$1:$AMJ$1048576
  AsianVerticalMode: False
  AutomaticPrintArea: True
  BorderColor: None
  BottomBorder: (com.sun.star.table.BorderLine2){ (com.sun.star.table.BorderLine){ Color = (long)0x0, InnerLineWidth = (short)0x0, OuterLineWidth = (short)0x0, LineDistance = (short)0x0 }, LineStyle = (short)0x0, LineWidth = (unsigned long)0x0 }
  BottomBorder2: (com.sun.star.table.BorderLine2){ (com.sun.star.table.BorderLine){ Color = (long)0x0, InnerLineWidth = (short)0x0, OuterLineWidth = (short)0x0, LineDistance = (short)0x0 }, LineStyle = (short)0x0, LineWidth = (unsigned long)0x0 }
  CellBackColor: -1
  CellProtection: (com.sun.star.util.CellProtection){ IsLocked = (boolean)true, IsFormulaHidden = (boolean)false, IsHidden = (boolean)false, IsPrintHidden = (boolean)false }
  CellStyle: Default
  CharColor: -1
  ...
Return type:

None

Parameters:
  • title (str) –

  • obj (object) –

classmethod show_obj_props(prop_kind, obj)[source]

Prints properties for an object to the console.

Method is Lo Instance Safe for use with multiple documents.

Parameters:
  • prop_kind (str) – The kind of properties that is displayed in console

  • obj (object) – object the implements XPropertySet interface.

Return type:

None

static show_property(p)[source]

Gets a property Name and type as string.

Parameters:

p (Property) – Property to print

Returns:

Property inf format of ‘Name: TypeName’

Return type:

str

classmethod show_props(title: str, props: Sequence[ooo.lo.beans.property_value.PropertyValue])[source]
classmethod show_props(prop_kind: str, props_set: com.sun.star.beans.XPropertySet)
classmethod show_props(*args, **kwargs)

Prints properties to console.

Method is Lo Instance Safe for use with multiple documents.

Parameters:
  • title (str) – Title to use that is displayed in console

  • props (Sequence[PropertyValue]) – Properties to print

  • prop_kind (str) – The kind of properties that is displayed in console

  • props_set (XPropertySet) – object the implements XPropertySet interface.

Return type:

None

classmethod show_values(name, props)[source]

Prints property to console

Parameters:
  • name (str) – Property Name

  • props (Iterable[PropertyValue]) – Properties

Return type:

None