Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add callbacks for widgets gaining/losing focus #135

Open
lfuerderer opened this issue Jun 24, 2021 · 2 comments
Open

Add callbacks for widgets gaining/losing focus #135

lfuerderer opened this issue Jun 24, 2021 · 2 comments
Labels
Core Add for issues having to do with core functions Feature Request Add for a new feature request Widgets Add for issues having to do with widgets
Milestone

Comments

@lfuerderer
Copy link

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.

@lfuerderer lfuerderer added the Feature Request Add for a new feature request label Jun 24, 2021
@jwlodek jwlodek added Core Add for issues having to do with core functions Widgets Add for issues having to do with widgets labels Jun 25, 2021
@jwlodek jwlodek added this to the v0.1.5 milestone Jun 25, 2021
@jwlodek
Copy link
Owner

jwlodek commented Jun 25, 2021

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.

@lfuerderer
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Core Add for issues having to do with core functions Feature Request Add for a new feature request Widgets Add for issues having to do with widgets
Projects
None yet
Development

No branches or pull requests

2 participants