Stage move API now works
The test plugin seems to have problems calling setPosition more than once. We don't understand this... Co-authored-by: Kaspar Emanuel <kaspar@monostable.co.uk>
This commit is contained in:
parent
757ee216cf
commit
297908fbc8
4 changed files with 298 additions and 39 deletions
|
|
@ -0,0 +1,131 @@
|
|||
<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: "./OpenFlexureSnapImageTemplate.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>
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
<docs>
|
||||
[TODO: write documentation for this plugin.]
|
||||
</docs>
|
||||
|
||||
<config lang="json">
|
||||
{
|
||||
"name": "OpenFlexureSnapImageTemplate",
|
||||
"type": "web-worker",
|
||||
"tags": [],
|
||||
"ui": "",
|
||||
"version": "0.1.0",
|
||||
"cover": "",
|
||||
"description": "[TODO: describe this plugin with one sentence.]",
|
||||
"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) {
|
||||
// get a list of service
|
||||
const services = await api.getServices({name: "OpenFlexure"});
|
||||
// get the first service
|
||||
const ofm = services[0];
|
||||
// snap an image
|
||||
await ofm.snapImage();
|
||||
console.log("snapped an image");
|
||||
}
|
||||
}
|
||||
|
||||
api.export(new ImJoyPlugin())
|
||||
</script>
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
<docs>
|
||||
[TODO: write documentation for this plugin.]
|
||||
</docs>
|
||||
|
||||
<config lang="json">
|
||||
{
|
||||
"name": "Test OFM Stage",
|
||||
"type": "web-worker",
|
||||
"tags": [],
|
||||
"ui": "",
|
||||
"version": "0.1.0",
|
||||
"cover": "",
|
||||
"description": "Move the OFM stage to test the API works",
|
||||
"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) {
|
||||
// get a list of service
|
||||
const services = await api.getServices({name: "OpenFlexure"});
|
||||
// get the first service
|
||||
const ofm = services[0];
|
||||
// snap an image
|
||||
const start = await ofm.getXYZPosition();
|
||||
console.log(`Starting position: ${start}`);
|
||||
// move the Z axis up and down
|
||||
await ofm.setPosition(start[2] + 100);
|
||||
console.log(`Moved Z to ${await ofm.getPosition()}`);
|
||||
await ofm.setPosition(start[2]);
|
||||
console.log(`Moved Z to ${await ofm.getPosition()}`);
|
||||
}
|
||||
}
|
||||
|
||||
api.export(new ImJoyPlugin())
|
||||
</script>
|
||||
Loading…
Add table
Add a link
Reference in a new issue