Skip to content

Instantly share code, notes, and snippets.

@ajbozarth
Last active April 23, 2020 20:27
Show Gist options
  • Save ajbozarth/48f0fe7f4213e11dc487046b73ded8f8 to your computer and use it in GitHub Desktop.
Save ajbozarth/48f0fe7f4213e11dc487046b73ded8f8 to your computer and use it in GitHub Desktop.
A simple JupyterLab widget that adds a button to the Notebook toolbar
import {ToolbarButton} from "@jupyterlab/apputils";
import {DocumentRegistry} from "@jupyterlab/docregistry";
import {INotebookModel, NotebookPanel} from "@jupyterlab/notebook";
import {IDisposable} from "@lumino/disposable";
export class ButtonExtension implements DocumentRegistry.IWidgetExtension<NotebookPanel, INotebookModel> {
createNew(panel: NotebookPanel, context: DocumentRegistry.IContext<INotebookModel>): IDisposable {
// Create the toolbar button
let mybutton = new ToolbarButton({
label: 'My Button',
onClick: () => alert('you did it!')
});
// Add the toolbar button to the notebook
panel.toolbar.insertItem(9, 'mybutton', mybutton);
// The ToolbarButton class implements `IDisposable`, so the
// button *is* the extension for the purposes of this method.
return mybutton;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment