Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…into per-kernel-widget-manager
  • Loading branch information
Alan Fleming committed Aug 31, 2024
2 parents 23d9b2b + b24fa6b commit b6a01b0
Show file tree
Hide file tree
Showing 49 changed files with 844 additions and 168 deletions.
4 changes: 2 additions & 2 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ ipyleaflet
jupyter-client
jupyter-packaging
jupyterlab >=4
jupyterlite-core >=0.3.0<0.4.0
jupyterlite-pyodide-kernel >=0.3.0<0.4.0
jupyterlite-core >=0.3.0,<0.4.0
jupyterlite-pyodide-kernel >=0.3.0,<0.4.0
matplotlib
myst-nb >=0.17,<0.18
numpy
Expand Down
2 changes: 1 addition & 1 deletion docs/source/dev_install.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ The core Jupyter Widgets packages are developed in the

To install ipywidgets from git, you will need:

- [yarn](https://yarnpkg.com/) package manager ** version 1.2.1 or later **
- [yarn](https://yarnpkg.com/) package manager ** version 3.0 or later **

- the latest [Jupyter Notebook development release](https://github.com/jupyter/notebook/releases)

Expand Down
11 changes: 7 additions & 4 deletions docs/source/examples/Image Processing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": ["remove-cell"]
"tags": [
"remove-cell"
]
},
"outputs": [],
"source": [
Expand All @@ -39,6 +41,7 @@
"from IPython.display import Image\n",
"from ipywidgets import interact, interactive, fixed\n",
"import matplotlib as mpl\n",
"import matplotlib.pyplot as plt\n",
"from skimage import data, filters, io, img_as_float\n",
"import numpy as np"
]
Expand Down Expand Up @@ -84,7 +87,7 @@
" # Don't let matplotlib autoscale the color range so we can control overall luminosity\n",
" vmax = 255 if arr.dtype == 'uint8' else 1.0\n",
" with BytesIO() as buffer:\n",
" mpl.image.imsave(buffer, arr, format=format, cmap=cmap, vmin=0, vmax=vmax)\n",
" plt.imsave(buffer, arr, format=format, cmap=cmap, vmin=0, vmax=vmax)\n",
" out = buffer.getvalue()\n",
" return Image(out)"
]
Expand Down Expand Up @@ -230,9 +233,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.5"
"version": "3.11.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}
1 change: 1 addition & 0 deletions docs/source/examples/Output Widget.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@
"```python\n",
"import threading\n",
"import time\n",
"import itertools\n",
"\n",
"def run():\n",
" for i in itertools.count(0):\n",
Expand Down
115 changes: 111 additions & 4 deletions docs/source/examples/Using Interact.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": ["remove-cell"]
"tags": [
"remove-cell"
]
},
"outputs": [],
"source": [
Expand Down Expand Up @@ -353,6 +355,111 @@
"interact(f, x=widgets.Combobox(options=[\"Chicago\", \"New York\", \"Washington\"], value=\"Chicago\"));"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Type Annotations"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If the function that you are using with interact uses type annotations, `interact` may be able to use those to determine what UI components to use in the auto-generated UI. For example, given a function with an argument annotated with type `float`"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def f(x: float):\n",
" return x"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"then `interact` will create a UI with a `FloatText` component without needing to be passed any values or abbreviations."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"interact(f);"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The following table gives an overview of different annotation types, and how they map to interactive controls:\n",
"\n",
"<table class=\"table table-condensed table-bordered\">\n",
" <tr><td><strong>Type Annotation</strong></td><td><strong>Widget</strong></td></tr> \n",
" <tr><td>`bool`</td><td>Checkbox</td></tr> \n",
" <tr><td>`str`</td><td>Text</td></tr>\n",
" <tr><td>`int`</td><td>IntText</td></tr>\n",
" <tr><td>`float`</td><td>FloatText</td></tr>\n",
" <tr><td>`Enum` subclasses</td><td>Dropdown</td></tr>\n",
"</table>\n",
"\n",
"Other type annotations are ignored."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If values or abbreviations are passed to the `interact` function, those will override any type annotations when determining what widgets to create."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Parameters which are annotationed with an `Enum` subclass will have a dropdown created whose labels are the names of the enumeration and which pass the corresponding values to the function parameter."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from enum import Enum\n",
"\n",
"class Color(Enum):\n",
" red = 0\n",
" green = 1\n",
" blue = 2\n",
"\n",
"def h(color: Color):\n",
" return color"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"When `interact` is used with the function `h`, the Dropdown widget it creates will have options `\"red\"`, `\"green\"` and `\"blue\"` and the values passed to the function will be, correspondingly, `Color.red`, `Color.green` and `Color.blue`."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"interact(h);"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -715,7 +822,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -762,9 +869,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.5"
"version": "3.12.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}
2 changes: 1 addition & 1 deletion docs/source/examples/Widget Custom.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
"\n",
"You also need to enable the widget frontend extension.\n",
"\n",
"If you are using JupyterLab 3.x:\n",
"If you are using JupyterLab (version 3.x or above):\n",
"\n",
"\n",
"```bash\n",
Expand Down
8 changes: 4 additions & 4 deletions examples/web1/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jupyter-widgets/example-web1",
"version": "8.0.10",
"version": "8.0.12",
"private": true,
"description": "Project that tests the ability to npm install jupyter-js-widgets within an npm project.",
"license": "BSD-3-Clause",
Expand All @@ -16,9 +16,9 @@
"test:firefox:headless": "npm run test:default -- --browsers=FirefoxHeadless"
},
"dependencies": {
"@jupyter-widgets/base": "^6.0.8",
"@jupyter-widgets/base-manager": "^1.0.9",
"@jupyter-widgets/controls": "^5.0.9"
"@jupyter-widgets/base": "^6.0.10",
"@jupyter-widgets/base-manager": "^1.0.11",
"@jupyter-widgets/controls": "^5.0.11"
},
"devDependencies": {
"chai": "^4.0.0",
Expand Down
8 changes: 4 additions & 4 deletions examples/web2/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jupyter-widgets/example-web2",
"version": "8.0.10",
"version": "8.0.12",
"private": true,
"description": "Project that tests the ability to npm install jupyter-js-widgets within an npm project.",
"license": "BSD-3-Clause",
Expand All @@ -13,9 +13,9 @@
"test:default": "echo \"No test specified\""
},
"dependencies": {
"@jupyter-widgets/base": "^6.0.8",
"@jupyter-widgets/base-manager": "^1.0.9",
"@jupyter-widgets/controls": "^5.0.9",
"@jupyter-widgets/base": "^6.0.10",
"@jupyter-widgets/base-manager": "^1.0.11",
"@jupyter-widgets/controls": "^5.0.11",
"codemirror": "^5.48.0",
"font-awesome": "^4.7.0"
},
Expand Down
8 changes: 4 additions & 4 deletions examples/web3/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jupyter-widgets/example-web3",
"version": "8.0.11",
"version": "8.0.13",
"private": true,
"description": "Project that tests the ability to npm install jupyter-js-widgets within an npm project.",
"license": "BSD-3-Clause",
Expand All @@ -14,9 +14,9 @@
"test:default": "echo \"No test specified\""
},
"dependencies": {
"@jupyter-widgets/base": "^6.0.8",
"@jupyter-widgets/controls": "^5.0.9",
"@jupyter-widgets/html-manager": "^1.0.11",
"@jupyter-widgets/base": "^6.0.10",
"@jupyter-widgets/controls": "^5.0.11",
"@jupyter-widgets/html-manager": "^1.0.13",
"@jupyterlab/services": "^6.0.0 || ^7.0.0",
"codemirror": "^5.48.0",
"font-awesome": "^4.7.0",
Expand Down
4 changes: 2 additions & 2 deletions examples/web4/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jupyter-widgets/example-web4",
"version": "8.0.11",
"version": "8.0.13",
"private": true,
"description": "Project that tests the ability to npm install jupyter-js-widgets within an npm project.",
"license": "BSD-3-Clause",
Expand All @@ -13,7 +13,7 @@
"test:default": "echo \"No test specified\""
},
"dependencies": {
"@jupyter-widgets/html-manager": "^1.0.11",
"@jupyter-widgets/html-manager": "^1.0.13",
"font-awesome": "^4.7.0"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/base-manager/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jupyter-widgets/base-manager",
"version": "1.0.9",
"version": "1.0.11",
"description": "Jupyter interactive widgets - base manager",
"repository": {
"type": "git",
Expand Down Expand Up @@ -32,7 +32,7 @@
"test:unit:ie": "npm run test:unit:default -- --browsers=IE"
},
"dependencies": {
"@jupyter-widgets/base": "^6.0.8",
"@jupyter-widgets/base": "^6.0.10",
"@jupyterlab/services": "^6.0.0 || ^7.0.0",
"@lumino/coreutils": "^1.11.1 || ^2",
"base64-js": "^1.2.1",
Expand Down
9 changes: 3 additions & 6 deletions packages/base-manager/src/manager-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,9 @@ export abstract class ManagerBase implements IWidgetManager {
async get_model(model_id: string): Promise<WidgetModel> {
let i = 0;
while (!this._models[model_id] && i < this._sleepTimes.length) {
await new Promise((resolve) => setTimeout(resolve, this._sleepTimes[i++]));
await new Promise((resolve) =>
setTimeout(resolve, this._sleepTimes[i++])
);
}
const modelPromise = this._models[model_id];
if (modelPromise === undefined) {
Expand Down Expand Up @@ -439,11 +441,6 @@ export abstract class ManagerBase implements IWidgetManager {
});
initComm.close();
} catch (error) {
console.warn(
'Failed to fetch ipywidgets through the "jupyter.widget.control" comm channel, fallback to fetching individual model state. Reason:',
error
);
clearTimeout(timeoutID);
// Fall back to the old implementation for old ipywidgets backend versions (ipywidgets<=7.6)
return this._loadFromKernelModels();
}
Expand Down
2 changes: 1 addition & 1 deletion packages/base/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jupyter-widgets/base",
"version": "6.0.8",
"version": "6.0.10",
"description": "Jupyter interactive widgets",
"repository": {
"type": "git",
Expand Down
12 changes: 12 additions & 0 deletions packages/base/src/widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,11 @@ export class JupyterLuminoPanelWidget extends Panel {
private _view: DOMWidgetView;
}

/**
* @deprecated Use {@link JupyterLuminoPanelWidget} instead (Since 8.0).
*/
export const JupyterPhosphorPanelWidget = JupyterLuminoPanelWidget;

export class DOMWidgetView extends WidgetView {
/**
* Public constructor
Expand Down Expand Up @@ -1244,6 +1249,13 @@ export class DOMWidgetView extends WidgetView {
return this.luminoWidget;
}

/**
* @deprecated Use {@link luminoWidget} instead (Since 8.0).
*/
set pWidget(value: Widget) {
this.luminoWidget = value;
}

el: HTMLElement; // Override typing
'$el': any;
luminoWidget: Widget;
Expand Down
Loading

0 comments on commit b6a01b0

Please sign in to comment.