Is there a way to capture keypress from a Button with Urwid?

241 views Asked by At

I'm using a Urwid button and wonder if there's a way to handle keypress events directly on the button?

urwid.Button((item["customer"] + "/ " + item["case"]), button_press_pick_case,
                                             user_data=item)

I know I can probably do this by capturing MainLoop's unhandled_input and then finding the currently focused button, but I wonder if there's an easier way.

Thanks

1

There are 1 answers

0
Elias Dorneles On

It seems that for global shortcuts, the way to go is really the unhandled_input.

If you want to make the button to answer to an additional key combination, you can edit the button's CommandMap, which is accessible through the _command_map widget attribute, but it will only work when the button has the focus.