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 17 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
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: 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: 6 additions & 2 deletions packages/base/src/widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1101,14 +1101,18 @@ export class DOMWidgetView extends WidgetView {
}

updateTooltip(): void {
const title = this.model.get('tooltip');
const title = this.tooltip;
if (!title) {
this.el.removeAttribute('title');
} else if (this.model.get('description').length === 0) {
} else if (!this.model.get('description')) {
fleming79 marked this conversation as resolved.
Show resolved Hide resolved
this.el.setAttribute('title', title);
}
}

get tooltip() {
return this.model.get('tooltip') ?? this.model.get('description');
}

/**
* Update the DOM classes applied to an element, default to this.el.
*/
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: 5 additions & 8 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 @@ -181,13 +180,11 @@ export class CheckboxView extends DescriptionView {
}

updateTooltip(): void {
super.updateTooltip();
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);
}
const title = this.tooltip;
this.checkbox.setAttribute('title', title);
this.descriptionSpan.setAttribute('title', title);
}

events(): { [e: string]: string } {
Expand Down
3 changes: 2 additions & 1 deletion packages/controls/src/widget_description.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,9 @@ export class DescriptionView extends DOMWidgetView {
}

updateTooltip(): void {
super.updateTooltip();
if (!this.label) return;
this.label.title = this.model.get('tooltip');
this.label.title = this.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
8 changes: 2 additions & 6 deletions packages/controls/src/widget_selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,9 @@ export class SelectionView extends DescriptionView {
}

updateTooltip(): void {
super.updateTooltip();
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);
}
this.listbox.setAttribute('title', this.tooltip);
}

listbox: HTMLSelectElement;
Expand Down
16 changes: 4 additions & 12 deletions packages/controls/src/widget_string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,13 +379,9 @@ export class TextareaView extends StringView {
}

updateTooltip(): void {
super.updateTooltip();
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);
}
this.textbox.setAttribute('title', this.tooltip);
}

events(): { [e: string]: string } {
Expand Down Expand Up @@ -505,13 +501,9 @@ export class TextView extends StringView {
}

updateTooltip(): void {
super.updateTooltip();
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);
}
this.textbox.setAttribute('title', this.tooltip);
}

update(options?: any): void {
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
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