Notebook: List of available front end hooks

Created on 21 Mar 2017  路  6Comments  路  Source: jupyter/notebook

I am searching for a list of all available front end hooks.

By "hook" I mean some way to inject a function to be called on specific event like running a cell, creating a cell, deleting a cell, all such things.

Do such hooks exist? And if so, where can I find a complete list of them, or what piece of code defines them?

Documentation

Most helpful comment

The following command inside the notebook source code top level directory is useful:

grep -rni "events.trigger" .

All 6 comments

There are named 'events' - e.g. when a Code cell is executed, the execute.CodeCell event is triggered. You can listen for that like this:

Jupyter.events.on('execute.CodeCell', function(evt, data) {
    // data.cell is the cell object
});

Unfortunately, I don't think there's a complete list of them anywhere, and the names are scattered throughout the codebase.

@takluyver Thanks. I think I can somehow find the occurrences in the source code with that example.

I added it to my extension, but when running it, I get the following in the console:

TypeError: Jupyter.events.on is not a function

I did require Jupyter as follows:

define(
    [
        'jquery',
        'base/js/namespace'
    ],
    function($, Jupyter) {
        function load_ipython_extension() {
            Jupyter.events.on('execute.CodeCell', function(evt, data) {
                // data.cell is the cell object
                notebook_cell = data.cell;
                console.log('EXTENSION: executing a cell');
            });
        }

        return {
            load_ipython_extension: load_ipython_extension
        };
    }
);

Do I need a different way of requiring it for the events?
I also tried with: Jupyter.notebook.events instead and that did not result in any errors. But which one is the correct one?

Oh, my mistake. I was just thinking of using the global Jupyter object, which I usually do because I'm lazy, but it doesn't work for this. If it works with Jupyter.notebook.events that should be fine - various objects have a reference to one shared events object, so it's the same however you get it.

It works with the Jupyter.notebook.events :+1:

The following command inside the notebook source code top level directory is useful:

grep -rni "events.trigger" .

Here is a list of events, though it is not complete: http://jupyter.readthedocs.io/en/latest/development_guide/js_events.html

Was this page helpful?
0 / 5 - 0 ratings

Related issues

md-jamal picture md-jamal  路  3Comments

arilwan picture arilwan  路  3Comments

mowe96 picture mowe96  路  3Comments

arbaazsama picture arbaazsama  路  3Comments

fonnesbeck picture fonnesbeck  路  3Comments