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

weakref to enable gc + setting children with iterable + fix various tooltips #3921

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
1 change: 1 addition & 0 deletions docs/source/dev_install.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ To update the widget model specification with changes, do something like this in
```
python ./packages/schema/generate-spec.py -f json-pretty packages/schema/jupyterwidgetmodels.latest.json
python ./packages/schema/generate-spec.py -f markdown packages/schema/jupyterwidgetmodels.latest.md
jlpm prettier
```

## Releasing new versions
Expand Down
1 change: 0 additions & 1 deletion packages/base-manager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
"chai": "^4.0.0",
"chai-as-promised": "^7.0.0",
"expect.js": "^0.3.1",
"istanbul-instrumenter-loader": "^3.0.1",
"karma": "^6.3.3",
"karma-chrome-launcher": "^3.1.0",
"karma-coverage": "^2.0.3",
Expand Down
3 changes: 1 addition & 2 deletions packages/base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"dependencies": {
"@jupyterlab/services": "^6.0.0 || ^7.0.0",
"@lumino/coreutils": "^1.11.1 || ^2.1",
"@lumino/messaging": "^1.10.1 || ^2.1",
"@lumino/messaging": "^1.10.1 || ^2.0.1",
"@lumino/widgets": "^1.30.0 || ^2.1",
"@types/backbone": "1.4.14",
"@types/lodash": "^4.14.134",
Expand All @@ -55,7 +55,6 @@
"chai": "^4.0.0",
"chai-as-promised": "^7.0.0",
"expect.js": "^0.3.1",
"istanbul-instrumenter-loader": "^3.0.1",
"karma": "^6.3.3",
"karma-chrome-launcher": "^3.1.0",
"karma-coverage": "^2.0.3",
Expand Down
8 changes: 4 additions & 4 deletions packages/base/src/widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1101,11 +1101,11 @@ export class DOMWidgetView extends WidgetView {
}

updateTooltip(): void {
const title = this.model.get('tooltip');
if (!title) {
this.el.removeAttribute('title');
} else if (this.model.get('description').length === 0) {
const title = this.model.get('tooltip') ?? this.model.get('description');
if (title) {
this.el.setAttribute('title', title);
} else {
this.el.removeAttribute('title');
}
}

Expand Down
5 changes: 2 additions & 3 deletions packages/controls/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
},
"dependencies": {
"@jupyter-widgets/base": "^6.0.10",
"@lumino/algorithm": "^1.9.1 || ^2.1",
"@lumino/algorithm": "^1.9.2 || ^2.0.1",
"@lumino/domutils": "^1.8.1 || ^2.1",
"@lumino/messaging": "^1.10.1 || ^2.1",
"@lumino/messaging": "^1.10.1 || ^2.0.1",
"@lumino/signaling": "^1.10.1 || ^2.1",
"@lumino/widgets": "^1.30.0 || ^2.1",
"d3-color": "^3.0.1",
Expand All @@ -57,7 +57,6 @@
"chai": "^4.0.0",
"css-loader": "^6.5.1",
"expect.js": "^0.3.1",
"istanbul-instrumenter-loader": "^3.0.1",
"karma": "^6.3.3",
"karma-chrome-launcher": "^3.1.0",
"karma-coverage": "^2.0.3",
Expand Down
13 changes: 1 addition & 12 deletions packages/controls/src/widget_bool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,7 @@ export class CheckboxView extends DescriptionView {
this.descriptionSpan.textContent = description;
}
this.typeset(this.descriptionSpan);
this.descriptionSpan.title = description;
this.checkbox.title = description;
this.updateTooltip();
}

/**
Expand All @@ -180,16 +179,6 @@ export class CheckboxView extends DescriptionView {
}
}

updateTooltip(): void {
if (!this.checkbox) return; // we might be constructing the parent
const title = this.model.get('tooltip');
if (!title) {
this.checkbox.removeAttribute('title');
} else if (this.model.get('description').length === 0) {
this.checkbox.setAttribute('title', title);
}
}

events(): { [e: string]: string } {
return {
'click input[type="checkbox"]': '_handle_click',
Expand Down
5 changes: 0 additions & 5 deletions packages/controls/src/widget_description.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,6 @@ export class DescriptionView extends DOMWidgetView {
}
}

updateTooltip(): void {
if (!this.label) return;
this.label.title = this.model.get('tooltip');
}

label: HTMLLabelElement;
}

Expand Down
3 changes: 3 additions & 0 deletions packages/controls/src/widget_link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,12 @@ export class DirectionalLinkModel extends CoreWidgetModel {
undefined
);
this.stopListening(this.sourceModel, 'destroy', undefined);
this.set('source', [null, '']);
}
if (this.targetModel) {
this.stopListening(this.targetModel, 'destroy', undefined);
this.set('target', [null, '']);
this.save_changes();
}
}

Expand Down
10 changes: 0 additions & 10 deletions packages/controls/src/widget_selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,6 @@ export class SelectionView extends DescriptionView {
}
}

updateTooltip(): void {
if (!this.listbox) return; // we might be constructing the parent
const title = this.model.get('tooltip');
if (!title) {
this.listbox.removeAttribute('title');
} else if (this.model.get('description').length === 0) {
this.listbox.setAttribute('title', title);
}
}

listbox: HTMLSelectElement;
}

Expand Down
20 changes: 0 additions & 20 deletions packages/controls/src/widget_string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,16 +378,6 @@ export class TextareaView extends StringView {
}
}

updateTooltip(): void {
if (!this.textbox) return; // we might be constructing the parent
const title = this.model.get('tooltip');
if (!title) {
this.textbox.removeAttribute('title');
} else if (this.model.get('description').length === 0) {
this.textbox.setAttribute('title', title);
}
}

events(): { [e: string]: string } {
return {
'keydown input': 'handleKeyDown',
Expand Down Expand Up @@ -504,16 +494,6 @@ export class TextView extends StringView {
}
}

updateTooltip(): void {
if (!this.textbox) return; // we might be constructing the parent
const title = this.model.get('tooltip');
if (!title) {
this.textbox.removeAttribute('title');
} else if (this.model.get('description').length === 0) {
this.textbox.setAttribute('title', title);
}
}

update(options?: any): void {
/**
* Update the contents of this view
Expand Down
2 changes: 1 addition & 1 deletion packages/html-manager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"@jupyterlab/outputarea": "^3.0.0 || ^4.0.0",
"@jupyterlab/rendermime": "^3.0.0 || ^4.0.0",
"@jupyterlab/rendermime-interfaces": "^3.0.0 || ^4.0.0",
"@lumino/messaging": "^1.10.1 || ^2.1",
"@lumino/messaging": "^1.10.1 || ^2.0.1",
"@lumino/widgets": "^1.30.0 || ^2.1",
"ajv": "^8.6.0",
"jquery": "^3.1.1",
Expand Down
42 changes: 7 additions & 35 deletions packages/schema/jupyterwidgetmodels.latest.json
Original file line number Diff line number Diff line change
Expand Up @@ -441,12 +441,8 @@
{
"default": [],
"help": "List of widget children",
"items": {
"type": "reference",
"widget": "Widget"
},
"name": "children",
"type": "array"
"type": "Children"
},
{
"default": "reference to new instance",
Expand Down Expand Up @@ -935,12 +931,8 @@
{
"default": [],
"help": "List of widget children",
"items": {
"type": "reference",
"widget": "Widget"
},
"name": "children",
"type": "array"
"type": "Children"
},
{
"default": "reference to new instance",
Expand Down Expand Up @@ -3753,12 +3745,8 @@
{
"default": [],
"help": "List of widget children",
"items": {
"type": "reference",
"widget": "Widget"
},
"name": "children",
"type": "array"
"type": "Children"
},
{
"default": "reference to new instance",
Expand Down Expand Up @@ -3850,12 +3838,8 @@
{
"default": [],
"help": "List of widget children",
"items": {
"type": "reference",
"widget": "Widget"
},
"name": "children",
"type": "array"
"type": "Children"
},
{
"default": "reference to new instance",
Expand Down Expand Up @@ -6643,12 +6627,8 @@
{
"default": [],
"help": "List of widget children",
"items": {
"type": "reference",
"widget": "Widget"
},
"name": "children",
"type": "array"
"type": "Children"
},
{
"default": "reference to new instance",
Expand Down Expand Up @@ -6756,12 +6736,8 @@
{
"default": [],
"help": "List of widget children",
"items": {
"type": "reference",
"widget": "Widget"
},
"name": "children",
"type": "array"
"type": "Children"
},
{
"default": "reference to new instance",
Expand Down Expand Up @@ -7914,12 +7890,8 @@
{
"default": [],
"help": "List of widget children",
"items": {
"type": "reference",
"widget": "Widget"
},
"name": "children",
"type": "array"
"type": "Children"
},
{
"default": "reference to new instance",
Expand Down
14 changes: 7 additions & 7 deletions packages/schema/jupyterwidgetmodels.latest.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ that the widget is registered with.
| `_view_module_version` | string | `'2.0.0'` |
| `_view_name` | string | `'AccordionView'` |
| `box_style` | string (one of `'success'`, `'info'`, `'warning'`, `'danger'`, `''`) | `''` | Use a predefined styling for the box. |
| `children` | array of reference to Widget widget | `[]` | List of widget children |
| `children` | Children | `[]` | List of widget children |
| `layout` | reference to Layout widget | reference to new instance |
| `selected_index` | `null` or number (integer) | `null` | The index of the selected page. This is either an integer selecting a particular sub-widget, or None to have no widgets selected. |
| `tabbable` | `null` or boolean | `null` | Is widget tabbable? |
Expand Down Expand Up @@ -163,7 +163,7 @@ that the widget is registered with.
| `_view_module_version` | string | `'2.0.0'` |
| `_view_name` | string | `'BoxView'` |
| `box_style` | string (one of `'success'`, `'info'`, `'warning'`, `'danger'`, `''`) | `''` | Use a predefined styling for the box. |
| `children` | array of reference to Widget widget | `[]` | List of widget children |
| `children` | Children | `[]` | List of widget children |
| `layout` | reference to Layout widget | reference to new instance |
| `tabbable` | `null` or boolean | `null` | Is widget tabbable? |
| `tooltip` | `null` or string | `null` | A tooltip caption. |
Expand Down Expand Up @@ -663,7 +663,7 @@ that the widget is registered with.
| `_view_module_version` | string | `'2.0.0'` |
| `_view_name` | string | `'GridBoxView'` |
| `box_style` | string (one of `'success'`, `'info'`, `'warning'`, `'danger'`, `''`) | `''` | Use a predefined styling for the box. |
| `children` | array of reference to Widget widget | `[]` | List of widget children |
| `children` | Children | `[]` | List of widget children |
| `layout` | reference to Layout widget | reference to new instance |
| `tabbable` | `null` or boolean | `null` | Is widget tabbable? |
| `tooltip` | `null` or string | `null` | A tooltip caption. |
Expand All @@ -680,7 +680,7 @@ that the widget is registered with.
| `_view_module_version` | string | `'2.0.0'` |
| `_view_name` | string | `'HBoxView'` |
| `box_style` | string (one of `'success'`, `'info'`, `'warning'`, `'danger'`, `''`) | `''` | Use a predefined styling for the box. |
| `children` | array of reference to Widget widget | `[]` | List of widget children |
| `children` | Children | `[]` | List of widget children |
| `layout` | reference to Layout widget | reference to new instance |
| `tabbable` | `null` or boolean | `null` | Is widget tabbable? |
| `tooltip` | `null` or string | `null` | A tooltip caption. |
Expand Down Expand Up @@ -1179,7 +1179,7 @@ that the widget is registered with.
| `_view_module_version` | string | `'2.0.0'` |
| `_view_name` | string | `'StackView'` |
| `box_style` | string (one of `'success'`, `'info'`, `'warning'`, `'danger'`, `''`) | `''` | Use a predefined styling for the box. |
| `children` | array of reference to Widget widget | `[]` | List of widget children |
| `children` | Children | `[]` | List of widget children |
| `layout` | reference to Layout widget | reference to new instance |
| `selected_index` | `null` or number (integer) | `null` | The index of the selected page. This is either an integer selecting a particular sub-widget, or None to have no widgets selected. |
| `tabbable` | `null` or boolean | `null` | Is widget tabbable? |
Expand All @@ -1198,7 +1198,7 @@ that the widget is registered with.
| `_view_module_version` | string | `'2.0.0'` |
| `_view_name` | string | `'TabView'` |
| `box_style` | string (one of `'success'`, `'info'`, `'warning'`, `'danger'`, `''`) | `''` | Use a predefined styling for the box. |
| `children` | array of reference to Widget widget | `[]` | List of widget children |
| `children` | Children | `[]` | List of widget children |
| `layout` | reference to Layout widget | reference to new instance |
| `selected_index` | `null` or number (integer) | `null` | The index of the selected page. This is either an integer selecting a particular sub-widget, or None to have no widgets selected. |
| `tabbable` | `null` or boolean | `null` | Is widget tabbable? |
Expand Down Expand Up @@ -1402,7 +1402,7 @@ that the widget is registered with.
| `_view_module_version` | string | `'2.0.0'` |
| `_view_name` | string | `'VBoxView'` |
| `box_style` | string (one of `'success'`, `'info'`, `'warning'`, `'danger'`, `''`) | `''` | Use a predefined styling for the box. |
| `children` | array of reference to Widget widget | `[]` | List of widget children |
| `children` | Children | `[]` | List of widget children |
| `layout` | reference to Layout widget | reference to new instance |
| `tabbable` | `null` or boolean | `null` | Is widget tabbable? |
| `tooltip` | `null` or string | `null` | A tooltip caption. |
Expand Down
2 changes: 1 addition & 1 deletion python/ipywidgets/ipywidgets/widgets/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.

from .widget import Widget, CallbackDispatcher, register, widget_serialization
from .widget import Widget, CallbackDispatcher, register, widget_serialization, enable_weakreference, disable_weakreference
from .domwidget import DOMWidget
from .valuewidget import ValueWidget

Expand Down
5 changes: 2 additions & 3 deletions python/ipywidgets/ipywidgets/widgets/tests/test_send_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@

from ..._version import __control_protocol_version__


# A widget with simple traits
class SimpleWidget(Widget):
a = Bool().tag(sync=True)
b = Tuple(Bool(), Bool(), Bool(), default_value=(False, False, False)).tag(
sync=True
)
b = Tuple(Bool(), Bool(), Bool(), default_value=(False, False, False)).tag(sync=True)
c = List(Bool()).tag(sync=True)


Expand Down
Loading