Exemple #1
0
    def unregister_for_event(self, event_name, callback):
        """Unregister the callback for the given event.

        :param str event_name: The name of the event to unregister.
        :param callback: The function to unregister from the event.

        .. code-block:: python

            from events.manager import event_manager

            def function(game_event):
                # Code...

            event_manager.unregister_for_event('player_death', function)
        """
        # Is the event registered?
        if event_name not in self:

            # Raise an error
            raise ValueError(
                'Event "{0}" is not registered'.format(event_name))

        # Remove the callback from the event's list
        self[event_name].remove(callback)

        # Are there any callbacks remaining for the event?
        if not self[event_name]:

            # Remove the listener from the game_event_manager
            game_event_manager.remove_listener(self[event_name].listener)

            # Remove the event from the dictionary
            del self[event_name]
    def unregister_for_event(self, event_name, callback):
        """Unregister the callback for the given event.

        :param str event_name: The name of the event to unregister.
        :param callback: The function to unregister from the event.

        .. code-block:: python

            from events.manager import event_manager

            def function(game_event):
                # Code...

            event_manager.unregister_for_event('player_death', function)
        """
        # Is the event registered?
        if event_name not in self:

            # Raise an error
            raise ValueError(
                'Event "{0}" is not registered'.format(event_name))

        # Remove the callback from the event's list
        self[event_name].remove(callback)

        # Are there any callbacks remaining for the event?
        if not self[event_name]:

            # Remove the listener from the game_event_manager
            game_event_manager.remove_listener(self[event_name].listener)

            # Remove the event from the dictionary
            del self[event_name]
Exemple #3
0
    def unregister_for_event(self, event_name, callback):
        """Unregister the callback for the given event."""
        # Is the event registered?
        if event_name not in self:

            # Raise an error
            raise ValueError(
                'Event "{0}" is not registered'.format(event_name))

        # Remove the callback from the event's list
        self[event_name].remove(callback)

        # Are there any callbacks remaining for the event?
        if not self[event_name]:

            # Remove the listener from the game_event_manager
            game_event_manager.remove_listener(self[event_name].listener)

            # Remove the event from the dictionary
            del self[event_name]