【发布时间】:2021-10-21 07:07:44
【问题描述】:
我想在自定义扩展中收听 JupyterLab 笔记本(版本 3.2.0)的单元格事件。我该怎么做?
a) 搜索有关“事件”的文档并没有提供有用的信息:
https://jupyterlab.readthedocs.io/en/latest/search.html?q=events&check_keywords=yes&area=default
b) 这是我能找到的一些过时的例子:
Jupyter.events.on('execute.CodeCell', function(evt, data) {
// data.cell is the cell object
});
https://github.com/jupyter/notebook/issues/2321
b) 这是另一个过时的代码被剪断:
require([
"base/js/namespace",
"base/js/events"
],
function(Jupyter, events){
console.log("hello2");
events.on('notebook_loaded.Notebook', function(){
console.log("hello3");
});
events.on('app_initialized.NotebookApp', function(){
console.log("hello4");
});
});
https://github.com/jupyter/notebook/issues/2499
我希望使用类似的东西
app.events
或
var { Events } = require('@jupyterlab/events');
但是,这些变体不起作用。
编辑
我找到了另一个代码sn-p:
panel.notebook.model.cells.changed.connect((list, changed) => {
if (changed.type == 'add') {
each(changed.newValues, cellmodel => {
let cell = panel.notebook.widgets.find(x => x.model.id === cellmodel.id);
// do something with cell widget.
});
}
});
https://github.com/jupyterlab/jupyterlab/issues/4316
也许不再有全局“事件注册表”,但需要通过模型属性访问事件?
相关:
Where is a docs for Jupyter front-end extensions JavaScript API?
【问题讨论】:
标签: javascript jupyter-lab jupyter-extensions