@@ -7,7 +7,7 @@ import { JupyterLuminoPanelWidget } from '@jupyter-widgets/base';
7
7
8
8
import { Panel } from '@lumino/widgets' ;
9
9
10
- import { WidgetManager } from './manager' ;
10
+ import { KernelWidgetManager , WidgetManager } from './manager' ;
11
11
12
12
import { OutputAreaModel , OutputArea } from '@jupyterlab/outputarea' ;
13
13
@@ -33,11 +33,14 @@ export class OutputModel extends outputBase.OutputModel {
33
33
return false ;
34
34
} ;
35
35
36
- this . widget_manager . context . sessionContext . kernelChanged . connect (
37
- ( sender , args ) => {
38
- this . _handleKernelChanged ( args ) ;
39
- }
40
- ) ;
36
+ // if the context is available, react on kernel changes
37
+ if ( this . widget_manager instanceof WidgetManager ) {
38
+ this . widget_manager . context . sessionContext . kernelChanged . connect (
39
+ ( sender , args ) => {
40
+ this . _handleKernelChanged ( args ) ;
41
+ }
42
+ ) ;
43
+ }
41
44
this . listenTo ( this , 'change:msg_id' , this . reset_msg_id ) ;
42
45
this . listenTo ( this , 'change:outputs' , this . setOutputs ) ;
43
46
this . setOutputs ( ) ;
@@ -60,7 +63,12 @@ export class OutputModel extends outputBase.OutputModel {
60
63
* Reset the message id.
61
64
*/
62
65
reset_msg_id ( ) : void {
63
- const kernel = this . widget_manager . context . sessionContext ?. session ?. kernel ;
66
+ let kernel ;
67
+ if ( this . widget_manager instanceof WidgetManager ) {
68
+ kernel = this . widget_manager . context . sessionContext ?. session ?. kernel ;
69
+ } else if ( this . widget_manager instanceof KernelWidgetManager ) {
70
+ kernel = this . widget_manager . kernel ;
71
+ }
64
72
const msgId = this . get ( 'msg_id' ) ;
65
73
const oldMsgId = this . previous ( 'msg_id' ) ;
66
74
@@ -114,7 +122,7 @@ export class OutputModel extends outputBase.OutputModel {
114
122
}
115
123
}
116
124
117
- widget_manager : WidgetManager ;
125
+ widget_manager : WidgetManager | KernelWidgetManager ;
118
126
119
127
private _msgHook : ( msg : KernelMessage . IIOPubMessage ) => boolean ;
120
128
private _outputs : OutputAreaModel ;
0 commit comments