Skip to content

Commit ba4cce7

Browse files
committed
Updated the files.
1 parent 688b360 commit ba4cce7

19 files changed

+632
-4901
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ You may find it easier to learn how to create extensions _by examples_, instead
5252

5353
Start with the [Hello World](hello-world) and then jump to the topic you are interested in.
5454

55+
- [Clear Cell Outputs](clear_cell_outputs)
5556
- [Commands](commands)
5657
- [Command Palette](command-palette)
5758
- [Context Menu](context-menu)

clear_cell_outputs/LICENSE

Lines changed: 0 additions & 28 deletions
This file was deleted.

clear_cell_outputs/Preview.gif

126 KB
Loading

clear_cell_outputs/README.md

Lines changed: 54 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,61 @@
1-
# clear_cell_outputs
1+
# clear cell outputs
22

3-
<!-- ![Github Actions Status](https://github.com/yash112-lang/clear-cell-outputs/preview.gif) -->
3+
This example shows how to clear all cell outputs at once by clicking on the button.
44

5-
A JupyterLab extension for clearing all cells output at once.
5+
![Github Actions Status](./preview.gif)
66

7+
<!-- A JupyterLab extension for clearing all cells output at once. -->
78

9+
To use it first we need to import the packages
10+
```
11+
import { ToolbarButton } from '@jupyterlab/apputils';
12+
import { DocumentRegistry } from '@jupyterlab/docregistry';
13+
import { NotebookActions, NotebookPanel, INotebookModel } from '@jupyterlab/notebook';
14+
import { JupyterFrontEnd, JupyterFrontEndPlugin } from '@jupyterlab/application';
15+
import { IDisposable, DisposableDelegate } from '@lumino/disposable';
16+
```
17+
18+
Firstly we have to register the plugin information. In this we have to pass a activate **function** & the plugin **id**.
19+
20+
```
21+
const plugin: JupyterFrontEndPlugin<void> = {
22+
activate,
23+
id: 'clear-cell-outputs:buttonPlugin',
24+
autoStart: true
25+
};
26+
```
27+
Now creating a notebook widget extension that adds a button to the toolbar. For more info [IWidgetExtension](https://jupyterlab.readthedocs.io/en/latest/api/interfaces/docregistry.documentregistry.iwidgetextension.html)
28+
29+
```
30+
export
31+
class ButtonExtension implements DocumentRegistry.IWidgetExtension<NotebookPanel, INotebookModel> {
32+
33+
// Create a new extension object.
34+
35+
createNew(panel: NotebookPanel, context: DocumentRegistry.IContext<INotebookModel>): IDisposable {
36+
let clearOutput = () => {
37+
NotebookActions.clearAllOutputs(panel.content);
38+
};
39+
let button = new ToolbarButton({
40+
className: 'clear-output-button',
41+
label: 'Clear All Outputs',
42+
onClick: clearOutput,
43+
tooltip: 'Clear All Outputs'
44+
});
45+
46+
panel.toolbar.insertItem(10, 'clearOutputs', button);
47+
return new DisposableDelegate(() => {
48+
button.dispose();
49+
});
50+
}
51+
}
52+
```
53+
Now activating the extension
54+
```
55+
function activate(app: JupyterFrontEnd) {
56+
app.docRegistry.addWidgetExtension('Notebook', new ButtonExtension());
57+
};
58+
```
859

960
## Requirements
1061

@@ -26,51 +77,3 @@ To remove the extension, execute:
2677
pip uninstall clear_cell_outputs
2778
```
2879

29-
30-
## Contributing
31-
32-
### Development install
33-
34-
Note: You will need NodeJS to build the extension package.
35-
36-
The `jlpm` command is JupyterLab's pinned version of
37-
[yarn](https://yarnpkg.com/) that is installed with JupyterLab. You may use
38-
`yarn` or `npm` in lieu of `jlpm` below.
39-
40-
```bash
41-
# Clone the repo to your local environment
42-
# Change directory to the clear_cell_outputs directory
43-
# Install package in development mode
44-
pip install -e .
45-
# Link your development version of the extension with JupyterLab
46-
jupyter labextension develop . --overwrite
47-
# Rebuild extension Typescript source after making changes
48-
jlpm run build
49-
```
50-
51-
You can watch the source directory and run JupyterLab at the same time in different terminals to watch for changes in the extension's source and automatically rebuild the extension.
52-
53-
```bash
54-
# Watch the source directory in one terminal, automatically rebuilding when needed
55-
jlpm run watch
56-
# Run JupyterLab in another terminal
57-
jupyter lab
58-
```
59-
60-
With the watch command running, every saved change will immediately be built locally and available in your running JupyterLab. Refresh JupyterLab to load the change in your browser (you may need to wait several seconds for the extension to be rebuilt).
61-
62-
By default, the `jlpm run build` command generates the source maps for this extension to make it easier to debug using the browser dev tools. To also generate source maps for the JupyterLab core extensions, you can run the following command:
63-
64-
```bash
65-
jupyter lab build --minimize=False
66-
```
67-
68-
### Development uninstall
69-
70-
```bash
71-
pip uninstall clear_cell_outputs
72-
```
73-
74-
In development mode, you will also need to remove the symlink created by `jupyter labextension develop`
75-
command. To find its location, you can run `jupyter labextension list` to figure out where the `labextensions`
76-
folder is located. Then you can remove the symlink named `clear-cell-outputs` within that folder.

clear_cell_outputs/Untitled.ipynb

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)