gpt4 book ai didi

ipython-notebook - 如何将命令绑定(bind)到 'Restart and Run All' ?

转载 作者:行者123 更新时间:2023-12-03 23:33:41 26 4
gpt4 key购买 nike

我最近构建了 Jupyter,但有一个菜单操作允许您 重启&全部运行 :

enter image description here

我想添加一个绑定(bind)到此操作的键盘快捷键。我看过documentation 用于键盘自定义,但我仍然不确定如何添加键盘快捷键。

我已经从源代码构建了 Juypter,因此根据帮助,看来我需要向 notebook/static/custom/custom.js 添加一些代码.

我尝试添加以下内容:

IPython.keyboard_manager.command_shortcuts.add_shortcut('meta-r', function (event) {
IPython.notebook.restart_kernel();
IPython.notebook.execute_run_all();
return false;
});

但是,当我按 [元-r] ,内核似乎重新启动但 execute_run_all() 没有被执行。

最佳答案

以防万一有人偶然发现这篇文章寻找相同的答案:您需要等待内核在执行前超时重新启动。
看到这个discussion on GitHub .

在您的情况下,它将给出:

IPython.keyboard_manager.command_shortcuts.add_shortcut('meta-r',
function (event) {
IPython.notebook.kernel.restart();
setTimeout(function(){ IPython.notebook.execute_all_cells(); }, 1000);
return false;
});

关于ipython-notebook - 如何将命令绑定(bind)到 'Restart and Run All' ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32573958/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com