Variable
Classes for ODF document variables and fields.
This module provides classes for various types of document fields that can be automatically updated, such as dates, times, page numbers, and document metadata (e.g., author, title). It also includes classes for declaring and managing custom variables (‘text:variable-set’, ‘text:variable-get’).
Classes:
| Name | Description |
|---|---|
VarChapter |
A chapter field, “text:chapter”. |
VarCreationDate |
A creation date field, “text:creation-date”. |
VarCreationTime |
A creation time field, “text:creation-time”. |
VarDate |
A date field, “text:date”. |
VarDescription |
A description field, “text:description”. |
VarFileName |
A file name field, “text:file-name”. |
VarGet |
A variable getter, “text:variable-get”. |
VarInitialCreator |
An initial creator field, “text:initial-creator”. |
VarKeywords |
A keywords field, “text:keywords”. |
VarPageCount |
A page count field, “text:page-count”. |
VarPageNumber |
A page number field, “text:page-number”. |
VarSet |
A variable setter, “text:variable-set”. |
VarSubject |
A subject field, “text:subject”. |
VarTime |
A time field, “text:time”. |
VarTitle |
A title field, “text:title”. |
VarChapter
Bases: Element
A chapter field, “text:chapter”.
Displays information about the current chapter, such as its name or number.
Attributes:
| Name | Type | Description |
|---|---|---|
display |
str
|
The format for displaying the chapter information (e.g., ‘name’, ‘number’, ‘number-and-name’). |
outline_level |
str
|
The heading level to consider for the chapter information. |
Methods:
| Name | Description |
|---|---|
__init__ |
Initializes the VarChapter element. |
Source code in odfdo/variable.py
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 | |
DISPLAY_VALUE_CHOICE
class-attribute
instance-attribute
DISPLAY_VALUE_CHOICE: ClassVar = {
"number",
"name",
"number-and-name",
"plain-number",
"plain-number-and-name",
}
_properties
class-attribute
instance-attribute
_properties = (
PropDef("display", "text:display"),
PropDef("outline_level", "text:outline-level"),
)
_tag
class-attribute
instance-attribute
_tag = 'text:chapter'
display
instance-attribute
display = display
outline_level
instance-attribute
outline_level = outline_level
__init__
__init__(
display: str | None = "name",
outline_level: str | None = None,
**kwargs: Any,
) -> None
Initializes the VarChapter element.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
display
|
str | None
|
The format for the chapter information. Can be ‘name’ (default), ‘number’, ‘number-and-name’, etc. |
'name'
|
outline_level
|
str | None
|
The heading outline level to use for chapter context. |
None
|
Source code in odfdo/variable.py
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 | |
VarCreationDate
Bases: Element
A creation date field, “text:creation-date”.
Displays the date the document was created, based on metadata.
Attributes:
| Name | Type | Description |
|---|---|---|
fixed |
bool
|
If True, the field is not updated automatically. |
data_style |
str
|
The style for formatting the date. |
Methods:
| Name | Description |
|---|---|
__init__ |
Initializes the VarCreationDate element. |
Source code in odfdo/variable.py
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 | |
_properties
class-attribute
instance-attribute
_properties = (
PropDef("fixed", "text:fixed"),
PropDef("data_style", "style:data-style-name"),
)
_tag
class-attribute
instance-attribute
_tag = 'text:creation-date'
data_style
instance-attribute
data_style = data_style
fixed
instance-attribute
fixed = True
__init__
__init__(
fixed: bool = False,
data_style: str | None = None,
**kwargs: Any,
) -> None
Initializes the VarCreationDate element.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fixed
|
bool
|
If True, the field is not updated automatically. |
False
|
data_style
|
str | None
|
The style name for formatting. |
None
|
Source code in odfdo/variable.py
510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 | |
VarCreationTime
Bases: Element
A creation time field, “text:creation-time”.
Displays the time the document was created, based on metadata.
Attributes:
| Name | Type | Description |
|---|---|---|
fixed |
bool
|
If True, the field is not updated automatically. |
data_style |
str
|
The style for formatting the time. |
Methods:
| Name | Description |
|---|---|
__init__ |
Initializes the VarCreationTime element. |
Source code in odfdo/variable.py
533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 | |
_properties
class-attribute
instance-attribute
_properties = (
PropDef("fixed", "text:fixed"),
PropDef("data_style", "style:data-style-name"),
)
_tag
class-attribute
instance-attribute
_tag = 'text:creation-time'
data_style
instance-attribute
data_style = data_style
fixed
instance-attribute
fixed = True
__init__
__init__(
fixed: bool = False,
data_style: str | None = None,
**kwargs: Any,
) -> None
Initializes the VarCreationTime element.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fixed
|
bool
|
If True, the field is not updated automatically. |
False
|
data_style
|
str | None
|
The style name for formatting. |
None
|
Source code in odfdo/variable.py
549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 | |
VarDate
Bases: Element
A date field, “text:date”.
Displays a date, which can be fixed or automatically updated.
Attributes:
| Name | Type | Description |
|---|---|---|
date |
str
|
The date value in ISO 8601 format. |
fixed |
bool
|
If True, the date is not updated automatically. |
data_style |
str
|
The style for formatting the date. |
date_adjust |
str
|
A duration to add to or subtract from the date. |
Methods:
| Name | Description |
|---|---|
__init__ |
Initializes the VarDate element. |
Source code in odfdo/variable.py
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
_properties
class-attribute
instance-attribute
_properties = (
PropDef("date", "text:date-value"),
PropDef("fixed", "text:fixed"),
PropDef("data_style", "style:data-style-name"),
PropDef("date_adjust", "text:date-adjust"),
)
_tag
class-attribute
instance-attribute
_tag = 'text:date'
data_style
instance-attribute
data_style = data_style
date
instance-attribute
date = encode(date)
date_adjust
instance-attribute
date_adjust = encode(date_adjust)
fixed
instance-attribute
fixed = True
text
instance-attribute
text = text
__init__
__init__(
date: datetime | None = None,
fixed: bool = False,
data_style: str | None = None,
text: str | None = None,
date_adjust: timedelta | None = None,
**kwargs: Any,
) -> None
Initializes the VarDate element.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
date
|
datetime | None
|
The date value. If not provided, the field may be updated automatically by a consumer. |
None
|
fixed
|
bool
|
If True, the date is not updated automatically. |
False
|
data_style
|
str | None
|
The style name for formatting. |
None
|
text
|
str | None
|
The textual representation of the date.
If not provided, it is generated from |
None
|
date_adjust
|
timedelta | None
|
A timedelta to adjust the date value. |
None
|
Source code in odfdo/variable.py
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
VarDescription
Bases: VarInitialCreator
A description field, “text:description”.
Displays the document’s description (or comments) from its metadata.
Source code in odfdo/variable.py
572 573 574 575 576 577 578 | |
_tag
class-attribute
instance-attribute
_tag = 'text:description'
VarFileName
Bases: Element
A file name field, “text:file-name”.
Displays the file name of the document, with different formatting options.
Attributes:
| Name | Type | Description |
|---|---|---|
display |
str
|
The format for the file name (‘full’, ‘path’, ‘name’, ‘name-and-extension’). |
fixed |
bool
|
If True, the file name is not updated automatically. |
Methods:
| Name | Description |
|---|---|
__init__ |
Initializes the VarFileName element. |
Source code in odfdo/variable.py
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 | |
DISPLAY_VALUE_CHOICE
class-attribute
instance-attribute
DISPLAY_VALUE_CHOICE: ClassVar = {
"full",
"path",
"name",
"name-and-extension",
}
_properties
class-attribute
instance-attribute
_properties = (
PropDef("display", "text:display"),
PropDef("fixed", "text:fixed"),
)
_tag
class-attribute
instance-attribute
_tag = 'text:file-name'
display
instance-attribute
display = display
fixed
instance-attribute
fixed = True
__init__
__init__(
display: str | None = "full",
fixed: bool = False,
**kwargs: Any,
) -> None
Initializes the VarFileName element.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
display
|
str | None
|
The format for the file name. Can be ‘full’ (default), ‘path’, ‘name’, or ‘name-and-extension’. |
'full'
|
fixed
|
bool
|
If True, the field is not updated automatically. |
False
|
Source code in odfdo/variable.py
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 | |
VarGet
Bases: ElementTyped
A variable getter, “text:variable-get”.
This element displays the current value of a variable at its position in the document.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The name of the variable to display. |
style |
str
|
The data style for formatting the value. |
Methods:
| Name | Description |
|---|---|
__init__ |
Initializes the VarGet element. |
Source code in odfdo/variable.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | |
_properties
class-attribute
instance-attribute
_properties = (
PropDef("name", "text:name"),
PropDef("style", "style:data-style-name"),
)
_tag
class-attribute
instance-attribute
_tag = 'text:variable-get'
name
instance-attribute
name = name
style
instance-attribute
style = style
text
instance-attribute
text = text
__init__
__init__(
name: str | None = None,
value: Any = None,
value_type: str | None = None,
text: str | None = None,
style: str | None = None,
**kwargs: Any,
) -> None
Initializes the VarGet element.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str | None
|
The name of the variable to get. |
None
|
value
|
Any
|
An initial value to display. |
None
|
value_type
|
str | None
|
The ODF value type. |
None
|
text
|
str | None
|
The textual representation to display. |
None
|
style
|
str | None
|
The data style name for formatting. |
None
|
Source code in odfdo/variable.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | |
VarInitialCreator
Bases: Element
An initial creator field, “text:initial-creator”.
Displays the name of the person who initially created the document, based on the document’s metadata.
Attributes:
| Name | Type | Description |
|---|---|---|
fixed |
bool
|
If True, the field is not updated automatically. |
Methods:
| Name | Description |
|---|---|
__init__ |
Initializes the VarInitialCreator element. |
Source code in odfdo/variable.py
467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 | |
_properties
class-attribute
instance-attribute
_properties = (PropDef('fixed', 'text:fixed'),)
_tag
class-attribute
instance-attribute
_tag = 'text:initial-creator'
fixed
instance-attribute
fixed = True
__init__
__init__(fixed: bool = False, **kwargs: Any) -> None
Initializes the VarInitialCreator element.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fixed
|
bool
|
If True, the field is not updated automatically. |
False
|
Source code in odfdo/variable.py
480 481 482 483 484 485 486 487 488 | |
VarKeywords
Bases: VarInitialCreator
A keywords field, “text:keywords”.
Displays the document’s keywords from its metadata.
Source code in odfdo/variable.py
608 609 610 611 612 613 614 | |
_tag
class-attribute
instance-attribute
_tag = 'text:keywords'
VarPageCount
Bases: Element
A page count field, “text:page-count”.
Displays the total number of pages in the document.
Source code in odfdo/variable.py
228 229 230 231 232 233 234 | |
_tag
class-attribute
instance-attribute
_tag = 'text:page-count'
VarPageNumber
Bases: Element
A page number field, “text:page-number”.
Displays the page number, which can be the current, previous, or next page number, with an optional adjustment.
Attributes:
| Name | Type | Description |
|---|---|---|
select_page |
str
|
Which page number to display (‘current’, ‘previous’, ‘next’). |
page_adjust |
str
|
A numerical value to add to or subtract from the page number. |
Methods:
| Name | Description |
|---|---|
__init__ |
Initializes the VarPageNumber element. |
Source code in odfdo/variable.py
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | |
_properties
class-attribute
instance-attribute
_properties = (
PropDef("select_page", "text:select-page"),
PropDef("page_adjust", "text:page-adjust"),
)
_tag
class-attribute
instance-attribute
_tag = 'text:page-number'
page_adjust
instance-attribute
page_adjust = page_adjust
select_page
instance-attribute
select_page = select_page
__init__
__init__(
select_page: str | None = None,
page_adjust: str | None = None,
**kwargs: Any,
) -> None
Initializes the VarPageNumber element.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
select_page
|
str | None
|
The page to select: ‘current’ (the default), ‘previous’, or ‘next’. |
None
|
page_adjust
|
str | None
|
A numerical value to add to or subtract from the selected page number. |
None
|
Source code in odfdo/variable.py
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | |
VarSet
Bases: ElementTyped
A variable setter, “text:variable-set”.
This element sets the value of a declared variable. It can optionally display the value at its position in the text.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The name of the variable to set. |
style |
str
|
The data style for formatting the displayed value. |
display |
str
|
Controls whether the value is displayed (‘none’ or omitted). |
Methods:
| Name | Description |
|---|---|
__init__ |
Initializes the VarSet element. |
set_value |
Sets the value of the variable. |
Source code in odfdo/variable.py
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 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | |
_properties
class-attribute
instance-attribute
_properties = (
PropDef("name", "text:name"),
PropDef("style", "style:data-style-name"),
PropDef("display", "text:display"),
)
_tag
class-attribute
instance-attribute
_tag = 'text:variable-set'
display
instance-attribute
display = 'none'
name
instance-attribute
name = name
style
instance-attribute
style = style
text
instance-attribute
text = text
__init__
__init__(
name: str | None = None,
value: Any = None,
value_type: str | None = None,
display: str | bool = False,
text: str | None = None,
style: str | None = None,
**kwargs: Any,
) -> None
Initializes the VarSet element.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str | None
|
The name of the variable to set. |
None
|
value
|
Any
|
The value to assign to the variable. |
None
|
value_type
|
str | None
|
The ODF value type. |
None
|
display
|
str | bool
|
If False or ‘none’, the value is not displayed. Otherwise, it is. Defaults to False. |
False
|
text
|
str | None
|
The textual representation of the value. |
None
|
style
|
str | None
|
The data style name for formatting. |
None
|
Source code in odfdo/variable.py
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 100 101 102 103 104 105 106 | |
set_value
set_value(value: Any) -> None
Sets the value of the variable.
This method updates the value and value type, preserving other attributes like name, style, and display setting.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Any
|
The new value for the variable. |
required |
Source code in odfdo/variable.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | |
VarSubject
Bases: VarInitialCreator
A subject field, “text:subject”.
Displays the document’s subject from its metadata.
Source code in odfdo/variable.py
596 597 598 599 600 601 602 | |
_tag
class-attribute
instance-attribute
_tag = 'text:subject'
VarTime
Bases: Element
A time field, “text:time”.
Displays a time, which can be fixed or automatically updated.
Attributes:
| Name | Type | Description |
|---|---|---|
time |
str
|
The time value in ISO 8601 format. |
fixed |
bool
|
If True, the time is not updated automatically. |
data_style |
str
|
The style for formatting the time. |
time_adjust |
str
|
A duration to add to or subtract from the time. |
Methods:
| Name | Description |
|---|---|
__init__ |
Initializes the VarTime element. |
Source code in odfdo/variable.py
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 | |
_properties
class-attribute
instance-attribute
_properties = (
PropDef("time", "text:time-value"),
PropDef("fixed", "text:fixed"),
PropDef("data_style", "style:data-style-name"),
PropDef("time_adjust", "text:time-adjust"),
)
_tag
class-attribute
instance-attribute
_tag = 'text:time'
data_style
instance-attribute
data_style = data_style
fixed
instance-attribute
fixed = True
text
instance-attribute
text = text
time
instance-attribute
time = encode(time)
time_adjust
instance-attribute
time_adjust = encode(time_adjust)
__init__
__init__(
time: datetime | time | None = None,
fixed: bool = False,
data_style: str | None = None,
text: str | None = None,
time_adjust: timedelta | None = None,
**kwargs: Any,
) -> None
Initializes the VarTime element.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time
|
datetime | time | None
|
The time value. Defaults to the current time. |
None
|
fixed
|
bool
|
If True, the time is not updated automatically. |
False
|
data_style
|
str | None
|
The style name for formatting. |
None
|
text
|
str | None
|
The textual representation of the time.
If not provided, it is generated from |
None
|
time_adjust
|
timedelta | None
|
A timedelta to adjust the time value. |
None
|
Source code in odfdo/variable.py
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 | |
VarTitle
Bases: VarInitialCreator
A title field, “text:title”.
Displays the document’s title from its metadata.
Source code in odfdo/variable.py
584 585 586 587 588 589 590 | |
_tag
class-attribute
instance-attribute
_tag = 'text:title'