Skip to content

Scene class

Scene class.

Scene(scene_id: int, project: Project)

Bases: pytvpaint.utils.Removable

A Scene is a collection of clips. A Scene is parented to a project.

Source code in pytvpaint/scene.py
20
21
22
23
def __init__(self, scene_id: int, project: Project) -> None:
    super().__init__()
    self._id: int = scene_id
    self._project = project

is_current: bool property

Returns True if the scene is the current one.

id: int property

The scene id.

project: Project property

The scene's project.

position: int property writable

The scene's position in the project.

Raises:

Type Description
ValueError

if scene cannot be found in the project

clip_ids: Iterator[int] property

Returns an Returns an iterator over the clip ids.

clips: Iterator[Clip] property

Yields the scene clips.

refresh_on_call = True instance-attribute

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

current_scene_id() -> int staticmethod

Returns the current scene id (the current clip's scene).

Source code in pytvpaint/scene.py
35
36
37
38
@staticmethod
def current_scene_id() -> int:
    """Returns the current scene id (the current clip's scene)."""
    return george.tv_scene_current_id()

current_scene() -> Scene staticmethod

Returns the current scene of the current project.

Source code in pytvpaint/scene.py
40
41
42
43
44
45
46
@staticmethod
def current_scene() -> Scene:
    """Returns the current scene of the current project."""
    return Scene(
        scene_id=george.tv_scene_current_id(),
        project=Project.current_project(),
    )

new(project: Project | None = None, clips: list[str] | None = None) -> Scene classmethod

Creates a new scene in the provided project.

Parameters:

Name Type Description Default
project pytvpaint.project.Project | None

parent project

None
clips list[str] | None

list of clip names to create alongside new scene

None

Returns:

Type Description
pytvpaint.scene.Scene

new scene instance

Source code in pytvpaint/scene.py
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
@classmethod
def new(cls, project: Project | None = None, clips: list[str] | None = None) -> Scene:
    """Creates a new scene in the provided project.

    Args:
        project: parent project
        clips: list of clip names to create alongside new scene

    Returns:
        new scene instance
    """
    project = project or Project.current_project()
    project.make_current()

    # TODO commenting this for now until george.tv_scene_create is fixed by TVP devs
    # if not clips or george.is_tvp_version_below_12():
    #     george.tv_scene_new() # noqa: ERA001
    #     new_scene = cls.current_scene() # noqa: ERA001
    #
    #     if clips and george.is_tvp_version_below_12():
    #         for clip_name in clips:
    #             new_scene.add_clip(clip_name) # noqa: ERA001
    #
    #     return new_scene # noqa: ERA001
    #
    # # if here, then we are using tvp 12 or superior
    # scene_id = george.tv_scene_create(clips) # noqa: ERA001
    # return project.get_scene(by_id=scene_id) # noqa: ERA001

    george.tv_scene_new()
    new_scene = cls.current_scene()

    if clips and george.is_tvp_version_below_12():
        for clip_name in clips:
            new_scene.add_clip(clip_name)

    return new_scene

make_current() -> None

Make this scene the current one.

Source code in pytvpaint/scene.py
86
87
88
89
90
91
92
93
def make_current(self) -> None:
    """Make this scene the current one."""
    if self.is_current:
        return

    # In order to select the scene, we select any child clip inside of it
    first_clip_id = george.tv_clip_enum_id(self.id, 0)
    george.tv_clip_select(first_clip_id)

get_clip(by_id: int | None = None, by_name: str | None = None, by_regex: re.Pattern[str] | None = None) -> Clip | None

Find a clip by id or by name.

Parameters:

Name Type Description Default
by_id int | 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

Raises:

Type Description
ValueError

if none of the search arguments where provided

Returns:

Type Description
pytvpaint.clip.Clip | None

Clip | None: the searched element or None if search was unsuccessful

Source code in pytvpaint/scene.py
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
def get_clip(
    self,
    by_id: int | None = None,
    by_name: str | None = None,
    by_regex: re.Pattern[str] | None = None,
) -> Clip | None:
    """Find a clip by id or by name.

    Args:
        by_id: search by id. Defaults to None.
        by_name: search by name, search is case-insensitive. Defaults to None.
        by_regex: search by name using a compiled regex, case-sensitivity is left to the regex. Defaults to None.

    Raises:
        ValueError: if none of the search arguments where provided

    Returns:
        Clip | None: the searched element or None if search was unsuccessful
    """
    return utils.get_tvp_element(self.clips, by_id=by_id, by_name=by_name, by_regex=by_regex)

add_clip(clip_name: str) -> Clip

Adds a new clip to the scene.

Source code in pytvpaint/scene.py
160
161
162
163
164
@set_as_current
def add_clip(self, clip_name: str) -> Clip:
    """Adds a new clip to the scene."""
    self.make_current()
    return Clip.new(name=clip_name, project=self.project)

duplicate() -> Scene

Duplicate the scene and return it.

Source code in pytvpaint/scene.py
166
167
168
169
170
171
172
def duplicate(self) -> Scene:
    """Duplicate the scene and return it."""
    self.project.make_current()
    george.tv_scene_duplicate(self.id)
    dup_pos = self.position + 1
    dup_id = george.tv_scene_enum_id(dup_pos)
    return Scene(dup_id, self.project)

split() -> list[Scene]

Duplicate the scene and return it.

Source code in pytvpaint/scene.py
174
175
176
177
178
179
180
181
182
183
184
185
186
187
@george.min_version_compatible(min_version="12")
def split(self) -> list[Scene]:
    """Duplicate the scene and return it."""
    self.project.make_current()
    clip_ids = george.tv_scene_split(self.id)

    new_scenes = []
    for clip_id in clip_ids:
        clip = self.project.get_clip(by_id=clip_id)
        if not clip:
            continue

        new_scenes.append(clip.scene)
    return new_scenes

remove() -> None

Remove the scene and all the clips inside.

Warning

All Clip instances will be invalid after removing the scene. There's no protection mechanism to prevent accessing clip data that doesn't exist anymore.

Source code in pytvpaint/scene.py
189
190
191
192
193
194
195
196
197
def remove(self) -> None:
    """Remove the scene and all the clips inside.

    Warning:
        All `Clip` instances will be invalid after removing the scene.
        There's no protection mechanism to prevent accessing clip data that doesn't exist anymore.
    """
    george.tv_scene_close(self._id)
    self.mark_removed()

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
def refresh(self) -> None:
    """Does a refresh of the object data.

    Raises:
        ValueError: if the object has been mark removed
    """
    if self._is_removed:
        raise ValueError(f"{self.__class__.__name__} has been removed!")

mark_removed() -> None

Marks the object as removed and is therefor not usable.

Source code in pytvpaint/utils.py
 98
 99
100
def mark_removed(self) -> None:
    """Marks the object as removed and is therefor not usable."""
    self._is_removed = True