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). 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)