隔江千里
2023-06-29 15:53:33
前段時間我為 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
提交
取消