Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
0f350d4
Remove compatibility module and update Python version requirements to…
fleming79 Feb 22, 2025
a806cd9
Fix for _wrap_awaitable where aw fails.
fleming79 Feb 26, 2025
83358b4
Change selector from a property to a coroutine.
fleming79 Feb 26, 2025
120d004
Refactor vpath handling to use a coroutine and update references to _…
fleming79 Feb 26, 2025
5ae8c94
Refactor _on_ready_callbacks to use a List and update related methods…
fleming79 Feb 26, 2025
69595df
Refactor CSSStyleSheet usage in examples and remove import from __ini…
fleming79 Feb 27, 2025
83093f1
Refactor vpath and selector access to properties in App class and upd…
fleming79 Feb 27, 2025
78c5d91
Fix CSSStyleSheet and on_ready registration.
fleming79 Feb 27, 2025
04b408e
Add tests for on_ready callback registration and removal in Ipylab
fleming79 Feb 27, 2025
bc8a52e
Update test cases for on_ready callback in Ipylab and remove unused n…
fleming79 Feb 27, 2025
c1c7298
Fix JupyteFrontEnd no closing properly.
fleming79 Feb 27, 2025
fdbc1b6
Add ResizeBox widget with resize capabilities and update related files
fleming79 Mar 3, 2025
ca7b133
Add ResizeBox example notebook and update related files
fleming79 Mar 3, 2025
a14d272
Refine ResizeBox documentation and improve resizing behavior in widget
fleming79 Mar 4, 2025
8b6cb36
Fix SimpleOutput not rendering widgets.
fleming79 Mar 4, 2025
5664a64
Tweak show_dialog help info
fleming79 Mar 7, 2025
c32f913
Remove unused variable in _wrap_awaitable method
fleming79 Mar 7, 2025
a889d56
Improve ResizeBox documentation
fleming79 Mar 7, 2025
3eca164
Update pre-commit dependencies to latest versions
fleming79 Mar 7, 2025
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
4 changes: 2 additions & 2 deletions .github/workflows/packaging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu, macos, windows]
python: ['3.11', '3.13']
python: ['3.12', '3.13']
include:
- python: '3.11'
- python: '3.12'
dist: 'ipylab*.tar.gz'
- python: '3.13'
dist: 'ipylab*.whl'
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ repos:
hooks:
- id: check-json5
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.31.1
rev: 0.31.3
hooks:
- id: check-github-workflows
- repo: https://github.com/ComPWA/taplo-pre-commit
rev: v0.9.3
hooks:
- id: taplo-format
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.4
rev: v0.9.10
hooks:
- id: ruff
types_or: [python, jupyter]
Expand Down
4 changes: 1 addition & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
"python.terminal.activateEnvInCurrentTerminal": true,
"python.createEnvironment.trigger": "prompt",
"python.analysis.typeCheckingMode": "basic",
"python.testing.pytestArgs": [
"tests"
],
"python.testing.pytestArgs": ["tests"],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
}
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,11 @@ combining [Per-kernel-widget-manager](https://github.com/jupyter-widgets/ipywidg
and [weakref](https://github.com/fleming79/ipywidgets/tree/weakref).

These versions enable:
* Widget restoration when the page is reloaded.
* Starting new kernels and opening widgets from those kernels.
* autostart plugins - Run code when Jupyterlab is started.
* Viewing widgets from kernels inside from other kernels.

- Widget restoration when the page is reloaded.
- Starting new kernels and opening widgets from those kernels.
- autostart plugins - Run code when Jupyterlab is started.
- Viewing widgets from kernels inside from other kernels.

```bash
# For per-kernel-widget-manager support (Install modified version of ipywidgets, jupyterlab_widgets & widgetsnbextension)
Expand Down
16 changes: 12 additions & 4 deletions examples/css_stylesheet.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"import ipywidgets as ipw\n",
"\n",
"import ipylab\n",
"from ipylab.css_stylesheet import CSSStyleSheet\n",
"\n",
"app = ipylab.app"
]
Expand All @@ -47,7 +48,7 @@
"outputs": [],
"source": [
"# Create a new CSSStyleSheet object.\n",
"ss = ipylab.CSSStyleSheet()\n",
"ss = CSSStyleSheet()\n",
"\n",
"# Set a css variable\n",
"t = ss.set_variables({\"--ipylab-custom\": \"orange\"}) # Demonstrate setting a variable\n",
Expand All @@ -59,6 +60,13 @@
"\"\"\") # Define the stylesheet"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Resize example"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -144,7 +152,7 @@
"metadata": {},
"outputs": [],
"source": [
"ss = ipylab.CSSStyleSheet()"
"ss = CSSStyleSheet()"
]
},
{
Expand Down Expand Up @@ -181,7 +189,7 @@
"metadata": {},
"outputs": [],
"source": [
"ss = ipylab.CSSStyleSheet()\n",
"ss = CSSStyleSheet()\n",
"ss.replace(\"\"\"\n",
"/* Modify Jupyter Styles */\n",
"\n",
Expand Down Expand Up @@ -253,7 +261,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.10"
"version": "3.12.9"
}
},
"nbformat": 4,
Expand Down
202 changes: 202 additions & 0 deletions examples/resize_box.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**To use this notebook:** Run one line at a time waiting for each cell to return before running the next cell."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# ResizeBox\n",
"\n",
"The `ResizeBox` is a Box which is resizeable and reports its client size to the `size` trait. \n",
"\n",
"A resize box is useful for wrapping a widget which is not dynamically resizable, for example: the [Matplotlib ipympl widget](https://github.com/matplotlib/ipympl).\n",
"\n",
"All views of the resize box are resizeable and have the same size.\n",
"\n",
"Tip: Only use a `ResizeBox` if enabling the resize style ([resize css example](css_stylesheet.ipynb#Resize-example))) doesn't work, or if you want all views to be the same size."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import ipywidgets as ipw\n",
"\n",
"import ipylab.widgets"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"button = ipw.Button()\n",
"label = ipw.HTML(\"Test\")\n",
"resize_box = ipylab.widgets.ResizeBox([label], layout={\"border\": \"solid 1px black\"})\n",
"\n",
"\n",
"def observe(_):\n",
" label.value = f\"<b>Size: {resize_box.size}px</b>\"\n",
"\n",
"\n",
"resize_box.observe(observe, names=(\"size\"))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"resize_box"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"resize_box"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"ipw.VBox([resize_box, resize_box])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Matplotlib example\n",
"\n",
"`ipympl` provides a resizeable figure, but it isn't dynamically resizeable."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%pip install -q ipympl numpy"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Restart jupyterlab if you installed ipympl**"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import matplotlib as mpl\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
"mpl.use(\"module://ipympl.backend_nbagg\")\n",
"\n",
"x = np.linspace(0, 2 * np.pi, 200)\n",
"y = np.sin(x)\n",
"\n",
"fig, ax = plt.subplots()\n",
"ax.plot(x, y)\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Make the plot resize dynamically\n",
"\n",
"We can dynamically update the size of the plot by using `ResizeBox`."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import ipylab\n",
"from ipylab.widgets import ResizeBox\n",
"\n",
"box = ResizeBox([fig.canvas])\n",
"fig.canvas.resizable = False\n",
"\n",
"\n",
"def _observe_resizebox_dimensions(change):\n",
" box: ResizeBox = change[\"owner\"] # type: ignore\n",
" canvas = box.children[0] # type: ignore\n",
" width, height = box.size\n",
" dpi = canvas.figure.dpi\n",
" fig.set_size_inches(max((width) // dpi, 1), max((height) // dpi, 1))\n",
" fig.canvas.draw_idle()\n",
"\n",
"\n",
"box.observe(_observe_resizebox_dimensions, names=(\"size\"))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Lets add the box to the shell.\n",
"\n",
"Try the following:\n",
"- Resize the browser and watch the figure update.\n",
"- Use the resize handle to resize the plot."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"ipylab.app.shell.add(box)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.9"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Loading
Loading