前段时间我为 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? }}];
1 回答
繁星淼淼
TA贡献1775条经验 获得超11个赞
var notebookPanel = __getFirstVisibleNotebookPanel(app);
var notebook = notebookPanel.content;
var cell = notebook.activeCell;
function __getFirstVisibleNotebookPanel(app){
var mainWidgets = app.shell.widgets('main');
var widget = mainWidgets.next();
while(widget){
var type = widget.constructor.name;
if(type == 'NotebookPanel'){ //other wigets might be of type DocumentWidget
if (widget.isVisible){
return widget;
}
}
widget = mainWidgets.next();
}
return null;
}
添加回答
举报
0/150
提交
取消