From 03446c192899507706ad3ad7fbc018a51e83436d Mon Sep 17 00:00:00 2001 From: clewis7 Date: Sat, 6 Sep 2025 12:11:47 -0400 Subject: [PATCH 1/5] add animation func getter and clear() method --- fastplotlib/layouts/_figure.py | 12 ++++++++++++ fastplotlib/layouts/_plot_area.py | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/fastplotlib/layouts/_figure.py b/fastplotlib/layouts/_figure.py index a4e219757..c6f499f98 100644 --- a/fastplotlib/layouts/_figure.py +++ b/fastplotlib/layouts/_figure.py @@ -543,6 +543,10 @@ def show_tooltips(self) -> bool: """show/hide tooltips for all graphics""" return self._show_tooltips + @property + def animation_funcs(self) -> list[callable]: + return self._animate_funcs_pre + self._animate_funcs_post + @show_tooltips.setter def show_tooltips(self, val: bool): self._show_tooltips = val @@ -765,6 +769,14 @@ def remove_animation(self, func): if func in self._animate_funcs_post: self._animate_funcs_post.remove(func) + def clear_animations(self): + """Removes all animation functions from both pre and post render.""" + 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) + def clear(self): """Clear all Subplots""" for subplot in self: diff --git a/fastplotlib/layouts/_plot_area.py b/fastplotlib/layouts/_plot_area.py index 2542fc215..b848a8369 100644 --- a/fastplotlib/layouts/_plot_area.py +++ b/fastplotlib/layouts/_plot_area.py @@ -272,6 +272,10 @@ 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) -> list[callable]: + return self._animate_funcs_pre + self._animate_funcs_post + def map_screen_to_world( self, pos: tuple[float, float] | pygfx.PointerEvent, allow_outside: bool = False ) -> np.ndarray | None: @@ -393,6 +397,14 @@ def remove_animation(self, func): if func in self._animate_funcs_post: self._animate_funcs_post.remove(func) + def clear_animations(self): + """Removes all animation functions from both pre and post render.""" + 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) + def add_graphic(self, graphic: Graphic, center: bool = True): """ Add a Graphic to the scene From f96b0637870378395c63010cca8f754f340795fe Mon Sep 17 00:00:00 2001 From: clewis7 Date: Mon, 8 Sep 2025 16:15:15 -0400 Subject: [PATCH 2/5] requested changes --- fastplotlib/layouts/_figure.py | 40 ++++++++++++++++++++++++------- fastplotlib/layouts/_plot_area.py | 40 ++++++++++++++++++++++++------- 2 files changed, 64 insertions(+), 16 deletions(-) diff --git a/fastplotlib/layouts/_figure.py b/fastplotlib/layouts/_figure.py index c6f499f98..70fd6a34c 100644 --- a/fastplotlib/layouts/_figure.py +++ b/fastplotlib/layouts/_figure.py @@ -544,8 +544,9 @@ def show_tooltips(self) -> bool: return self._show_tooltips @property - def animation_funcs(self) -> list[callable]: - return self._animate_funcs_pre + self._animate_funcs_post + 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): @@ -769,13 +770,36 @@ def remove_animation(self, func): if func in self._animate_funcs_post: self._animate_funcs_post.remove(func) - def clear_animations(self): - """Removes all animation functions from both pre and post render.""" - for func in self._animate_funcs_pre: - self._animate_funcs_pre.remove(func) + def clear_animations(self, type: str = None): + """ + Remove animation functions. - for func in self._animate_funcs_post: - self._animate_funcs_post.remove(func) + Parameters + ---------- + type: str, default ``None`` + The type of animation functions to clear. One of 'pre' or 'post'. If `None`, removes all animation + functions. + """ + if type 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 type == "pre": + # only pre + for func in self._animate_funcs_pre: + self._animate_funcs_pre.remove(func) + elif type == "post": + # only post + for func in self._animate_funcs_post: + self._animate_funcs_post.remove(func) + else: + raise ValueError( + f"Animation type: {type} must be one of 'pre' or 'post'. To remove all animation " + f"functions, pass `type=None`" + ) def clear(self): """Clear all Subplots""" diff --git a/fastplotlib/layouts/_plot_area.py b/fastplotlib/layouts/_plot_area.py index b848a8369..59637574b 100644 --- a/fastplotlib/layouts/_plot_area.py +++ b/fastplotlib/layouts/_plot_area.py @@ -273,8 +273,9 @@ def background_color(self, colors: str | tuple[float]): self._background_material.set_colors(*colors) @property - def animation_funcs(self) -> list[callable]: - return self._animate_funcs_pre + self._animate_funcs_post + 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 @@ -397,13 +398,36 @@ def remove_animation(self, func): if func in self._animate_funcs_post: self._animate_funcs_post.remove(func) - def clear_animations(self): - """Removes all animation functions from both pre and post render.""" - for func in self._animate_funcs_pre: - self._animate_funcs_pre.remove(func) + def clear_animations(self, type: str = None): + """ + Remove animation functions. - for func in self._animate_funcs_post: - self._animate_funcs_post.remove(func) + Parameters + ---------- + type: str, default ``None`` + The type of animation functions to clear. One of 'pre' or 'post'. If `None`, removes all animation + functions. + """ + if type 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 type == "pre": + # only pre + for func in self._animate_funcs_pre: + self._animate_funcs_pre.remove(func) + elif type == "post": + # only post + for func in self._animate_funcs_post: + self._animate_funcs_post.remove(func) + else: + raise ValueError( + f"Animation type: {type} 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): """ From 87a1d8a346ceb99685e2341b5969605dbba134c5 Mon Sep 17 00:00:00 2001 From: clewis7 Date: Tue, 9 Sep 2025 08:38:32 -0400 Subject: [PATCH 3/5] fix kwarg name --- fastplotlib/layouts/_figure.py | 12 ++++++------ fastplotlib/layouts/_plot_area.py | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/fastplotlib/layouts/_figure.py b/fastplotlib/layouts/_figure.py index 70fd6a34c..313ab2bf6 100644 --- a/fastplotlib/layouts/_figure.py +++ b/fastplotlib/layouts/_figure.py @@ -770,34 +770,34 @@ def remove_animation(self, func): if func in self._animate_funcs_post: self._animate_funcs_post.remove(func) - def clear_animations(self, type: str = None): + def clear_animations(self, removal: str = None): """ Remove animation functions. Parameters ---------- - type: str, default ``None`` + removal: str, default ``None`` The type of animation functions to clear. One of 'pre' or 'post'. If `None`, removes all animation functions. """ - if type is None: + 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 type == "pre": + elif removal == "pre": # only pre for func in self._animate_funcs_pre: self._animate_funcs_pre.remove(func) - elif type == "post": + elif removal == "post": # only post for func in self._animate_funcs_post: self._animate_funcs_post.remove(func) else: raise ValueError( - f"Animation type: {type} must be one of 'pre' or 'post'. To remove all animation " + f"Animation type: {removal} must be one of 'pre' or 'post'. To remove all animation " f"functions, pass `type=None`" ) diff --git a/fastplotlib/layouts/_plot_area.py b/fastplotlib/layouts/_plot_area.py index 59637574b..7ca5a81a7 100644 --- a/fastplotlib/layouts/_plot_area.py +++ b/fastplotlib/layouts/_plot_area.py @@ -398,34 +398,34 @@ def remove_animation(self, func): if func in self._animate_funcs_post: self._animate_funcs_post.remove(func) - def clear_animations(self, type: str = None): + def clear_animations(self, removal: str = None): """ Remove animation functions. Parameters ---------- - type: str, default ``None`` + removal: str, default ``None`` The type of animation functions to clear. One of 'pre' or 'post'. If `None`, removes all animation functions. """ - if type is None: + 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 type == "pre": + elif removal == "pre": # only pre for func in self._animate_funcs_pre: self._animate_funcs_pre.remove(func) - elif type == "post": + elif removal == "post": # only post for func in self._animate_funcs_post: self._animate_funcs_post.remove(func) else: raise ValueError( - f"Animation type: {type} must be one of 'pre' or 'post'. To remove all animation " + f"Animation type: {removal} must be one of 'pre' or 'post'. To remove all animation " f"functions, pass `type=None`" ) From dcd5cb2531bda836c5ac18f344b63e66ab44f1cf Mon Sep 17 00:00:00 2001 From: clewis7 Date: Tue, 21 Oct 2025 08:46:12 -0400 Subject: [PATCH 4/5] requested changes --- fastplotlib/layouts/_figure.py | 2 +- fastplotlib/layouts/_plot_area.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/fastplotlib/layouts/_figure.py b/fastplotlib/layouts/_figure.py index 313ab2bf6..8fd5dc666 100644 --- a/fastplotlib/layouts/_figure.py +++ b/fastplotlib/layouts/_figure.py @@ -544,7 +544,7 @@ def show_tooltips(self) -> bool: return self._show_tooltips @property - def animation_funcs(self) -> dict[str, list[callable]]: + 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} diff --git a/fastplotlib/layouts/_plot_area.py b/fastplotlib/layouts/_plot_area.py index c97123b21..3c5027caf 100644 --- a/fastplotlib/layouts/_plot_area.py +++ b/fastplotlib/layouts/_plot_area.py @@ -275,7 +275,7 @@ def background_color(self, colors: str | tuple[float]): self._background_material.set_colors(*colors) @property - def animation_funcs(self) -> dict[str, list[callable]]: + 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} From 31d0c01b424381ad6eaa51c7cb92e60d30d88ed2 Mon Sep 17 00:00:00 2001 From: clewis7 Date: Wed, 22 Oct 2025 08:56:31 -0400 Subject: [PATCH 5/5] update api docs --- docs/source/api/layouts/figure.rst | 2 ++ docs/source/api/layouts/imgui_figure.rst | 2 ++ docs/source/api/layouts/subplot.rst | 2 ++ 3 files changed, 6 insertions(+) diff --git a/docs/source/api/layouts/figure.rst b/docs/source/api/layouts/figure.rst index d191fe8ce..e306710be 100644 --- a/docs/source/api/layouts/figure.rst +++ b/docs/source/api/layouts/figure.rst @@ -20,6 +20,7 @@ Properties .. autosummary:: :toctree: Figure_api + Figure.animations Figure.cameras Figure.canvas Figure.controllers @@ -38,6 +39,7 @@ Methods Figure.add_animations Figure.add_subplot Figure.clear + Figure.clear_animations Figure.close Figure.export Figure.export_numpy diff --git a/docs/source/api/layouts/imgui_figure.rst b/docs/source/api/layouts/imgui_figure.rst index e1922a9f4..959a98743 100644 --- a/docs/source/api/layouts/imgui_figure.rst +++ b/docs/source/api/layouts/imgui_figure.rst @@ -20,6 +20,7 @@ Properties .. autosummary:: :toctree: ImguiFigure_api + ImguiFigure.animations ImguiFigure.cameras ImguiFigure.canvas ImguiFigure.controllers @@ -42,6 +43,7 @@ Methods ImguiFigure.add_gui ImguiFigure.add_subplot ImguiFigure.clear + ImguiFigure.clear_animations ImguiFigure.close ImguiFigure.export ImguiFigure.export_numpy diff --git a/docs/source/api/layouts/subplot.rst b/docs/source/api/layouts/subplot.rst index bc2b3aa29..0183c7e63 100644 --- a/docs/source/api/layouts/subplot.rst +++ b/docs/source/api/layouts/subplot.rst @@ -20,6 +20,7 @@ Properties .. autosummary:: :toctree: Subplot_api + Subplot.animations Subplot.axes Subplot.background_color Subplot.camera @@ -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