Utilities¶
Utility functions and classes which are not specific to anything else in the codebase.
refreshed_property = property
module-attribute
¶
T = TypeVar('T')
module-attribute
¶
Params = ParamSpec('Params')
module-attribute
¶
ReturnType = TypeVar('ReturnType')
module-attribute
¶
TVPElementType = TypeVar('TVPElementType', bound=_TVPElement)
module-attribute
¶
RefreshedProperty
¶
Refreshable()
¶
Abstract class that denotes an object that have data that can be refreshed (a TVPaint project for example).
Source code in pytvpaint/utils.py
45 46 | |
Removable()
¶
Bases: pytvpaint.utils.Refreshable
Abstract class that denotes an object that can be removed from TVPaint (a Layer for example).
Source code in pytvpaint/utils.py
57 58 59 | |
is_removed: bool
property
¶
Checks if the object is removed by trying to refresh its data.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
whether if it was removed or not |
refresh_on_call = True
instance-attribute
¶
refresh() -> None
¶
Does a refresh of the object data.
Raises:
| Type | Description |
|---|---|
ValueError
|
if the object has been mark removed |
Source code in pytvpaint/utils.py
70 71 72 73 74 75 76 77 | |
remove() -> None
abstractmethod
¶
Removes the object in TVPaint.
Source code in pytvpaint/utils.py
93 94 95 96 | |
mark_removed() -> None
¶
Marks the object as removed and is therefor not usable.
Source code in pytvpaint/utils.py
98 99 100 | |
Renderable()
¶
CanMakeCurrent
¶
HasCurrentFrame
¶
Bases: typing_extensions.Protocol
Class that has a current frame property.
current_frame: int
property
writable
¶
The current frame, clip or project.
get_unique_name(names: Iterable[str], stub: str) -> str
¶
Get a unique name from a list of names and a stub prefix. It does auto increment it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
names
|
collections.abc.Iterable[str]
|
existing names |
required |
stub
|
str
|
the base name |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the stub is empty |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
a unique name with the stub prefix |
Source code in pytvpaint/utils.py
227 228 229 230 231 232 233 234 235 236 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 | |
position_generator(fn: Callable[[int], T], stop_when: type[GeorgeError] = GeorgeError) -> Iterator[T]
¶
Utility generator that yields the result of a function according to a position.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fn
|
typing.Callable[[int], pytvpaint.utils.T]
|
the function to run at each iteration |
required |
stop_when
|
Type[pytvpaint.george.exceptions.GeorgeError]
|
exception at which we stop. Defaults to GeorgeError. |
pytvpaint.george.exceptions.GeorgeError
|
Yields:
| Type | Description |
|---|---|
pytvpaint.utils.T
|
Iterator[T]: a generator of the resulting values |
Source code in pytvpaint/utils.py
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 | |
set_as_current(func: Callable[Params, ReturnType]) -> Callable[Params, ReturnType]
¶
Decorator to apply on object methods.
Sets the current TVPaint object as 'current'. Useful when George functions only apply on the current project, clip, layer or scene.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
typing.Callable[pytvpaint.utils.Params, pytvpaint.utils.ReturnType]
|
the method apply on |
required |
Returns:
| Type | Description |
|---|---|
typing.Callable[pytvpaint.utils.Params, pytvpaint.utils.ReturnType]
|
Callable[Params, ReturnType]: the wrapped method |
Source code in pytvpaint/utils.py
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 | |
render_context(alpha_mode: george.AlphaSaveMode | None = None, background_mode: george.BackgroundMode | None = None, save_format: george.SaveFormat | None = None, format_opts: list[str] | None = None, layer_selection: list[Layer] | None = None) -> Generator[None, None, None]
¶
Context used to do renders in TVPaint.
It does the following things:
- Set the alpha mode and save format (with custom options)
- Hide / Show the given layers (some render functions only render by visibility)
- Restore the previous values after rendering
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
alpha_mode
|
pytvpaint.george.AlphaSaveMode | None
|
the render alpha save mode |
None
|
save_format
|
pytvpaint.george.SaveFormat | None
|
the render format to use. Defaults to None. |
None
|
background_mode
|
pytvpaint.george.BackgroundMode | None
|
the render background mode |
None
|
format_opts
|
list[str] | None
|
the custom format options as strings. Defaults to None. |
None
|
layer_selection
|
list[pytvpaint.layer.Layer] | None
|
the layers to render. Defaults to None. |
None
|
Source code in pytvpaint/utils.py
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 361 362 363 364 365 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 | |
restore_current_frame(tvp_element: HasCurrentFrame, frame: int) -> Generator[None, None, None]
¶
Context that temporarily changes the current frame to the one provided and restores it when done.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tvp_element
|
pytvpaint.utils.HasCurrentFrame
|
clip to change |
required |
frame
|
int
|
frame to set. Defaults to None. |
required |
Source code in pytvpaint/utils.py
405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 | |
get_tvp_element(tvp_elements: Iterator[TVPElementType], by_id: int | str | None = None, by_name: str | None = None, by_regex: re.Pattern[str] | None = None, by_path: str | Path | None = None) -> TVPElementType | None
¶
Search for a TVPaint element by attributes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tvp_elements
|
collections.abc.Iterator[pytvpaint.utils.TVPElementType]
|
a collection of TVPaint objects |
required |
by_id
|
int | str | None
|
search by id. Defaults to None. |
None
|
by_name
|
str | None
|
search by name, search is case-insensitive. Defaults to None. |
None
|
by_regex
|
re.Pattern[str] | None
|
search by name using a compiled regex, case-sensitivity is left to the regex. Defaults to None. |
None
|
by_path
|
str | pathlib.Path | None
|
search by path. Defaults to None. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
if none of the search arguments where provided |
Returns:
| Type | Description |
|---|---|
pytvpaint.utils.TVPElementType | None
|
_TVPElementType | None: the searched element or None if search was unsuccessful |
Source code in pytvpaint/utils.py
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 462 463 464 465 466 467 468 469 470 471 472 473 | |
handle_output_range(output_path: Path | str | FileSequence, default_start: int, default_end: int, start: int | None = None, end: int | None = None) -> tuple[FileSequence, int, int, bool, bool]
¶
Handle the different options for output paths and range.
Whether the user provides a range (start-end) or a frame set or a filesequence with a range or not, this functions ensures we always end up with a valid range to render
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_path
|
pathlib.Path | str | fileseq.filesequence.FileSequence
|
user provided output path |
required |
default_start
|
int
|
the default start to use if none provided or found in the file sequence object |
required |
default_end
|
int
|
the default end to use if none provided or found in the file sequence object |
required |
start
|
int | None
|
user provided start frame or None |
None
|
end
|
int | None
|
user provided end frame or None |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
file_sequence |
fileseq.filesequence.FileSequence
|
output path as a FileSequence object |
start |
int
|
computed start frame |
end |
int
|
computed end frame |
is_sequence |
bool
|
whether the output is a sequence or not |
is_image |
bool
|
whether the output is an image or not (a movie) |
Source code in pytvpaint/utils.py
476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 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 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 | |