Skip to content

Commit e0b6c6e

Browse files
committed
Document how to execute code and render outputs
1 parent 94adec5 commit e0b6c6e

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

src/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,17 @@ const plugin: JupyterFrontEndPlugin<IBlocklyManager> = {
5353
modelName: 'text',
5454
fileTypes: ['json'],
5555
defaultFor: ['json'],
56+
57+
// Kernel options, in this case we need to execute the code generated
58+
// in the blockly editor. The best way would be to use kernels, for
59+
// that reason, we tell the widget factory to start a kernel session
60+
// when opening the editor, and close the session when closing the editor.
5661
canStartKernel: true,
5762
preferKernel: true,
5863
shutdownOnClose: true,
64+
65+
// The rendermime instance, necessary to render the outputs
66+
// after a code execution.
5967
rendermime: rendermime
6068
});
6169

src/layout.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { SimplifiedOutputArea, OutputAreaModel } from '@jupyterlab/outputarea';
21
import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
32
import { ISessionContext } from '@jupyterlab/apputils';
43

@@ -19,7 +18,7 @@ export class BlocklyLayout extends PanelLayout {
1918
private _manager: BlocklyManager;
2019
private _workspace: Blockly.WorkspaceSvg;
2120
private _sessionContext: ISessionContext;
22-
private _outputArea: SimplifiedOutputArea;
21+
private _outputArea: Widget;
2322

2423
/**
2524
* Construct a `BlocklyLayout`.
@@ -35,11 +34,9 @@ export class BlocklyLayout extends PanelLayout {
3534
this._sessionContext = sessionContext;
3635

3736
// Creating the container for the Blockly editor
37+
// and the output area to render the execution replies.
3838
this._host = document.createElement('div');
39-
this._outputArea = new SimplifiedOutputArea({
40-
model: new OutputAreaModel({ trusted: true }),
41-
rendermime
42-
});
39+
this._outputArea = new Widget();
4340
}
4441

4542
get workspace(): PartialJSONValue {
@@ -89,12 +86,7 @@ export class BlocklyLayout extends PanelLayout {
8986

9087
run(): void {
9188
const code = this._manager.generator.workspaceToCode(this._workspace);
92-
SimplifiedOutputArea.execute(code, this._outputArea, this._sessionContext)
93-
.then(resp => {
94-
this.addWidget(this._outputArea);
95-
this._resizeWorkspace();
96-
})
97-
.catch(e => console.error(e));
89+
// Execute the code using the kernel
9890
}
9991

10092
/**

src/widget.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ export class BlocklyEditor extends DocumentWidget<BlocklyPanel, DocumentModel> {
1818
constructor(options: DocumentWidget.IOptions<BlocklyPanel, DocumentModel>) {
1919
super(options);
2020

21-
const run = new Widget();
22-
run.node.style.width = '25px';
23-
run.node.style.backgroundColor = 'green';
24-
run.node.onclick = () => (this.content.layout as BlocklyLayout).run();
25-
this.toolbar.addItem('run', run);
21+
// Create and add a button to the toolbar to execute
22+
// the code.
23+
// Example: https://github.com/jupyterlab/extension-examples/blob/9c35013ce5da125f1b5865b3f7cbb301970d5970/toolbar-button/src/index.ts#L44-L52
24+
// (this.content.layout as BlocklyLayout).run();
25+
// this.toolbar.addItem('run', button);
2626
}
2727

2828
/**

0 commit comments

Comments
 (0)