如何将键盘快捷键永久添加到 Jupyter (ipython) 笔记本? [英] How to add keyboard shortcuts permanently to Jupyter (ipython) notebook?

查看:24
本文介绍了如何将键盘快捷键永久添加到 Jupyter (ipython) 笔记本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下快捷方式配置,在 Jupiter notebook 的单元格中运行后即可使用:

I have the following configuration for shortcuts, that works after running it in the cell of Jupiter notebook:

%%javascript


IPython.keyboard_manager.command_shortcuts.add_shortcut('ctrl-q', {
    help: 'Clear all output',               // This text will show up on the help page (CTRL-M h or ESC h)
    handler: function (event) {             // Function that gets invoked
        if (IPython.notebook.mode == 'command') {
            IPython.notebook.clear_all_output();
            return false;
        }
        return true;                   
    }
  });

如何设置 Jupiter notebook 在启动时自动进行初始化?

How can I setup Jupiter notebook to make this initialization automatically on startup?

我尝试将相同的代码(没有 %%javascript)添加到 C:Users.ipythonprofile_defaultstaticcustomcustom.js但它没有用.

I tried adding the same code (without %%javascript) to C:Users<username>.ipythonprofile_defaultstaticcustomcustom.js but it didn't work.

我只有一个配置文件,使用 ipython profile create、Python 3.3、Windows 7 创建.

I have only one profile, created with ipython profile create, Python 3.3, Windows 7.

提前致谢.

推荐答案

custom.js 是这段代码的正确位置.尝试按如下方式包装它(不要忘记块结束前的 return true):

custom.js is the correct place for this code. Try wrapping it as follows (don't forget the return true before the end of the block):

$([IPython.events]).on("app_initialized.NotebookApp", function () {
    <your code>

    return true;
});

这篇关于如何将键盘快捷键永久添加到 Jupyter (ipython) 笔记本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆