48 lines
No EOL
1.1 KiB
Python
48 lines
No EOL
1.1 KiB
Python
import random
|
|
import time
|
|
from openflexure_microscope.plugins import MicroscopePlugin
|
|
|
|
from .api import IdentifyAPI, HelloWorldAPI, LongRunningAPI
|
|
|
|
|
|
class Plugin(MicroscopePlugin):
|
|
"""
|
|
A set of default plugins
|
|
"""
|
|
|
|
api_views = {
|
|
'/identify': IdentifyAPI,
|
|
'/hello': HelloWorldAPI,
|
|
'/long_running': LongRunningAPI,
|
|
}
|
|
|
|
def identify(self):
|
|
"""
|
|
Demonstrate access to Microscope.camera, and Microscope.stage
|
|
"""
|
|
|
|
response = "My parent camera is {}, and my parent stage is {}.".format(self.microscope.camera, self.microscope.stage)
|
|
print(response)
|
|
return response
|
|
|
|
def hello_world(self):
|
|
"""
|
|
Demonstrate passive method
|
|
"""
|
|
|
|
return "Hello world!"
|
|
|
|
def long_running(self, t_run):
|
|
"""
|
|
Demonstrate a long-running method that requires microscope hardware
|
|
"""
|
|
print("Starting a long-running task...")
|
|
n_array = []
|
|
|
|
for _ in range(t_run):
|
|
n_array.append(random.random())
|
|
time.sleep(1)
|
|
|
|
print("Long-running task finished!")
|
|
|
|
return n_array |