Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
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
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 animation_funcs(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 @@ -272,6 +272,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 animation_funcs(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 @@ -393,6 +398,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 add_graphic(self, graphic: Graphic, center: bool = True):
"""
Add a Graphic to the scene
Expand Down
Loading