Skip to content

Commit

Permalink
Rename pWidget to lmWidget
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbrochart committed Feb 16, 2021
1 parent cb8eefe commit c2a9638
Show file tree
Hide file tree
Showing 11 changed files with 91 additions and 81 deletions.
30 changes: 20 additions & 10 deletions packages/base/src/widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,16 @@ export class DOMWidgetView extends WidgetView {
this.updateTooltip();
}

/**
* Getter for backward compatibility.
*
* pWidget is deprecated and will be removed in the future,
* please use lmWidget instead.
*/
get pWidget(): Widget {
return this.lmWidget;
}

setLayout(layout: LayoutModel, oldLayout?: LayoutModel): void {
if (layout) {
this.layoutPromise = this.layoutPromise.then(oldLayoutView => {
Expand All @@ -904,12 +914,12 @@ export class DOMWidgetView extends WidgetView {
// Post (asynchronous) so layout changes can take
// effect first.
MessageLoop.postMessage(
this.pWidget,
this.lmWidget,
Widget.ResizeMessage.UnknownSize
);
});
MessageLoop.postMessage(
this.pWidget,
this.lmWidget,
Widget.ResizeMessage.UnknownSize
);
return view;
Expand Down Expand Up @@ -1034,21 +1044,21 @@ export class DOMWidgetView extends WidgetView {
}

_setElement(el: HTMLElement): void {
if (this.pWidget) {
this.pWidget.dispose();
if (this.lmWidget) {
this.lmWidget.dispose();
}

this.$el = el instanceof $ ? el : $(el);
this.el = this.$el[0];
this.pWidget = new JupyterLuminoWidget({
this.lmWidget = new JupyterLuminoWidget({
node: el,
view: this
});
}

remove(): any {
if (this.pWidget) {
this.pWidget.dispose();
if (this.lmWidget) {
this.lmWidget.dispose();
}
return super.remove();
}
Expand All @@ -1063,9 +1073,9 @@ export class DOMWidgetView extends WidgetView {

private _comm_live_update(): void {
if (this.model.comm_live) {
this.pWidget.removeClass('jupyter-widgets-disconnected');
this.lmWidget.removeClass('jupyter-widgets-disconnected');
} else {
this.pWidget.addClass('jupyter-widgets-disconnected');
this.lmWidget.addClass('jupyter-widgets-disconnected');
}
}

Expand All @@ -1081,7 +1091,7 @@ export class DOMWidgetView extends WidgetView {
}
el: HTMLElement; // Override typing
'$el': any;
pWidget: Widget;
lmWidget: Widget;
layoutPromise: Promise<any>;
stylePromise: Promise<any>;
}
2 changes: 1 addition & 1 deletion packages/controls/src/widget_audio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class AudioView extends DOMWidgetView {
* Called when view is rendered.
*/
super.render();
this.pWidget.addClass('jupyter-widgets');
this.lmWidget.addClass('jupyter-widgets');
this.update(); // Set defaults.
}

Expand Down
34 changes: 17 additions & 17 deletions packages/controls/src/widget_box.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,18 @@ export class VBoxModel extends BoxModel {

export class BoxView extends DOMWidgetView {
_createElement(tagName: string): HTMLElement {
this.pWidget = new JupyterLuminoPanelWidget({ view: this });
return this.pWidget.node;
this.lmWidget = new JupyterLuminoPanelWidget({ view: this });
return this.lmWidget.node;
}

_setElement(el: HTMLElement): void {
if (this.el || el !== this.pWidget.node) {
if (this.el || el !== this.lmWidget.node) {
// Boxes don't allow setting the element beyond the initial creation.
throw new Error('Cannot reset the DOM element.');
}

this.el = this.pWidget.node;
this.$el = $(this.pWidget.node);
this.el = this.lmWidget.node;
this.$el = $(this.lmWidget.node);
}

initialize(parameters: WidgetView.IInitializeParameters): void {
Expand All @@ -80,9 +80,9 @@ export class BoxView extends DOMWidgetView {
this.listenTo(this.model, 'change:children', this.update_children);
this.listenTo(this.model, 'change:box_style', this.update_box_style);

this.pWidget.addClass('jupyter-widgets');
this.pWidget.addClass('widget-container');
this.pWidget.addClass('widget-box');
this.lmWidget.addClass('jupyter-widgets');
this.lmWidget.addClass('widget-container');
this.lmWidget.addClass('widget-box');
}

render(): void {
Expand All @@ -98,7 +98,7 @@ export class BoxView extends DOMWidgetView {
// Notify all children that their sizes may have changed.
views.forEach(view => {
MessageLoop.postMessage(
view.pWidget,
view.lmWidget,
Widget.ResizeMessage.UnknownSize
);
});
Expand All @@ -117,13 +117,13 @@ export class BoxView extends DOMWidgetView {
// we insert a dummy element so the order is preserved when we add
// the rendered content later.
const dummy = new Widget();
this.pWidget.addWidget(dummy);
this.lmWidget.addWidget(dummy);

return this.create_child_view(model)
.then((view: DOMWidgetView) => {
// replace the dummy widget with the new one.
const i = ArrayExt.firstIndexOf(this.pWidget.widgets, dummy);
this.pWidget.insertWidget(i, view.pWidget);
const i = ArrayExt.firstIndexOf(this.lmWidget.widgets, dummy);
this.lmWidget.insertWidget(i, view.lmWidget);
dummy.dispose();
return view;
})
Expand All @@ -136,7 +136,7 @@ export class BoxView extends DOMWidgetView {
}

children_views: ViewList<DOMWidgetView> | null;
pWidget: JupyterLuminoPanelWidget;
lmWidget: JupyterLuminoPanelWidget;

static class_map = {
success: ['alert', 'alert-success'],
Expand All @@ -152,7 +152,7 @@ export class HBoxView extends BoxView {
*/
initialize(parameters: WidgetView.IInitializeParameters): void {
super.initialize(parameters);
this.pWidget.addClass('widget-hbox');
this.lmWidget.addClass('widget-hbox');
}
}

Expand All @@ -162,7 +162,7 @@ export class VBoxView extends BoxView {
*/
initialize(parameters: WidgetView.IInitializeParameters): void {
super.initialize(parameters);
this.pWidget.addClass('widget-vbox');
this.lmWidget.addClass('widget-vbox');
}
}

Expand All @@ -172,9 +172,9 @@ export class GridBoxView extends BoxView {
*/
initialize(parameters: WidgetView.IInitializeParameters): void {
super.initialize(parameters);
this.pWidget.addClass('widget-gridbox');
this.lmWidget.addClass('widget-gridbox');
// display needn't be set to flex and grid
this.pWidget.removeClass('widget-box');
this.lmWidget.removeClass('widget-box');
}
}

Expand Down
20 changes: 10 additions & 10 deletions packages/controls/src/widget_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,18 +329,18 @@ export class ControllerModel extends CoreDOMWidgetModel {
*/
export class ControllerView extends DOMWidgetView {
_createElement(tagName: string): HTMLElement {
this.pWidget = new JupyterLuminoPanelWidget({ view: this });
return this.pWidget.node;
this.lmWidget = new JupyterLuminoPanelWidget({ view: this });
return this.lmWidget.node;
}

_setElement(el: HTMLElement): void {
if (this.el || el !== this.pWidget.node) {
if (this.el || el !== this.lmWidget.node) {
// Boxes don't allow setting the element beyond the initial creation.
throw new Error('Cannot reset the DOM element.');
}

this.el = this.pWidget.node;
this.$el = $(this.pWidget.node);
this.el = this.lmWidget.node;
this.$el = $(this.lmWidget.node);
}

initialize(parameters: WidgetView.IInitializeParameters): void {
Expand All @@ -367,11 +367,11 @@ export class ControllerView extends DOMWidgetView {

this.axis_box = new Panel();
this.axis_box.node.style.display = 'flex';
this.pWidget.addWidget(this.axis_box);
this.lmWidget.addWidget(this.axis_box);

this.button_box = new Panel();
this.button_box.node.style.display = 'flex';
this.pWidget.addWidget(this.button_box);
this.lmWidget.addWidget(this.button_box);

this.button_views.update(this.model.get('buttons'));
this.axis_views.update(this.model.get('axes'));
Expand All @@ -393,7 +393,7 @@ export class ControllerView extends DOMWidgetView {
.then((view: ControllerButtonView) => {
// replace the dummy widget with the new one.
const i = ArrayExt.firstIndexOf(this.button_box.widgets, dummy);
this.button_box.insertWidget(i, view.pWidget);
this.button_box.insertWidget(i, view.lmWidget);
dummy.dispose();
return view;
})
Expand All @@ -410,7 +410,7 @@ export class ControllerView extends DOMWidgetView {
.then((view: ControllerAxisView) => {
// replace the dummy widget with the new one.
const i = ArrayExt.firstIndexOf(this.axis_box.widgets, dummy);
this.axis_box.insertWidget(i, view.pWidget);
this.axis_box.insertWidget(i, view.lmWidget);
dummy.dispose();
return view;
})
Expand All @@ -429,5 +429,5 @@ export class ControllerView extends DOMWidgetView {
axis_box: Panel;
button_box: Panel;
model: ControllerModel;
pWidget: JupyterLuminoPanelWidget;
lmWidget: JupyterLuminoPanelWidget;
}
4 changes: 2 additions & 2 deletions packages/controls/src/widget_image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ export class ImageView extends DOMWidgetView {
* Called when view is rendered.
*/
super.render();
this.pWidget.addClass('jupyter-widgets');
this.pWidget.addClass('widget-image');
this.lmWidget.addClass('jupyter-widgets');
this.lmWidget.addClass('widget-image');
this.update(); // Set defaults.
}

Expand Down
2 changes: 1 addition & 1 deletion packages/controls/src/widget_int.ts
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ export class ProgressView extends DescriptionView {
initialize(parameters: WidgetView.IInitializeParameters): void {
super.initialize(parameters);
this.listenTo(this.model, 'change:bar_style', this.update_bar_style);
this.pWidget.addClass('jupyter-widgets');
this.lmWidget.addClass('jupyter-widgets');
}

render(): void {
Expand Down
Loading

0 comments on commit c2a9638

Please sign in to comment.