After speaking with Jiba, we've decided a better way of handling events is needed. An object cannot just read events without erasing them for other objects, etc. So now event list is persistant thru the entire round. Also, event callbacks can now be registered, and called whenever the appropriate event occurs. This helps eliminate key checks inside begin_round for every interactive object. And, it's prettier to code.
This is the overall design of the changes. Comments would be appriciated.
soya.event.list:
A list containing all of the events that occured in the last round. Maintained inside the main-loop.
User-changes to the list will only remain until end of round.
soya.event.update_list():
Updates soya.event.list, in case someone doesn't want to wait for the main-loop (note: old events will be removed)
soya.process_event():
Deprecated.
Basically calls event.update_list() and returns the list before the update.
soya.event.register(type_pred, value_pred, callback):
Registers a callback
Whenever an event of type 'event_type' and with value of 'event_value' is encountered when updating the list (whether from main-loop or from event.update), callback will be called with relevant params.
The type of 'event_type' and 'event_value' can be one of the following:
1) int. In that case it is compared with the event's type/value (==)
2) tuple. In that case the event's type/value is searched inside the tuple (in)
3) function. In that case the function is called with the event's type/value as an argument, and the result is the predicate.
An instance of class EventCallback will be created to hold the necessary data, and returned to the user.
User may later access attributes type_pred, value_pred and callback, and change them as he wishes.
The instance will also be added to the list - 'event.registered'
soya.event.unregister(event_callback):
Unregisters a callback. (Callback will no longer be called)
event_ballback is the instance of EventCallback returned from event.register().
soya.event.registered():
Returns a list of registered events.
By default, soya.MAIN_LOOP.stop is registered to be called upon a QUIT event.
It's accessible at soya.event.QUIT_EVENT .
Have a great day,
Erez Sh.
_______________________________________________ Soya-user mailing list [email protected] https://mail.gna.org/listinfo/soya-user
