MainLoop
The MainLoop class ties together a display module, a set of widgets and an event loop. It handles passing input from the display module to the widgets, rendering the widgets and passing the rendered canvas to the display module to display.
You can filter the input before it is passed to the widgets, or have special handling for input not handled by the widgets.
You can set and clear alarms to create timed events. To update the UI from an alarm remember to use draw_screen() before returning from your callback.
When the main loop is running, any code that raises an ExitMainLoop exception will cause the loop to exit cleanly. If any other exception reaches the main loop code, it will shut down the screen to avoid leaving the terminal in an unusual state then re-raise the exception for normal handling.
Using MainLoop is highly recommended, but if it does not fit the needs of your application you may choose to use your own code instead. There are no dependencies on MainLoop in other parts of Urwid.
Widgets Displayed
The topmost widget displayed by MainLoop must be passed to the constructor. If you want to change the topmost widget while running, you can assign a new widget to the MainLoop object's widget attribute. This is useful for applications that have a number of different modes or views.
The displayed widgets will be handling user input, so it is better to extend the widgets that are displayed with your application-specific input handling so that the application's behaviour changes when the widgets change. If all your custom input handling is done from unhandled_input, it will be difficult to extend as your application gets more complicated.
