亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何從 JupyterLab 擴展激活方法訪問筆記本?

如何從 JupyterLab 擴展激活方法訪問筆記本?

隔江千里 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;

}


查看完整回答
反對 回復 2023-06-29
  • 1 回答
  • 0 關注
  • 153 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號