Variable Declaration
Classes for ODF document variables declarations.
This module provides classes for managing variable declaration “text:variable-decl” and variable declaration container “text:variable-decls”.
Classes:
| Name | Description |
|---|---|
VarDecl |
A variable declaration, “text:variable-decl”. |
VarDeclMixin |
Mixin class for elements that can contain variable declarations. |
VarDecls |
A container for variable declarations, “text:variable-decls”. |
VarDecl
Bases: Element
A variable declaration, “text:variable-decl”.
This element defines a variable by its name and value type.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The unique name of the variable. |
value_type |
str
|
The ODF value type (e.g., ‘string’, ‘float’). |
Methods:
| Name | Description |
|---|---|
__init__ |
Initializes the VarDecl element. |
Source code in odfdo/variable_declaration.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | |
_properties
class-attribute
instance-attribute
_properties = (
PropDef("name", "text:name"),
PropDef("value_type", "office:value-type"),
)
_tag
class-attribute
instance-attribute
_tag = 'text:variable-decl'
name
instance-attribute
name = name
value_type
instance-attribute
value_type = value_type
__init__
__init__(
name: str | None = None,
value_type: str | None = None,
**kwargs: Any,
) -> None
Initializes the VarDecl element.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str | None
|
The name of the variable. |
None
|
value_type
|
str | None
|
The ODF value type. |
None
|
Source code in odfdo/variable_declaration.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | |
VarDeclMixin
Bases: Element
Mixin class for elements that can contain variable declarations.
This mixin provides methods to access and manipulate “text:variable-decls” and “text:variable-decl”.
Used by the following classes
- “office:chart”
- “office:drawing”
- “office:presentation”
- “office:spreadsheet”
- “office:text”
- “style:footer”
- “style:footer-first”
- “style:footer-left”
- “style:header”
- “style:header-first”
- “style:header-left”
Methods:
| Name | Description |
|---|---|
get_variable_decl |
Returns a single variable declaration that matches the specified criteria. |
get_variable_decl_list |
Returns all variable declarations as a list. |
get_variable_decls |
Returns the container for variable declarations. |
Source code in odfdo/variable_declaration.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | |
get_variable_decl
get_variable_decl(
name: str, position: int = 0
) -> VarDecls | None
Returns a single variable declaration that matches the specified criteria.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the variable declaration to retrieve. |
required |
position
|
int
|
The 0-based index of the matching variable declaration to return. |
0
|
Returns:
| Type | Description |
|---|---|
VarDecls | None
|
VarDecls | None: A VarDecls instance, or None if no declaration matches the criteria. |
Source code in odfdo/variable_declaration.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | |
get_variable_decl_list
get_variable_decl_list() -> list[VarDecls]
Returns all variable declarations as a list.
Returns:
| Type | Description |
|---|---|
list[VarDecls]
|
list[VarDecls]: A list of all VarDecls instances that are descendants of this element. |
Source code in odfdo/variable_declaration.py
74 75 76 77 78 79 80 81 82 | |
get_variable_decls
get_variable_decls() -> VarDecls
Returns the container for variable declarations.
If the container is not found, it is created within the document body.
Returns:
| Name | Type | Description |
|---|---|---|
VarDecls |
VarDecls
|
The VarDecls instance (container for variable declarations). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the document body is empty and a new container cannot be inserted. |
Source code in odfdo/variable_declaration.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | |
VarDecls
Bases: Element
A container for variable declarations, “text:variable-decls”.
This element groups all the ‘text:variable-decl’ elements in the document.
Source code in odfdo/variable_declaration.py
102 103 104 105 106 107 108 109 | |
_tag
class-attribute
instance-attribute
_tag = 'text:variable-decls'