diff --git a/src/ipyaladin/__init__.py b/src/ipyaladin/__init__.py index 5601631e..fda7077a 100644 --- a/src/ipyaladin/__init__.py +++ b/src/ipyaladin/__init__.py @@ -408,11 +408,21 @@ def set_listener(self, listener_type: str, callback: callable) -> None: listener_type is detected """ - self.add_listener(listener_type, callback, False) + if listener_type in {"objectHovered", "object_hovered"}: + self.listener_callback["object_hovered"] = callback + elif listener_type in {"objectClicked", "object_clicked"}: + self.listener_callback["object_clicked"] = callback + elif listener_type == "click": + self.listener_callback["click"] = callback + elif listener_type == "select": + self.listener_callback["select"] = callback + else: + raise ValueError( + "listener_type must be 'object_hovered', " + "'object_clicked', 'click' or 'select'" + ) - def add_listener( - self, listener_type: str, callback: callable, _dWarning: bool = True - ) -> None: + def add_listener(self, listener_type: str, callback: callable) -> None: """Add a listener to the widget. Use set_listener instead. Parameters @@ -422,30 +432,15 @@ def add_listener( callback: callable A python function to be called when the event corresponding to the listener_type is detected - _dWarning: bool - If True, a deprecation warning is raised Note ---- This method is deprecated, use set_listener instead """ - if _dWarning: - warnings.warn( - "add_listener is deprecated, use set_listener instead", - DeprecationWarning, - stacklevel=2, - ) - if listener_type in {"objectHovered", "object_hovered"}: - self.listener_callback["object_hovered"] = callback - elif listener_type in {"objectClicked", "object_clicked"}: - self.listener_callback["object_clicked"] = callback - elif listener_type == "click": - self.listener_callback["click"] = callback - elif listener_type == "select": - self.listener_callback["select"] = callback - else: - raise ValueError( - "listener_type must be 'object_hovered', " - "'object_clicked', 'click' or 'select'" - ) + warnings.warn( + "add_listener is deprecated, use set_listener instead", + DeprecationWarning, + stacklevel=2, + ) + self.set_listener(listener_type, callback)