diff --git a/fury/animation/animation.py b/fury/animation/animation.py index f2fa56bb9..d72fb6387 100644 --- a/fury/animation/animation.py +++ b/fury/animation/animation.py @@ -13,6 +13,7 @@ spline_interpolator, step_interpolator, ) +from fury.decorators import warn_on_args_to_kwargs from fury.lib import Actor, Camera, Transform @@ -42,7 +43,8 @@ class Animation: """ - def __init__(self, actors=None, length=None, loop=True, motion_path_res=None): + @warn_on_args_to_kwargs() + def __init__(self, *, actors=None, length=None, loop=True, motion_path_res=None): super().__init__() self._data = defaultdict(dict) self._animations = [] @@ -191,7 +193,8 @@ def _get_attribute_data(self, attrib): } return data.get(attrib) - def get_keyframes(self, attrib=None): + @warn_on_args_to_kwargs() + def get_keyframes(self, *, attrib=None): """Get a keyframe for a specific or all attributes. Parameters @@ -209,8 +212,9 @@ def get_keyframes(self, attrib=None): } return data.get(attrib, {}).get("keyframes", {}) + @warn_on_args_to_kwargs() def set_keyframe( - self, attrib, timestamp, value, update_interpolator=True, **kwargs + self, attrib, timestamp, value, *, update_interpolator=True, **kwargs ): """Set a keyframe for a certain attribute. @@ -263,7 +267,7 @@ def set_keyframe( self._timeline.update_duration() else: self.update_duration() - self.update_animation(0) + self.update_animation(time=0) self.update_motion_path() def set_keyframes(self, attrib, keyframes): @@ -359,7 +363,8 @@ def _handle_scene_event(self, timestamp): self._scene.rm(*self._actors) self._added_to_scene = False - def set_interpolator(self, attrib, interpolator, is_evaluator=False, **kwargs): + @warn_on_args_to_kwargs() + def set_interpolator(self, attrib, interpolator, *, is_evaluator=False, **kwargs): """Set keyframes interpolator for a certain property Parameters @@ -437,7 +442,8 @@ def is_interpolatable(self, attrib): data = self._data return bool(data.get(attrib, {}).get("interpolator", {}).get("func")) - def set_position_interpolator(self, interpolator, is_evaluator=False, **kwargs): + @warn_on_args_to_kwargs() + def set_position_interpolator(self, interpolator, *, is_evaluator=False, **kwargs): """Set the position interpolator. Parameters @@ -464,7 +470,8 @@ def set_position_interpolator(self, interpolator, is_evaluator=False, **kwargs): "position", interpolator, is_evaluator=is_evaluator, **kwargs ) - def set_scale_interpolator(self, interpolator, is_evaluator=False): + @warn_on_args_to_kwargs() + def set_scale_interpolator(self, interpolator, *, is_evaluator=False): """Set the scale interpolator. Parameters @@ -483,7 +490,8 @@ def set_scale_interpolator(self, interpolator, is_evaluator=False): """ self.set_interpolator("scale", interpolator, is_evaluator=is_evaluator) - def set_rotation_interpolator(self, interpolator, is_evaluator=False): + @warn_on_args_to_kwargs() + def set_rotation_interpolator(self, interpolator, *, is_evaluator=False): """Set the rotation interpolator . Parameters @@ -502,7 +510,8 @@ def set_rotation_interpolator(self, interpolator, is_evaluator=False): """ self.set_interpolator("rotation", interpolator, is_evaluator=is_evaluator) - def set_color_interpolator(self, interpolator, is_evaluator=False): + @warn_on_args_to_kwargs() + def set_color_interpolator(self, interpolator, *, is_evaluator=False): """Set the color interpolator. Parameters @@ -521,7 +530,8 @@ def set_color_interpolator(self, interpolator, is_evaluator=False): """ self.set_interpolator("color", interpolator, is_evaluator=is_evaluator) - def set_opacity_interpolator(self, interpolator, is_evaluator=False): + @warn_on_args_to_kwargs() + def set_opacity_interpolator(self, interpolator, *, is_evaluator=False): """Set the opacity interpolator. Parameters @@ -899,7 +909,8 @@ def add_child_animation(self, animation): self._animations.append(animation) self.update_duration() - def add_actor(self, actor, static=False): + @warn_on_args_to_kwargs() + def add_actor(self, actor, *, static=False): """Add an actor or list of actors to the Animation. Parameters @@ -1094,7 +1105,8 @@ def add_update_callback(self, callback, prop=None): attrib = self._get_attribute_data(prop) attrib.get("callbacks", []).append(callback) - def update_animation(self, time=None): + @warn_on_args_to_kwargs() + def update_animation(self, *, time=None): """Update the animation. Update the animation at a certain time. This will make sure all @@ -1168,7 +1180,7 @@ def update_animation(self, time=None): [callback(time) for callback in self._general_callbacks] # Also update all child Animations. - [animation.update_animation(time) for animation in self._animations] + [animation.update_animation(time=time) for animation in self._animations] if self._scene and not has_handler: self._scene.reset_clipping_range() @@ -1184,7 +1196,7 @@ def add_to_scene(self, scene): self._scene = scene self._added_to_scene = True self._start_time = perf_counter() - self.update_animation(0) + self.update_animation(time=0) def remove_from_scene(self, scene): """Remove Animation, its actors and sub Animations from the scene""" @@ -1217,7 +1229,8 @@ class CameraAnimation(Animation): """ - def __init__(self, camera=None, length=None, loop=True, motion_path_res=None): + @warn_on_args_to_kwargs() + def __init__(self, *, camera=None, length=None, loop=True, motion_path_res=None): super(CameraAnimation, self).__init__( length=length, loop=loop, motion_path_res=motion_path_res ) @@ -1353,7 +1366,8 @@ def get_view_up(self, t): """ return self.get_value("view_up", t) - def set_focal_interpolator(self, interpolator, is_evaluator=False): + @warn_on_args_to_kwargs() + def set_focal_interpolator(self, interpolator, *, is_evaluator=False): """Set the camera focal position interpolator. Parameters @@ -1368,7 +1382,8 @@ def set_focal_interpolator(self, interpolator, is_evaluator=False): """ self.set_interpolator("focal", interpolator, is_evaluator=is_evaluator) - def set_view_up_interpolator(self, interpolator, is_evaluator=False): + @warn_on_args_to_kwargs() + def set_view_up_interpolator(self, interpolator, *, is_evaluator=False): """Set the camera up-view vector animation interpolator. Parameters @@ -1383,7 +1398,8 @@ def set_view_up_interpolator(self, interpolator, is_evaluator=False): """ self.set_interpolator("view_up", interpolator, is_evaluator=is_evaluator) - def update_animation(self, time=None): + @warn_on_args_to_kwargs() + def update_animation(self, *, time=None): """Update the camera animation. Parameters @@ -1396,7 +1412,7 @@ def update_animation(self, time=None): if self._camera is None: if self._scene: self._camera = self._scene.camera() - self.update_animation(time) + self.update_animation(tile=time) return else: if self.is_interpolatable("rotation"): diff --git a/fury/animation/helpers.py b/fury/animation/helpers.py index 03746f386..6ea49da20 100644 --- a/fury/animation/helpers.py +++ b/fury/animation/helpers.py @@ -1,7 +1,10 @@ import numpy as np +from fury.decorators import warn_on_args_to_kwargs -def get_previous_timestamp(timestamps, current_time, include_last=False): + +@warn_on_args_to_kwargs() +def get_previous_timestamp(timestamps, current_time, *, include_last=False): """Return the maximum previous timestamp of a given time. Parameters @@ -26,7 +29,8 @@ def get_previous_timestamp(timestamps, current_time, include_last=False): return timestamps[0] -def get_next_timestamp(timestamps, current_time, include_first=False): +@warn_on_args_to_kwargs() +def get_next_timestamp(timestamps, current_time, *, include_first=False): """Return the minimum next timestamp of a given time. Parameters diff --git a/fury/animation/tests/test_animation.py b/fury/animation/tests/test_animation.py index 207e94a61..469996345 100644 --- a/fury/animation/tests/test_animation.py +++ b/fury/animation/tests/test_animation.py @@ -30,14 +30,14 @@ def test_animation(): anim.add_static_actor(cube_actor) assert cube_actor in anim.static_actors - anim = Animation(cube_actor) + anim = Animation(actors=cube_actor) assert cube_actor in anim.actors anim_main = Animation() anim_main.add_child_animation(anim) assert anim in anim_main.child_animations - anim = Animation(cube_actor) + anim = Animation(actors=cube_actor) anim.set_position(0, np.array([1, 1, 1])) # overriding a keyframe anim.set_position(0, np.array([0, 0, 0])) @@ -79,7 +79,7 @@ def test_animation(): cube = actor.cube(np.array([[0, 0, 0]])) anim.add_actor(cube) - anim.update_animation(0) + anim.update_animation(time=0) if not shaders: transform = cube.GetUserTransform() npt.assert_almost_equal(anim.get_position(0), transform.GetPosition()) @@ -89,7 +89,7 @@ def test_animation(): def test_camera_animation(): cam = Camera() - anim = CameraAnimation(cam) + anim = CameraAnimation(camera=cam) assert anim.camera is cam @@ -101,13 +101,13 @@ def test_camera_animation(): anim.set_rotation(0, np.array([180, 0, 0])) - anim.update_animation(0) + anim.update_animation(time=0) npt.assert_almost_equal(cam.GetPosition(), np.array([1, 2, 3])) npt.assert_almost_equal(cam.GetFocalPoint(), np.array([10, 20, 30])) - anim.update_animation(3) + anim.update_animation(time=3) npt.assert_almost_equal(cam.GetPosition(), np.array([3, 2, 1])) npt.assert_almost_equal(cam.GetFocalPoint(), np.array([30, 20, 10])) - anim.update_animation(1.5) + anim.update_animation(time=1.5) npt.assert_almost_equal(cam.GetPosition(), np.array([2, 2, 2])) npt.assert_almost_equal(cam.GetFocalPoint(), np.array([20, 20, 20])) rot = np.zeros(16) diff --git a/fury/animation/tests/test_timeline.py b/fury/animation/tests/test_timeline.py index 79a3301be..1a1618ac3 100644 --- a/fury/animation/tests/test_timeline.py +++ b/fury/animation/tests/test_timeline.py @@ -57,7 +57,7 @@ def test_timeline(): anim.set_position(12, [1, 2, 1]) assert tl_2.duration == length - tl_2 = Timeline(anim, length=11) + tl_2 = Timeline(animations=anim, length=11) assert tl_2.duration == 11 tl = Timeline(playback_panel=True) diff --git a/fury/animation/timeline.py b/fury/animation/timeline.py index 7156a809d..17d342b93 100644 --- a/fury/animation/timeline.py +++ b/fury/animation/timeline.py @@ -6,6 +6,7 @@ from fury import window from fury.animation.animation import Animation +from fury.decorators import warn_on_args_to_kwargs from fury.lib import RenderWindow, WindowToImageFilter, numpy_support from fury.ui.elements import PlaybackPanel @@ -33,7 +34,10 @@ class Timeline: """ - def __init__(self, animations=None, playback_panel=False, loop=True, length=None): + @warn_on_args_to_kwargs() + def __init__( + self, *, animations=None, playback_panel=False, loop=True, length=None + ): self._scene = None self.playback_panel = None self._current_timestamp = 0 @@ -284,8 +288,10 @@ def has_playback_panel(self): """ return self.playback_panel is not None + @warn_on_args_to_kwargs() def record( self, + *, fname=None, fps=30, speed=1.0, @@ -450,7 +456,8 @@ def animations(self) -> "list[Animation]": """ return self._animations - def update(self, force=False): + @warn_on_args_to_kwargs() + def update(self, *, force=False): """Update the timeline. Update the Timeline and all the animations that it controls. As well as @@ -477,7 +484,7 @@ def update(self, force=False): else: self.pause() if self.playing or force: - [anim.update_animation(time) for anim in self._animations] + [anim.update_animation(time=time) for anim in self._animations] def add_to_scene(self, scene): """Add Timeline and all of its Animations to the scene""" diff --git a/fury/tests/test_gltf.py b/fury/tests/test_gltf.py index f2094c303..896a7f8d5 100644 --- a/fury/tests/test_gltf.py +++ b/fury/tests/test_gltf.py @@ -221,7 +221,7 @@ def test_skinning(): file = read_viz_gltf("SimpleSkin") gltf_obj = glTF(file) animation = gltf_obj.skin_animation()["anim_0"] - timeline = Timeline(animation) + timeline = Timeline(animations=animation) # checking weights and joints weights = np.array( [ diff --git a/fury/tests/test_window.py b/fury/tests/test_window.py index 3c3e11b4e..608da3852 100644 --- a/fury/tests/test_window.py +++ b/fury/tests/test_window.py @@ -612,7 +612,7 @@ def test_add_animation_to_show_manager(): cube = actor.cube(np.array([[2, 2, 3]])) timeline = Timeline(playback_panel=True) - animation = Animation(cube) + animation = Animation(actors=cube) timeline.add_animation(animation) showm.add_animation(timeline)