Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/source/api/layouts/figure.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Properties
.. autosummary::
:toctree: Figure_api

Figure.animations
Figure.cameras
Figure.canvas
Figure.controllers
Expand All @@ -38,6 +39,7 @@ Methods
Figure.add_animations
Figure.add_subplot
Figure.clear
Figure.clear_animations
Figure.close
Figure.export
Figure.export_numpy
Expand Down
2 changes: 2 additions & 0 deletions docs/source/api/layouts/imgui_figure.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Properties
.. autosummary::
:toctree: ImguiFigure_api

ImguiFigure.animations
ImguiFigure.cameras
ImguiFigure.canvas
ImguiFigure.controllers
Expand All @@ -42,6 +43,7 @@ Methods
ImguiFigure.add_gui
ImguiFigure.add_subplot
ImguiFigure.clear
ImguiFigure.clear_animations
ImguiFigure.close
ImguiFigure.export
ImguiFigure.export_numpy
Expand Down
2 changes: 2 additions & 0 deletions docs/source/api/layouts/subplot.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Properties
.. autosummary::
:toctree: Subplot_api

Subplot.animations
Subplot.axes
Subplot.background_color
Subplot.camera
Expand Down Expand Up @@ -57,6 +58,7 @@ Methods
Subplot.center_graphic
Subplot.center_scene
Subplot.clear
Subplot.clear_animations
Subplot.delete_graphic
Subplot.get_figure
Subplot.insert_graphic
Expand Down
36 changes: 36 additions & 0 deletions fastplotlib/layouts/_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,11 @@ def show_tooltips(self) -> bool:
"""show/hide tooltips for all graphics"""
return self._show_tooltips

@property
def animations(self) -> dict[str, list[callable]]:
"""Returns a dictionary of 'pre' and 'post' animation functions."""
return {"pre": self._animate_funcs_pre, "post": self._animate_funcs_post}

@show_tooltips.setter
def show_tooltips(self, val: bool):
self._show_tooltips = val
Expand Down Expand Up @@ -765,6 +770,37 @@ def remove_animation(self, func):
if func in self._animate_funcs_post:
self._animate_funcs_post.remove(func)

def clear_animations(self, removal: str = None):
"""
Remove animation functions.

Parameters
----------
removal: str, default ``None``
The type of animation functions to clear. One of 'pre' or 'post'. If `None`, removes all animation
functions.
"""
if removal is None:
# remove all
for func in self._animate_funcs_pre:
self._animate_funcs_pre.remove(func)

for func in self._animate_funcs_post:
self._animate_funcs_post.remove(func)
elif removal == "pre":
# only pre
for func in self._animate_funcs_pre:
self._animate_funcs_pre.remove(func)
elif removal == "post":
# only post
for func in self._animate_funcs_post:
self._animate_funcs_post.remove(func)
else:
raise ValueError(
f"Animation type: {removal} must be one of 'pre' or 'post'. To remove all animation "
f"functions, pass `type=None`"
)

def clear(self):
"""Clear all Subplots"""
for subplot in self:
Expand Down
36 changes: 36 additions & 0 deletions fastplotlib/layouts/_plot_area.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,11 @@ def background_color(self, colors: str | tuple[float]):
"""1, 2, or 4 colors, each color must be acceptable by pygfx.Color"""
self._background_material.set_colors(*colors)

@property
def animations(self) -> dict[str, list[callable]]:
"""Returns a dictionary of 'pre' and 'post' animation functions."""
return {"pre": self._animate_funcs_pre, "post": self._animate_funcs_post}

def map_screen_to_world(
self, pos: tuple[float, float] | pygfx.PointerEvent, allow_outside: bool = False
) -> np.ndarray | None:
Expand Down Expand Up @@ -395,6 +400,37 @@ def remove_animation(self, func):
if func in self._animate_funcs_post:
self._animate_funcs_post.remove(func)

def clear_animations(self, removal: str = None):
"""
Remove animation functions.

Parameters
----------
removal: str, default ``None``
The type of animation functions to clear. One of 'pre' or 'post'. If `None`, removes all animation
functions.
"""
if removal is None:
# remove all
for func in self._animate_funcs_pre:
self._animate_funcs_pre.remove(func)

for func in self._animate_funcs_post:
self._animate_funcs_post.remove(func)
elif removal == "pre":
# only pre
for func in self._animate_funcs_pre:
self._animate_funcs_pre.remove(func)
elif removal == "post":
# only post
for func in self._animate_funcs_post:
self._animate_funcs_post.remove(func)
else:
raise ValueError(
f"Animation type: {removal} must be one of 'pre' or 'post'. To remove all animation "
f"functions, pass `type=None`"
)

def _sort_images_by_depth(self):
"""
In general, we want to avoid setting the offset of a graphic, because the
Expand Down