diff --git a/src/commands/CommandIDs.tsx b/src/commands/CommandIDs.tsx index 406abf6a..6924e20f 100644 --- a/src/commands/CommandIDs.tsx +++ b/src/commands/CommandIDs.tsx @@ -35,6 +35,7 @@ export const commandIDs = { nextNode: "Xircuit-editor:next-node", outputMsg: "Xircuit-log:logOutputMessage", executeToOutputPanel: "Xircuit-output-panel:execute", + executeToTerminal: "Xircuit-terminal:execute", createNewComponentLibrary: "Xircuit-editor:new-component-library", refreshComponentList: "xircuits-sidebar:refresh-component-list", toggleDisplayNodesInLibrary: "xircuits-sidebar:toggle-display-nodes-in-library", diff --git a/src/components/XircuitsBodyWidget.tsx b/src/components/XircuitsBodyWidget.tsx index 6db63fda..0d2e84b5 100644 --- a/src/components/XircuitsBodyWidget.tsx +++ b/src/components/XircuitsBodyWidget.tsx @@ -618,19 +618,30 @@ export const BodyWidget: FC = ({ if (runType == 'run') { result = await handleLocalRunDialog(); if (result.status === 'ok') { - code += "%run " + model_path + result.args; + code += "%run " + model_path + result.args; + commands.execute(commandIDs.executeToOutputPanel, { code }); + } + else if (result.status === 'cancelled') { + console.log("Run operation cancelled by user."); } - } else if (runType == 'remote-run') { + } + + else if (runType == 'remote-run') { result = await handleRemoteRunDialog(); if (result.status === 'ok') { - code += buildRemoteRunCommand(model_path, result.args); + code += buildRemoteRunCommand(model_path, result.args); + commands.execute(commandIDs.executeToOutputPanel, { code }); } } - - if (result.status === 'ok') { - commands.execute(commandIDs.executeToOutputPanel, { code }); - } else if (result.status === 'cancelled') { - console.log("Run operation cancelled by user."); + + else if (runType === 'terminal-run') { + commands.execute(commandIDs.executeToTerminal, { + python_path: model_path + }); + } + + else { + console.log("Unknown runType or user cancelled."); } }) } diff --git a/src/components/runner/RunSwitcher.tsx b/src/components/runner/RunSwitcher.tsx index 88dfd684..221548f7 100644 --- a/src/components/runner/RunSwitcher.tsx +++ b/src/components/runner/RunSwitcher.tsx @@ -42,6 +42,7 @@ export class RunSwitcher extends ReactWidget { + ); } @@ -54,8 +55,9 @@ export class RunSwitcher extends ReactWidget { title={'Select the run type'} > - + + ); }} diff --git a/src/index.tsx b/src/index.tsx index e22573f4..5d7357d9 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -356,6 +356,21 @@ const xircuits: JupyterFrontEndPlugin = { }, }); + app.commands.addCommand(commandIDs.executeToTerminal, { + label: 'Run in Terminal', + execute: async args => { + + const python_path = (args['python_path'] as string); + const terminalWidget = await app.commands.execute('terminal:create-new'); + app.shell.add(terminalWidget, 'main', { mode: 'split-bottom' }); + const terminalSession = terminalWidget.content.session; + + terminalSession.send({ type: 'stdin', content: [`cd $JUPYTER_SERVER_ROOT\n`] }); + terminalSession.send({ type: 'stdin', content: [`export PYTHONPATH=$JUPYTER_SERVER_ROOT:$PYTHONPATH\n`] }); + terminalSession.send({ type: 'stdin', content: ['python ' + python_path + '\n'] }); + } + }); + // Add a command for compiling a xircuits file from the file browser context menu. app.commands.addCommand(commandIDs.compileWorkflowFromFileBrowser, { label: 'Compile Xircuits', @@ -523,4 +538,4 @@ const plugins: JupyterFrontEndPlugin[] = [ logPlugin ]; -export default plugins; \ No newline at end of file +export default plugins;