I’ve gotten keybindings to work with Panel (thanks again to @Hoxbro) but this simple case seems to have a bug. The code works fine to increment the clicks using the up arrow, until I add lines to disable/re-enable the button during the callback. The shortcut stops working after the first use.
I wonder if it’s possible to disable/re-enable in the javascript?
import panel as pn
pn.extension()
script = """
<script>
const doc = window.parent.document;
buttons = Array.from(doc.querySelectorAll('button[type=button]'));
const up_button = buttons.find(el => el.innerText === 'UP');
doc.addEventListener('keydown', function(e) {
if (e.keyCode == 38) {
up_button.click();
}
});
</script>
"""
html = pn.pane.HTML(script)
button_up = pn.widgets.Button(name="UP")
def callback_up(event):
'''
up button & arrow callback
-> key shortcut fails after first use when disabling the button
'''
button_up.disabled = True
print('callback_up')
button_up.disabled = False
button_up.on_click(callback_up)
pn.Column(
pn.Column(button_up, button_up.param.clicks),
html,
).servable()