Utilities¶
Utility functions and classes which are not specific to anything else in the codebase.
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
51 52 |
|
refresh() -> None
abstractmethod
¶
Refreshes the object data.
Source code in pytvpaint/utils.py
54 55 56 57 |
|
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
63 64 65 |
|
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() -> 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
74 75 76 77 78 79 80 81 |
|
remove() -> None
abstractmethod
¶
Removes the object in TVPaint.
Source code in pytvpaint/utils.py
96 97 98 99 |
|
mark_removed() -> None
¶
Marks the object as removed and is therefor not usable.
Source code in pytvpaint/utils.py
101 102 103 |
|
Renderable()
¶
CanMakeCurrent
¶
Bases: typing_extensions.Protocol
Describes an object that can do make_current
and has an id.
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
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
|
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]: an generator of the resulting values |
Source code in pytvpaint/utils.py
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
|
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
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 |
|
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
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 361 362 363 364 365 366 367 368 369 370 371 372 373 |
|
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
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 |
|
get_tvp_element(tvp_elements: Iterator[TVPElementType], by_id: int | str | None = None, by_name: 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_path |
str | pathlib.Path | None
|
search by path. Defaults to None. |
None
|
Raises:
Type | Description |
---|---|
ValueError
|
if bad arguments were given |
Returns:
Type | Description |
---|---|
pytvpaint.utils.TVPElementType | None
|
TVPElementType | None: the found element |
Source code in pytvpaint/utils.py
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 |
|
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 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
457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 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 |
|