如何从 JupyterLab 扩展激活方法访问笔记本?

前段时间我为 JupyterNotebook 编写了一个扩展。现在我想将其改编为 JupyterLab。


为了访问当前打开的笔记本,我使用了:


var notebook = Jupyter.notebook;

var firstCell = notebook.get_cells()[0];

=> Jupyterlab对应的代码是什么?


module.exports = [{

    id: 'jupyterlab_workspace_module',

    autoStart: true,

    activate: function(app) {

       //app.notebook is not defined

       var notebook = getNotebook(app); // <= how to implement this?

    }

}];


隔江千里
浏览 131回答 1
1回答

繁星淼淼

var notebookPanel = __getFirstVisibleNotebookPanel(app);var notebook = notebookPanel.content;var cell = notebook.activeCell;function __getFirstVisibleNotebookPanel(app){&nbsp; &nbsp; var mainWidgets = app.shell.widgets('main');&nbsp; &nbsp; var widget = mainWidgets.next();&nbsp; &nbsp; while(widget){&nbsp; &nbsp; &nbsp; &nbsp; var type = widget.constructor.name;&nbsp; &nbsp; &nbsp; &nbsp; if(type == 'NotebookPanel'){&nbsp; //other wigets might be of type DocumentWidget&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (widget.isVisible){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return widget;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; widget = mainWidgets.next();&nbsp; &nbsp; }&nbsp; &nbsp; return null;}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript