|
4 | 4 | import types |
5 | 5 | import collections.abc |
6 | 6 | import copy |
| 7 | +import json |
7 | 8 |
|
8 | 9 | from .. import ( |
9 | 10 | _otio, |
|
14 | 15 | AnyVector, |
15 | 16 | PyAny |
16 | 17 | ) |
| 18 | +from .. _opentime import ( |
| 19 | + RationalTime, |
| 20 | + TimeRange, |
| 21 | + TimeTransform |
| 22 | +) |
17 | 23 |
|
18 | 24 |
|
19 | 25 | SUPPORTED_VALUE_TYPES = ( |
@@ -388,3 +394,57 @@ def __deepcopy__(self, *args, **kwargs): |
388 | 394 | @add_method(SerializableObject) |
389 | 395 | def __copy__(self, *args, **kwargs): |
390 | 396 | raise ValueError("SerializableObjects may not be shallow copied.") |
| 397 | + |
| 398 | + |
| 399 | +@add_method(AnyDictionary) |
| 400 | +def to_dict(self): |
| 401 | + """ |
| 402 | + Convert to a built-in dict. It will recursively convert all values |
| 403 | + to their corresponding python built-in types. |
| 404 | + """ |
| 405 | + return json.loads(_otio._serialize_json_to_string(_value_to_any(self), {}, 0)) |
| 406 | + |
| 407 | + |
| 408 | +@add_method(AnyVector) |
| 409 | +def to_list(self): |
| 410 | + """ |
| 411 | + Convert to a built-in list. It will recursively convert all values |
| 412 | + to their corresponding python built-in types. |
| 413 | + """ |
| 414 | + return json.loads(_otio._serialize_json_to_string(_value_to_any(self), {}, 0)) |
| 415 | + |
| 416 | + |
| 417 | +@add_method(SerializableObject) |
| 418 | +def to_dict(self): |
| 419 | + """ |
| 420 | + Convert to a built-in dict. It will recursively convert all values |
| 421 | + to their corresponding python built-in types. |
| 422 | + """ |
| 423 | + return json.loads(_otio._serialize_json_to_string(_value_to_any(self), {}, 0)) |
| 424 | + |
| 425 | + |
| 426 | +@add_method(RationalTime) |
| 427 | +def to_dict(self): |
| 428 | + """ |
| 429 | + Convert to a built-in dict. It will recursively convert all values |
| 430 | + to their corresponding python built-in types. |
| 431 | + """ |
| 432 | + return json.loads(_otio._serialize_json_to_string(_value_to_any(self), {}, 0)) |
| 433 | + |
| 434 | + |
| 435 | +@add_method(TimeRange) |
| 436 | +def to_dict(self): |
| 437 | + """ |
| 438 | + Convert to a built-in dict. It will recursively convert all values |
| 439 | + to their corresponding python built-in types. |
| 440 | + """ |
| 441 | + return json.loads(_otio._serialize_json_to_string(_value_to_any(self), {}, 0)) |
| 442 | + |
| 443 | + |
| 444 | +@add_method(TimeTransform) |
| 445 | +def to_dict(self): |
| 446 | + """ |
| 447 | + Convert to a built-in dict. It will recursively convert all values |
| 448 | + to their corresponding python built-in types. |
| 449 | + """ |
| 450 | + return json.loads(_otio._serialize_json_to_string(_value_to_any(self), {}, 0)) |
0 commit comments