Add callbacks for widgets gaining/losing focus
Is your feature request related to a problem? Please describe. I am writing a ui with two scroll menus. The user is able to navigate through the widgets using custom shortcuts (e.g. when pressing enter on the left scroll menu, the right scroll menu is selected.) Because the ui is so simple, there is no need for selecting widgets manually. When a user presses ESC while one widget is focused, I would like to just exit the program. But I see no way to detect the event of one widget losing focus.
Describe the solution you'd like I would like to be able to register a callback function for a widget losing focus. (For consistency a callback on gaining focus could also be added, but is not needed in my case.) This would allow me to call the PyCUI.stop() function when a user defocuses one widget.
The feature could also be used to change widget styles depending on the focus.
Possible alternative An alternative solution would be to allow widgets to catch the ESC-keypress event and replace the default action (going back to widget selection) with a custom action.
I think this is a good idea, and shouldn't be too challenging to implement. One thing to consider would be whether or not we should allow for specifying a different callback for losing focus into overview mode, vs. moving focus to another widget.
As far as I understand, moving focus directly to another widget is only possible using the PyCUI.move_focus() method, not by user interaction.
In my specific case, different callbacks would actually be helpful, but not absolutely necessary. (I could change a variable before calling move_focus() so that the callback is able to check this.)
In my opinion, separate callbacks are not needed in the general case. Especially when using the callbacks to change the widget style, it is not relevant which way the focus got lost.