-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added clap-button-message widget example. (#244)
* Initial clap-button-message example. * Removed notebooks. * Added README. * Removed unneeded RELEASE file. * Updated README and id's. * Updated README. * Updated README. * Updated root/proj README. * Updated title. * Updated root project metadata files. * Updated comments to highlight lab/nb7 plugins. * Formatting. * Fixed hello world config file diff in CI. * Improve example * Skip browser_check for clap-button example --------- Co-authored-by: Frédéric Collonval <[email protected]> Co-authored-by: Frédéric Collonval <[email protected]>
- Loading branch information
1 parent
f3b2b0b
commit 6f7b031
Showing
29 changed files
with
950 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Changes here will be overwritten by Copier; NEVER EDIT MANUALLY | ||
_commit: v4.2.4 | ||
_src_path: https://github.com/jupyterlab/extension-template | ||
author_email: '' | ||
author_name: Project Jupyter Contributors | ||
data_format: string | ||
file_extension: '' | ||
has_binder: false | ||
has_settings: false | ||
kind: frontend | ||
labextension_name: '@jupyterlab-examples/clap-button' | ||
mimetype: '' | ||
mimetype_name: '' | ||
project_short_description: Adds a clap button to the status bar (JupyterLab) or top | ||
area (Jupyter Notebook 7) | ||
python_name: jupyterlab_examples_shout_button | ||
repository: https://github.com/jupyterlab/extension-examples | ||
test: true | ||
viewer_name: '' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
*.bundle.* | ||
lib/ | ||
node_modules/ | ||
*.log | ||
.eslintcache | ||
.stylelintcache | ||
*.egg-info/ | ||
.ipynb_checkpoints | ||
*.tsbuildinfo | ||
jupyterlab_examples_shout_button/labextension | ||
# Version file is handled by hatchling | ||
jupyterlab_examples_shout_button/_version.py | ||
|
||
# Integration tests | ||
ui-tests/test-results/ | ||
ui-tests/playwright-report/ | ||
|
||
# Created by https://www.gitignore.io/api/python | ||
# Edit at https://www.gitignore.io/?templates=python | ||
|
||
### Python ### | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
pip-wheel-metadata/ | ||
share/python-wheels/ | ||
.installed.cfg | ||
*.egg | ||
MANIFEST | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.nox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage/ | ||
coverage.xml | ||
*.cover | ||
.hypothesis/ | ||
.pytest_cache/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
target/ | ||
|
||
# pyenv | ||
.python-version | ||
|
||
# celery beat schedule file | ||
celerybeat-schedule | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# Mr Developer | ||
.mr.developer.cfg | ||
.project | ||
.pydevproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
.dmypy.json | ||
dmypy.json | ||
|
||
# Pyre type checker | ||
.pyre/ | ||
|
||
# End of https://www.gitignore.io/api/python | ||
|
||
# OSX files | ||
.DS_Store | ||
|
||
# Yarn cache | ||
.yarn/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
node_modules | ||
**/node_modules | ||
**/lib | ||
**/package.json | ||
!/package.json | ||
jupyterlab_examples_shout_button |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
nodeLinker: node-modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# Clap Button (cross compatible extension) | ||
|
||
This example defines an extension that adds a button that if clicked will | ||
display an alert to the user. In JupyterLab the button in added in the top | ||
area (next to the main menu) and in Jupyter Notebook v7+ the button is added to the rights sidebar. | ||
|
||
![preview in Notebook v7+](./preview.png) | ||
|
||
We strongly advice to look to those examples before diving into this one: | ||
|
||
- [widgets](../widgets): The basic DOM Jupyter component. | ||
- [Simple compatibility example](../toparea-text-widget): Extension working without modification in both Notebook and JupyterLab. | ||
- [Conditional compatibility example](../shout-button-message): Extension that has | ||
a part conditionned on feature specific to JupyterLab. | ||
|
||
## Jupyter Notebook / JupyterLab compatibility | ||
|
||
As Jupyter Notebook 7+ is built with components from JupyterLab, and since | ||
both use the same building blocks, that means your extension can work | ||
on both (or any other frontend built with JupyterLab components) with | ||
little or no modification depending on its design. | ||
|
||
In this example, you will define two different plugins that require | ||
different tokens to have a custom behavior depending on the frontend used. | ||
|
||
## Require tokens | ||
|
||
For JupyterLab you can require the specific | ||
token `ILabShell`. | ||
|
||
```ts | ||
// src/index.ts#L48-L53 | ||
|
||
const pluginJupyterLab: JupyterFrontEndPlugin<void> = { | ||
id: '@jupyterlab-examples/clap-button:pluginLab', | ||
description: 'Adds a clap button to the top area JupyterLab', | ||
autoStart: true, | ||
requires: [ILabShell], | ||
activate: (app: JupyterFrontEnd, labShell: ILabShell) => { | ||
``` | ||
And for Jupyter Notebook, you can require the specific token `INotebookShell`. | ||
```ts | ||
// src/index.ts#L68-L73 | ||
|
||
const pluginJupyterNotebook: JupyterFrontEndPlugin<void> = { | ||
id: '@jupyterlab-examples/clap-button:pluginNotebook', | ||
description: 'Adds a clap button to the right sidebar of Jupyter Notebook 7', | ||
autoStart: true, | ||
requires: [INotebookShell], | ||
activate: (app: JupyterFrontEnd, notebookShell: INotebookShell) => { | ||
``` | ||
In the two plugins, the `activate` method will receive as | ||
second argument the shell token. It is fine to not used | ||
a required token as here the goal is to allow the application | ||
to figure out if the plugin should be activated or not. | ||
## Export multiple plugins | ||
If your extension is defining multiple plugin, you have to | ||
return as default export of your extension package an array | ||
of plugins. In this example: | ||
```ts | ||
// src/index.ts#L88-L93 | ||
|
||
const plugins: JupyterFrontEndPlugin<void>[] = [ | ||
pluginJupyterLab, | ||
pluginJupyterNotebook | ||
]; | ||
|
||
export default plugins; | ||
``` | ||
## Where to Go Next | ||
You can have more information about making extension compatible with | ||
multiple applications in the | ||
[Extension Dual Compatibility Guide](https://jupyterlab.readthedocs.io/en/latest/extension_dual_compatibility.html). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"packageManager": "python", | ||
"packageName": "jupyterlab_examples_shout_button", | ||
"uninstallInstructions": "Use your Python package manager (pip, conda, etc.) to uninstall the package jupyterlab_examples_shout_button" | ||
} |
16 changes: 16 additions & 0 deletions
16
clap-button-message/jupyterlab_examples_shout_button/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
try: | ||
from ._version import __version__ | ||
except ImportError: | ||
# Fallback when using the package in dev mode without installing | ||
# in editable mode with pip. It is highly recommended to install | ||
# the package from a stable release or in editable mode: https://pip.pypa.io/en/stable/topics/local-project-installs/#editable-installs | ||
import warnings | ||
warnings.warn("Importing 'jupyterlab_examples_shout_button' outside a proper installation.") | ||
__version__ = "dev" | ||
|
||
|
||
def _jupyter_labextension_paths(): | ||
return [{ | ||
"src": "labextension", | ||
"dest": "@jupyterlab-examples/clap-button" | ||
}] |
Oops, something went wrong.