Declarative coordinated multiple views for Jupyter Widgets
Project description
with-coordination
declarative coordinated multiple views for Jupyter Widgets
pip install with-coordination
usage
import ipywidgets
# create a set of widgets
slider1 = ipywidgets.FloatSlider(description='Slider 1')
slider2 = ipywidgets.FloatSlider(description='Slider 2')
slider3 = ipywidgets.FloatSlider(description='Slider 3')
# prepare an output area with arrangement of widgets
ipywidgets.VBox([slider1, slider2, slider3])
from with_coordination import Coordination
# create a coordination context
with Coordination() as c:
# define a coordination type
with c.type("sliderValue") as t:
# add a scope with a set of widgets
with t.scope("A", 10) as s:
# alias maps the widget prop to the coordination type if they are different
s.view(slider1, alias="value")
with t.scope("B", 4.0) as s:
s.view(slider2, alias="value")
s.view(slider3, alias="value")
# get the coordination configuration as json
print(c.to_json()) # b'{"coordinationSpace":{"sliderValue":{"A":10,"B":4.0}},"viewCoordination":{"view_0": ...'
Alternatively, you can use use an existing configuration to create a coordination context.
with open("config.json", "w") as f:
f.write("""
{
"key": 1,
"coordinationSpace": { "sliderValue": { "A": 0.5, "B": 0.75 } },
"viewCoordination": {
"slider1": { "coordinationScopes": { "sliderValue": "A" } },
"slider2": { "coordinationScopes": { "sliderValue": "B" } },
"slider3": { "coordinationScopes": { "sliderValue": "B" } }
}
}
""")
with Coordination("config.json") as c:
c.use_widget(slider1, view_id="slider1", aliases={"value": "sliderValue"})
c.use_widget(slider2, view_id="slider2", aliases={"value": "sliderValue"})
c.use_widget(slider3, view_id="slider3", aliases={"value": "sliderValue"})
why
Managing coordinated multiple views is a complex task. This library provides an ergonomic and declarative API to specify how widgets traits should be coordinated.
with-coordination is based on the declarative JSON coordination
specification from
use-coordination
and is
designed to work with anywidget.
development
this project is managed using rye.
rye run jupyter lab
rye manages testing, linting, and formatting.
rye test
rye lint
rye format
alternatively you can create a virtual environment and use an development installation. You will need to install jupyterlab
.
python -m venv .venv
source .venv/bin/activate
pip install -e .
pip install jupyterlab
jupyter lab
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file with_coordination-0.0.1.tar.gz
.
File metadata
- Download URL: with_coordination-0.0.1.tar.gz
- Upload date:
- Size: 9.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 19df2c4c6253a03c46abbb3c929a896af4bba092a43d4f6028503caf6f111520 |
|
MD5 | f33a538562703aec7a5c8358a9c2abea |
|
BLAKE2b-256 | 8446a854d3a196008c2d39fae210253bd0e40c234bcf9df6b12bc39c6eb55649 |
File details
Details for the file with_coordination-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: with_coordination-0.0.1-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 31bfa68d184419c2025f3739ac3be53c1eaa57e98ffd76bc4f9c1d3d64077c54 |
|
MD5 | ecef7cf0aeb07941a4a525c1e9060263 |
|
BLAKE2b-256 | 0404420eb6257697477cc26f14f90deb0a54062cbb39dd11e51f397ba360e32a |