This defines the Messenger class, which is responsible for most of the event handling that happens on the Python side.