@@ -36,17 +36,17 @@ Jupyterlab provides a class `SessionContext`
36
36
that manages a single kernel session. Here is the code to initialize such session:
37
37
38
38
``` ts
39
- // src/panel.ts#L33-L37
39
+ // src/panel.ts#L41-L45
40
40
41
41
this ._sessionContext = new SessionContext ({
42
42
sessionManager: manager .sessions ,
43
43
specsManager: manager .kernelspecs ,
44
- name: ' Extension Examples'
44
+ name: ' Extension Examples' ,
45
45
});
46
46
```
47
47
48
48
<!-- prettier-ignore-start -->
49
- <!-- embedme src/panel.ts#L43-L54 -->
49
+ <!-- embedme src/panel.ts#L51-L62 -->
50
50
51
51
``` ts
52
52
void this ._sessionContext
@@ -68,7 +68,7 @@ The session manager object is
68
68
provided directly by the JupyterLab application:
69
69
70
70
``` ts
71
- // src/index.ts#L48-L48
71
+ // src/index.ts#L52-L52
72
72
73
73
const manager = app .serviceManager ;
74
74
```
@@ -81,20 +81,22 @@ to free the kernel session resources if the panel is closed. The whole adapted
81
81
panel class looks like this:
82
82
83
83
``` ts
84
- // src/panel.ts#L25-L74
84
+ // src/panel.ts#L31-L85
85
85
86
86
export class ExamplePanel extends StackedPanel {
87
- constructor (manager : ServiceManager .IManager ) {
87
+ constructor (manager : ServiceManager .IManager , translator ? : ITranslator ) {
88
88
super ();
89
+ this ._translator = translator || nullTranslator ;
90
+ this ._trans = this ._translator .load (' jupyterlab' );
89
91
this .addClass (PANEL_CLASS );
90
92
this .id = ' kernel-messaging-panel' ;
91
- this .title .label = ' Kernel Messaging Example View' ;
93
+ this .title .label = this . _trans . __ ( ' Kernel Messaging Example View' ) ;
92
94
this .title .closable = true ;
93
95
94
96
this ._sessionContext = new SessionContext ({
95
97
sessionManager: manager .sessions ,
96
98
specsManager: manager .kernelspecs ,
97
- name: ' Extension Examples'
99
+ name: ' Extension Examples' ,
98
100
});
99
101
100
102
this ._model = new KernelModel (this ._sessionContext );
@@ -103,12 +105,12 @@ export class ExamplePanel extends StackedPanel {
103
105
this .addWidget (this ._example );
104
106
void this ._sessionContext
105
107
.initialize ()
106
- .then (async value => {
108
+ .then (async ( value ) => {
107
109
if (value ) {
108
110
await sessionContextDialogs .selectKernel (this ._sessionContext );
109
111
}
110
112
})
111
- .catch (reason => {
113
+ .catch (( reason ) => {
112
114
console .error (
113
115
` Failed to initialize the session in ExamplePanel.\n ${reason } `
114
116
);
@@ -132,6 +134,9 @@ export class ExamplePanel extends StackedPanel {
132
134
private _model: KernelModel ;
133
135
private _sessionContext: SessionContext ;
134
136
private _example: KernelView ;
137
+
138
+ private _translator: ITranslator ;
139
+ private _trans: TranslationBundle ;
135
140
}
136
141
```
137
142
@@ -143,7 +148,7 @@ Once a kernel is initialized and ready, code can be executed with the following
143
148
// src/model.ts#L46-L48
144
149
145
150
this .future = this ._sessionContext .session ?.kernel ?.requestExecute ({
146
- code
151
+ code ,
147
152
});
148
153
```
149
154
@@ -200,7 +205,7 @@ export class KernelModel {
200
205
return ;
201
206
}
202
207
this .future = this ._sessionContext .session ?.kernel ?.requestExecute ({
203
- code
208
+ code ,
204
209
});
205
210
}
206
211
0 commit comments