diff --git a/src/openflexure_microscope_server/things/scan_workflows.py b/src/openflexure_microscope_server/things/scan_workflows.py index 6affdecf..13b6dba3 100644 --- a/src/openflexure_microscope_server/things/scan_workflows.py +++ b/src/openflexure_microscope_server/things/scan_workflows.py @@ -44,6 +44,7 @@ from openflexure_microscope_server.ui import ( Accordion, HTMLBlock, UIElementList, + action_button_for, property_control_for, ) @@ -560,6 +561,28 @@ class HistoScanWorkflow(RectGridWorkflow[HistoScanSettingsModel]): return imaged, focus_height + @lt.action + def check_background(self) -> str: + """Check if sample is background. + + This action is a pre-run check for feeding back to the user. + """ + image_array = self._cam.grab_as_array(stream_name="lores") + is_sample, bg_message = self._background_detector.image_is_sample(image_array) + label = "sample" if is_sample else "background" + + return f"Current image is {label} ({bg_message})" + + @lt.action + def set_background(self) -> None: + """Set the background for this background detector. + + This sets the background for this workflows background detector as opposed to + the active background detector for the camera. + """ + image_array = self._cam.grab_as_array(stream_name="lores") + self._background_detector.set_background(image_array) + @lt.endpoint("get", "settings_ui", responses=UI_ELEMENT_RESPONSE) def settings_ui(self) -> UIElementList: """Return the UI for the workflow's settings in the scan tab.""" @@ -593,13 +616,32 @@ class HistoScanWorkflow(RectGridWorkflow[HistoScanSettingsModel]): ), ] ) + background_ui = self._background_detector.settings_ui() + set_bg_button = action_button_for( + self, + "set_background", + poll_interval=0.1, + submit_label="Set Background", + can_terminate=False, + notify_on_success=True, + success_message="Background image has been updated", + ) + check_bg_button = action_button_for( + self, + "check_background", + poll_interval=0.1, + submit_label="Check Current Image", + can_terminate=False, + notify_on_success=True, + response_is_success_message=True, + ) + + background_ui.root += [set_bg_button, check_bg_button] + return UIElementList( [ HTMLBlock(html=f"
{self.ui_blurb}
"),
- Accordion(
- title="Background Detect",
- children=self._background_detector.settings_ui(),
- ),
+ Accordion(title="Background Detect", children=background_ui),
Accordion(
title="Scan Settings",
children=scan_settings,
diff --git a/src/openflexure_microscope_server/ui.py b/src/openflexure_microscope_server/ui.py
index 66e12241..9df04f5d 100644
--- a/src/openflexure_microscope_server/ui.py
+++ b/src/openflexure_microscope_server/ui.py
@@ -140,7 +140,7 @@ class ActionButton(BaseModel):
action: str
"""The name of the action to be triggered."""
- poll_interval: int = 1
+ poll_interval: float = 1
"""The interval for polling in seconds."""
submit_label: str = "Submit"
@@ -171,6 +171,12 @@ class ActionButton(BaseModel):
notify_on_success: bool = False
"""Specify whether to a notification on successful completion."""
+ response_is_success_message: bool = False
+ """Set True to use the action response as the success message.
+
+ If set ``success_message`` has is never used.
+ """
+
success_message: str = "Success!"
"""The message to show on successful completion."""
diff --git a/webapp/src/components/appContent.vue b/webapp/src/components/appContent.vue
index 51428b5f..502462d7 100644
--- a/webapp/src/components/appContent.vue
+++ b/webapp/src/components/appContent.vue
@@ -82,7 +82,6 @@ import tabContent from "./genericComponents/tabContent.vue";
// Import new content components
import aboutContent from "./tabContentComponents/aboutContent.vue";
-import backgroundDetectContent from "./tabContentComponents/backgroundDetectContent.vue";
import controlContent from "./tabContentComponents/controlContent.vue";
import loggingContent from "./tabContentComponents/loggingContent.vue";
import powerContent from "./tabContentComponents/powerContent.vue";
@@ -150,15 +149,6 @@ export default {
component: markRaw(controlContent),
requiredThings: [],
},
- {
- id: "background-detect",
- title: "Background Detect",
- icon: "background_replace",
- component: markRaw(backgroundDetectContent),
- // While stage isn't needed; automatic background detect has little function
- // for a manual microscope.
- requiredThings: ["stage"],
- },
{
id: "slide-scan",
title: "Slide Scan",
diff --git a/webapp/src/components/labThingsComponents/serverSpecifiedActionButton.vue b/webapp/src/components/labThingsComponents/serverSpecifiedActionButton.vue
index 78f81dd0..df1afd23 100644
--- a/webapp/src/components/labThingsComponents/serverSpecifiedActionButton.vue
+++ b/webapp/src/components/labThingsComponents/serverSpecifiedActionButton.vue
@@ -45,7 +45,11 @@ export default {
*/
actionResponse: function (response) {
if (this.actionData.notify_on_success) {
- this.modalNotify(this.actionData.success_message);
+ if (this.actionData.response_is_success_message) {
+ this.modalNotify(response.output);
+ } else {
+ this.modalNotify(this.actionData.success_message);
+ }
this.$emit("response", response);
}
},
diff --git a/webapp/src/components/labThingsComponents/serverSpecifiedInterface.vue b/webapp/src/components/labThingsComponents/serverSpecifiedInterface.vue
index 0a48c572..8c47c622 100644
--- a/webapp/src/components/labThingsComponents/serverSpecifiedInterface.vue
+++ b/webapp/src/components/labThingsComponents/serverSpecifiedInterface.vue
@@ -9,7 +9,7 @@
/>