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 inside a project.

Source code in pytvpaint/scene.py
19
20
21
22
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 iterator over the clip ids.

clips: Iterator[Clip] property

Yields the scene clips.

current_scene_id() -> int staticmethod

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

Source code in pytvpaint/scene.py
34
35
36
37
@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
39
40
41
42
43
44
45
@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) -> Scene classmethod

Creates a new scene in the provided project.

Source code in pytvpaint/scene.py
47
48
49
50
51
52
53
@classmethod
def new(cls, project: Project | None = None) -> Scene:
    """Creates a new scene in the provided project."""
    project = project or Project.current_project()
    project.make_current()
    george.tv_scene_new()
    return cls.current_scene()

make_current() -> None

Make this scene the current one.

Source code in pytvpaint/scene.py
55
56
57
58
59
60
61
62
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) -> Clip | None

Find a clip by id or by name.

Source code in pytvpaint/scene.py
110
111
112
113
114
115
116
117
118
119
120
def get_clip(
    self,
    by_id: int | None = None,
    by_name: str | None = None,
) -> Clip | None:
    """Find a clip by id or by name."""
    for clip in self.clips:
        if (by_id and clip.id == by_id) or (by_name and clip.name == by_name):
            return clip

    return None

add_clip(clip_name: str) -> Clip

Adds a new clip to the scene.

Source code in pytvpaint/scene.py
122
123
124
125
126
@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
128
129
130
131
132
133
134
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)

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
136
137
138
139
140
141
142
143
144
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()