From 0d5f0d2a3f28b335d0a8a872bbad8375de17daf9 Mon Sep 17 00:00:00 2001 From: Paul Kern Date: Tue, 1 Jun 2021 14:29:02 +0200 Subject: [PATCH 1/2] Added check for parameters --- pyghelper/utils.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/pyghelper/utils.py b/pyghelper/utils.py index 22feca7..bae730c 100644 --- a/pyghelper/utils.py +++ b/pyghelper/utils.py @@ -36,3 +36,25 @@ def close(): pygame.display.quit() pygame.quit() + + +def _check_param_type(parameter: Any, types: List[Type], error_message: str = None): + if type(types) != list and type(types) != tuple: + raise TypeError("The 'types' parameter should be a list or tuple.") + + if type(parameter) not in types: + if error_message is None: + error_message = "The parameter is not of the right type." + raise TypeError(error_message) + +def _check_list_items_type(iter: Union[List[Any], Tuple[Any]], types: List[Type], error_message: str = None): + if type(iter) != list and type(iter) != tuple: + raise TypeError("The 'iter' parameter should be a list or tuple.") + + if type(types) != list and type(types) != tuple: + raise TypeError("The 'types' parameter should be a list or tuple.") + + if any(type(item) not in types for item in iter): + if error_message is None: + error_message = "One of the element is not of the right." + raise ValueError(error_message) From a5e0f137bd7e68cd409a1be790240f7a385ac17c Mon Sep 17 00:00:00 2001 From: Paul Kern Date: Fri, 3 Feb 2023 23:35:24 +0100 Subject: [PATCH 2/2] Added mouse wheel premade events --- pyghelper/event_manager.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pyghelper/event_manager.py b/pyghelper/event_manager.py index 9b6db39..1098c2c 100644 --- a/pyghelper/event_manager.py +++ b/pyghelper/event_manager.py @@ -28,6 +28,7 @@ def __init__(self, use_default_quit_callback: bool = True): pygame.MOUSEMOTION: None, pygame.MOUSEBUTTONDOWN: None, pygame.MOUSEBUTTONUP: None, + pygame.MOUSEWHEEL: None, config.MUSICENDEVENT: None } @@ -113,6 +114,16 @@ def set_mousebuttonup_callback(self, callback: Callable[[dict], None]): self.__set_premade_callback(pygame.MOUSEBUTTONUP, callback, parameters_count=1) + def set_mousewheel_callback(self, callback: Callable[[dict], None]): + """ + Set the callback for the 'MOUSEWHEEL' event. + + callback: function to be called when this event occurs. + It should have only one parameter : a dictionary containing the event data. + """ + + self.__set_premade_callback(pygame.MOUSEWHEEL, callback, parameters_count=1) + def set_music_end_callback(self, callback: Callable[[], None]): """ Set the callback for the music end event (see SoundManager docs).