Last active
February 14, 2021 21:25
-
-
Save oeway/7a9dcb49c51b1f99b2c3619f470fe35c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <config lang="json"> | |
| { | |
| "name": "Script Editor", | |
| "type": "web-worker", | |
| "tags": [], | |
| "ui": "", | |
| "version": "0.1.0", | |
| "cover": "", | |
| "description": "A Script Editor for Controlling OpenFlexure Microscope with ImJoy", | |
| "icon": "extension", | |
| "inputs": null, | |
| "outputs": null, | |
| "api_version": "0.1.8", | |
| "env": "", | |
| "permissions": [], | |
| "requirements": [], | |
| "dependencies": [] | |
| } | |
| </config> | |
| <script lang="javascript"> | |
| class ImJoyPlugin { | |
| async setup() { | |
| api.log('initialized') | |
| } | |
| async run(ctx) { | |
| let pluginInEditor, stopped, editorWindow; | |
| const config = {lang: 'javascript'} | |
| config.templates = [ | |
| { | |
| name: "New", | |
| url: null, | |
| lang: 'javascript', | |
| }, | |
| { | |
| name: "Snap Image Template", | |
| url: "https://gist.githubusercontent.com/oeway/d8d297350f32a456677c99cf9146b437/raw/OpenFlexureSnapImageTemplate.imjoy.html", | |
| lang: "html", | |
| }, | |
| { | |
| name: "ImJoy window", | |
| url: | |
| "https://raw.githubusercontent.com/imjoy-team/ImJoy/master/web/src/plugins/windowTemplate.imjoy.html", | |
| lang: 'html', | |
| }, | |
| { | |
| name: "ImJoy web-worker", | |
| url: | |
| "https://raw.githubusercontent.com/imjoy-team/ImJoy/master/web/src/plugins/webWorkerTemplate.imjoy.html", | |
| lang: 'html', | |
| }, | |
| { | |
| name: "ImJoy web-python", | |
| url: | |
| "https://raw.githubusercontent.com/imjoy-team/ImJoy/master/web/src/plugins/webPythonTemplate.imjoy.html", | |
| lang: 'html', | |
| }, | |
| { | |
| name: "ImJoy native-python", | |
| url: | |
| "https://raw.githubusercontent.com/imjoy-team/ImJoy/master/web/src/plugins/nativePythonTemplate.imjoy.html", | |
| lang: 'html', | |
| } | |
| ] | |
| config.ui_elements = { | |
| save: { | |
| _rintf: true, | |
| type: 'button', | |
| label: "Save", | |
| visible: false, | |
| icon: "content-save", | |
| callback(content) { | |
| console.log(content) | |
| } | |
| }, | |
| run: { | |
| _rintf: true, | |
| type: 'button', | |
| label: "Run", | |
| icon: "play", | |
| visible: true, | |
| shortcut: 'Shift-Enter', | |
| async callback(content) { | |
| try { | |
| editorWindow.setLoader(true); | |
| editorWindow.updateUIElement('stop', { | |
| visible: true | |
| }) | |
| api.showProgress(0); | |
| pluginInEditor = await api.getPlugin({src: content, hot_reloading: true}) | |
| if (stopped) { | |
| pluginInEditor = null; | |
| return; | |
| } | |
| if (pluginInEditor && pluginInEditor.run) { | |
| return await pluginInEditor.run({ | |
| config: {}, | |
| data: {} | |
| }); | |
| } | |
| if (stopped) { | |
| pluginInEditor = null; | |
| return; | |
| } | |
| } catch (e) { | |
| api.showMessage("Failed to load plugin, error: " + e.toString()); | |
| } finally { | |
| editorWindow.updateUIElement('stop', { | |
| visible: false | |
| }) | |
| editorWindow.setLoader(false); | |
| api.showProgress(100); | |
| } | |
| } | |
| }, | |
| stop: { | |
| _rintf: true, | |
| type: 'button', | |
| label: "Stop", | |
| style: "color: #ff0080cf;", | |
| icon: "stop", | |
| visible: false, | |
| async callback() { | |
| stopped = true; | |
| await editorWindow.setLoader(false); | |
| await editorWindow.updateUIElement('stop', { | |
| visible: false | |
| }) | |
| } | |
| }, | |
| export: { | |
| _rintf: true, | |
| type: 'button', | |
| label: "Export", | |
| icon: "file-download-outline", | |
| visible: true, | |
| async callback(content) { | |
| const fileName = (pluginInEditor && pluginInEditor.config.name && pluginInEditor.config.name + '.imjoy.html') || config.name + '.imjoy.html' || "myPlugin.imjoy.html"; | |
| await api.exportFile(content, fileName); | |
| } | |
| } | |
| } | |
| editorWindow = await api.createWindow({ | |
| src: 'https://if.imjoy.io', | |
| name: (ctx && ctx.data && ctx.data.name) ||'OpenFlexure Script Editor', | |
| config, | |
| data: {code: ctx && ctx.data && ctx.data.code} | |
| }) | |
| } | |
| } | |
| api.export(new ImJoyPlugin()) | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment