A monorepo containing jupyter-blocks and jupyter-tidyblocks. Blockly extension for JupyterLab.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #15 from DenisaCG/code_execution

code execution implementation

authored by

Carlos Herrero and committed by
GitHub
3aae241a 6c7a102d

+47 -9
+22 -6
src/layout.ts
··· 1 + import { SimplifiedOutputArea, OutputAreaModel } from '@jupyterlab/outputarea'; 1 2 import { IRenderMimeRegistry } from '@jupyterlab/rendermime'; 2 3 import { ISessionContext } from '@jupyterlab/apputils'; 3 4 ··· 18 19 private _host: HTMLElement; 19 20 private _manager: BlocklyManager; 20 21 private _workspace: Blockly.WorkspaceSvg; 21 - //private _sessionContext: ISessionContext; 22 - private _outputArea: Widget; 22 + private _sessionContext: ISessionContext; 23 + private _outputArea: SimplifiedOutputArea; 23 24 24 25 /** 25 26 * Construct a `BlocklyLayout`. ··· 32 33 ) { 33 34 super(); 34 35 this._manager = manager; 35 - //this._sessionContext = sessionContext; 36 + this._sessionContext = sessionContext; 36 37 37 38 // Creating the container for the Blockly editor 38 39 // and the output area to render the execution replies. 39 40 this._host = document.createElement('div'); 40 - this._outputArea = new Widget(); 41 + 42 + // Creating a SimplifiedOutputArea widget to render the 43 + // outputs from the execution reply. 44 + this._outputArea= new SimplifiedOutputArea({ 45 + model: new OutputAreaModel({ trusted: true }), 46 + rendermime 47 + }); 41 48 } 42 49 43 50 get workspace(): PartialJSONValue { ··· 86 93 } 87 94 88 95 run(): void { 89 - //const code = this._manager.generator.workspaceToCode(this._workspace); 90 - // Execute the code using the kernel 96 + // Serializing our workspace into the chosen language generator. 97 + const code = this._manager.generator.workspaceToCode(this._workspace); 98 + 99 + // Execute the code using the kernel, by using a static method from the 100 + // same class to make an execution request. 101 + SimplifiedOutputArea.execute(code, this._outputArea, this._sessionContext) 102 + .then(resp => { 103 + this.addWidget(this._outputArea); 104 + this._resizeWorkspace(); 105 + }) 106 + .catch(e => console.error(e)); 91 107 } 92 108 93 109 /**
+14 -3
src/widget.ts
··· 3 3 DocumentWidget, 4 4 DocumentModel 5 5 } from '@jupyterlab/docregistry'; 6 + import { ToolbarButton } from '@jupyterlab/apputils'; 6 7 import { IRenderMimeRegistry } from '@jupyterlab/rendermime'; 8 + import { runIcon } from '@jupyterlab/ui-components'; 7 9 8 10 import { Panel } from '@lumino/widgets'; 9 11 import { Signal } from '@lumino/signaling'; ··· 20 22 21 23 // Create and add a button to the toolbar to execute 22 24 // 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); 25 + const runCode = () => { 26 + (this.content.layout as BlocklyLayout).run(); 27 + }; 28 + const button = new ToolbarButton({ 29 + label: 'Run Code', 30 + icon: runIcon, 31 + className: 'jp-blockly-button', 32 + onClick: runCode, 33 + tooltip: 'Run Code' 34 + }); 35 + button.addClass('jp-blockly-runButton'); 36 + this.toolbar.addItem('run', button); 26 37 } 27 38 28 39 /**
+11
style/base.css
··· 1 + .jp-blockly-button:hover { 2 + background-color: transparent !important; 3 + } 4 + 5 + .jp-blockly-runButton { 6 + background-color: var(--md-green-500) 7 + } 8 + 9 + .jp-blockly-runButton:hover { 10 + background-color: var(--md-green-700) 11 + }