Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added jupyterlab-toparea-text widget example. #240

Merged
merged 22 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ jobs:
- signals
- state
- toolbar-button
- toparea-text-widget
- widgets
os: [ubuntu-latest, macos-latest, windows-latest]

Expand Down
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
1. [Signals](#signals)
1. [State](#state)
1. [Toolbar Item](#toolbar-item)
1. [Top Area Text Widget](#top-area-text-widget)
1. [Widgets](#widgets)
1. [Prerequisites](#prerequisites)
1. [Develop and Use the Examples](#develop-and-use-the-examples)
Expand Down Expand Up @@ -116,6 +117,7 @@ Start with the [Hello World](hello-world) and then jump to the topic you are int
- [Signals](signals)
- [State](state)
- [Toolbar item](toolbar-button)
- [Top Area Text Widget](toparea-text-widget)
- [Widgets](widgets)

You can expect from each example:
Expand Down Expand Up @@ -225,7 +227,7 @@ Add user interface to edit cell or notebook metadata.

[![Metadata Form](metadata-form/preview.gif)](metadata-form)

## [MIME Renderer](mimerenderer)
### [MIME Renderer](mimerenderer)

Add a MIME renderer for mp4 content to the application.

Expand Down Expand Up @@ -273,6 +275,13 @@ Add a new button to the notebook toolbar.

[![Toolbar button](toolbar-button/preview.gif)](toolbar-button)

### [Top Area Text Widget](toparea-text-widget)

A very simple example that adds a basic text widget to the top area. See [related video.](https://www.youtube.com/watch?v=mqotG1MkHa4).
This example is part of the [Extension Dual Compatibility Guide](https://jupyterlab.readthedocs.io/en/latest/extension_dual_compatibility.html).

[![Top Area Text Widget](toparea-text-widget/preview.jpg)](toparea-text-widget)

### [Widgets](widgets)

Add a new Widget element to the main window.
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"signals",
"state",
"toolbar-button",
"toparea-text-widget",
"widgets"
],
"devDependencies": {
Expand Down
19 changes: 19 additions & 0 deletions toparea-text-widget/.copier-answers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# 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: true
has_settings: false
kind: frontend
labextension_name: '@jupyterlab-examples/toparea'
mimetype: ''
mimetype_name: ''
project_short_description: A JupyterLab extension to add text in the top area.
python_name: jupyterlab_examples_toparea
repository: https://github.com/jupyterlab/extension-examples
test: false
viewer_name: ''

121 changes: 121 additions & 0 deletions toparea-text-widget/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
*.bundle.*
lib/
node_modules/
*.log
.eslintcache
.stylelintcache
*.egg-info/
.ipynb_checkpoints
*.tsbuildinfo
jupyterlab_examples_toparea/labextension
# Version file is handled by hatchling
jupyterlab_examples_toparea/_version.py

# 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/
6 changes: 6 additions & 0 deletions toparea-text-widget/.prettierignore
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_toparea
1 change: 1 addition & 0 deletions toparea-text-widget/.yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodeLinker: node-modules
41 changes: 41 additions & 0 deletions toparea-text-widget/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Top area widget (cross compatible extension)

This example defines an extension that adds a single self-contained text widget
to the top bar of the UI.

![preview](./preview.jpg)

## 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.

This extension doesn't need to do anything at all to be compatible
with both JupyterLab and Notebook 7+ (both apps have a top area that can hold the
widget, so it will be visible in both JupyterLab and Notebook 7+ upon install and
after launch). This will be the case if your extension only uses features
that both applications have.

## Adding a widget to the top area

You can add a widget to the top area by calling the following
method of the application shell:

```ts
// src/index.ts#L34-L34

app.shell.add(widget, 'top', { rank: 1000 });
```

The _rank_ is used to order the widget within the top area.

## Where to Go Next

If your extension is using features that are not common to both interfaces,
special steps needs to be taken. You can have a look at the [Shout button example](../shout-button-message)
that uses a feature available in JupyterLab but not in Notebook 7+.

You can have more information about this in the
[Extension Dual Compatibility Guide](https://jupyterlab.readthedocs.io/en/latest/extension_dual_compatibility.html).
5 changes: 5 additions & 0 deletions toparea-text-widget/install.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"packageManager": "python",
"packageName": "jupyterlab_examples_toparea",
"uninstallInstructions": "Use your Python package manager (pip, conda, etc.) to uninstall the package jupyterlab_examples_toparea"
}
16 changes: 16 additions & 0 deletions toparea-text-widget/jupyterlab_examples_toparea/__init__.py
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_toparea' outside a proper installation.")
__version__ = "dev"


def _jupyter_labextension_paths():
return [{
"src": "labextension",
"dest": "@jupyterlab-examples/toparea"
}]
Loading
Loading