Skip to content

Commit

Permalink
Merge pull request #3561 from jtpio/output-model-kernel-widget-manager
Browse files Browse the repository at this point in the history
Handle `KernelWidgetManager` in the JupyterLab `OutputModel`
  • Loading branch information
martinRenou committed Nov 17, 2022
2 parents 09bf0cf + ed4ab3d commit 2af0cc4
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions python/jupyterlab_widgets/src/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { JupyterLuminoPanelWidget } from '@jupyter-widgets/base';

import { Panel } from '@lumino/widgets';

import { WidgetManager } from './manager';
import { LabWidgetManager, WidgetManager } from './manager';

import { OutputAreaModel, OutputArea } from '@jupyterlab/outputarea';

Expand All @@ -33,11 +33,14 @@ export class OutputModel extends outputBase.OutputModel {
return false;
};

this.widget_manager.context.sessionContext.kernelChanged.connect(
(sender, args) => {
this._handleKernelChanged(args);
}
);
// if the context is available, react on kernel changes
if (this.widget_manager instanceof WidgetManager) {
this.widget_manager.context.sessionContext.kernelChanged.connect(
(sender, args) => {
this._handleKernelChanged(args);
}
);
}
this.listenTo(this, 'change:msg_id', this.reset_msg_id);
this.listenTo(this, 'change:outputs', this.setOutputs);
this.setOutputs();
Expand All @@ -60,7 +63,7 @@ export class OutputModel extends outputBase.OutputModel {
* Reset the message id.
*/
reset_msg_id(): void {
const kernel = this.widget_manager.context.sessionContext?.session?.kernel;
const kernel = this.widget_manager.kernel;
const msgId = this.get('msg_id');
const oldMsgId = this.previous('msg_id');

Expand Down Expand Up @@ -114,7 +117,7 @@ export class OutputModel extends outputBase.OutputModel {
}
}

widget_manager: WidgetManager;
widget_manager: LabWidgetManager;

private _msgHook: (msg: KernelMessage.IIOPubMessage) => boolean;
private _outputs: OutputAreaModel;
Expand Down

0 comments on commit 2af0cc4

Please sign in to comment.