The Command Dispatch pattern is helpful when implementing GUI frameworks for your game.

Widgets are derived from the Node class, and implement event handlers, which are methods which are the event names, and have a prefix of 'EVT_'. Eg a Button class would typically implement a EVT_MouseButtonDown method which is called when a 'MouseButtonDown' event is posted to the Root node, and the Button node has the focus.

If the Button node received other events, and did not have handlers for those events, the event is passed up to the parent node.

An event handler method can explicitly pass the event onto the parent by calling self.dispatch_to_parent(event).

The end result of using the command dispatch pattern is a heirarchy of widgets, of which only one can have focus at a time, and which respond to events.

Leaf objects can be added into the widget tree to any node. A leaf node would typically be used to implement dynamic widget behaviours, and not overide the main widget event handlers. Eg, tooltips and hover effects would be created using leaf objects.