I'm trying to create a keyboard shortcut to invoke the Close and Halt dropdown button in an open notebook. I've tried using the following without success:
%%javascript
Jupyter.keyboard_manager.command_shortcuts.add_shortcut('ctrl-q', {
help : 'Halt and Close',
help_index : 'zz',
handler : function (event) {
IPython.notebook.kill_and_exit();
return false;
}}
);
If I use another method, say clear_all_output in place of kill_and_exit, the shortcut works as expected. Am I using the wrong method here?
IIRC this is a browser limitation, you cannot trigger a window closing too long after an user action, which often need to be a click, or someone else. The definition of "Too long" is variable, and I would expect we do too many indirection and the request to close is cancelled.
We can try to investigate.
Thanks @Carreau , this might not be a crucial feature, but would help workflow, especially without the ability to preview notebooks before opening them.
+1 on this, it would assist workflow for when you're making changes to lots of notebooks in sequence.
+1, if no one doing this, I can do it
5.0 (now in rc2) have the ability to create custom shortcuts from the help menu. So there is no need for patch, for the shortcut, though it is not exposed as an action. It should not be too hard to do .
Is this still active?
I think the active part is to expose the function behind the 'close and halt' menu entry:
As an action, so that users can easily assign it a keyboard shortcut in the UI.
Fixed by #3314 - it doesn't add a shortcut by default, but it makes it an action so you can easily configure a shortcut in the notebook interface.
Most helpful comment
Thanks @Carreau , this might not be a crucial feature, but would help workflow, especially without the ability to preview notebooks before opening them.