Moved plugin mounting to a Microscope method
This commit is contained in:
parent
8e953e1064
commit
7a58b4e95e
3 changed files with 23 additions and 13 deletions
|
|
@ -8,7 +8,7 @@ import numpy as np
|
||||||
from openflexure_stage import OpenFlexureStage
|
from openflexure_stage import OpenFlexureStage
|
||||||
from .camera.pi import StreamingCamera
|
from .camera.pi import StreamingCamera
|
||||||
|
|
||||||
from .plugins import PluginMount
|
from .plugins import PluginMount, load_plugin, search_plugin_paths
|
||||||
|
|
||||||
|
|
||||||
class Microscope(object):
|
class Microscope(object):
|
||||||
|
|
@ -61,6 +61,20 @@ class Microscope(object):
|
||||||
logging.info("Attached stage {}".format(stage))
|
logging.info("Attached stage {}".format(stage))
|
||||||
self.stage.backlash = np.zeros(3, dtype=np.int)
|
self.stage.backlash = np.zeros(3, dtype=np.int)
|
||||||
|
|
||||||
|
def find_plugins(self, plugin_paths=[], include_default=True):
|
||||||
|
"""
|
||||||
|
Automatically search for plugins, and attach to self.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
plugin_paths (list): List of strings of plugin directories.
|
||||||
|
include_default (bool): Also load plugins from the module default directory (DEFAULT_PLUGIN_PATH)
|
||||||
|
"""
|
||||||
|
plugins_list = search_plugin_paths(plugin_paths, include_default=include_default)
|
||||||
|
|
||||||
|
for i in plugins_list:
|
||||||
|
module = load_plugin(i)
|
||||||
|
self.plugin.attach(module)
|
||||||
|
|
||||||
# Create unified state
|
# Create unified state
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
|
|
|
||||||
|
|
@ -8,23 +8,23 @@ HERE = os.path.abspath(os.path.dirname(__file__))
|
||||||
DEFAULT_PLUGIN_PATH = os.path.join(HERE, 'default')
|
DEFAULT_PLUGIN_PATH = os.path.join(HERE, 'default')
|
||||||
|
|
||||||
|
|
||||||
def search_plugin_dirs(plugin_dirs, include_default=True):
|
def search_plugin_dirs(plugin_paths, include_default=True):
|
||||||
"""
|
"""
|
||||||
Search through, and load from, a list of plugin directories.
|
Search through, and load from, a list of plugin directories.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
plugin_dirs (list): List of strings of plugin directories.
|
plugin_paths (list): List of strings of plugin directories.
|
||||||
include_default (bool): Also load plugins from the module default directory (DEFAULT_PLUGIN_PATH)
|
include_default (bool): Also load plugins from the module default directory (DEFAULT_PLUGIN_PATH)
|
||||||
"""
|
"""
|
||||||
global DEFAULT_PLUGIN_PATH
|
global DEFAULT_PLUGIN_PATH
|
||||||
|
|
||||||
if include_default: # If including default plugins
|
if include_default: # If including default plugins
|
||||||
plugin_dirs.append(DEFAULT_PLUGIN_PATH) # Add default directory to the search paths
|
plugin_paths.append(DEFAULT_PLUGIN_PATH) # Add default directory to the search paths
|
||||||
|
|
||||||
logging.debug(plugin_dirs)
|
logging.debug(plugin_paths)
|
||||||
|
|
||||||
plugins = [] # List of loaded plugins
|
plugins = [] # List of loaded plugins
|
||||||
for plugin_dir in plugin_dirs: # For each plugin directory
|
for plugin_dir in plugin_paths: # For each plugin directory
|
||||||
logging.debug("Searching {}".format(plugin_dir))
|
logging.debug("Searching {}".format(plugin_dir))
|
||||||
plugins.extend(find_plugins(plugin_dir)) # Find plugin folders, and load into list
|
plugins.extend(find_plugins(plugin_dir)) # Find plugin folders, and load into list
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
from openflexure_microscope.camera.pi import StreamingCamera
|
from openflexure_microscope.camera.pi import StreamingCamera
|
||||||
from openflexure_stage import OpenFlexureStage
|
from openflexure_stage import OpenFlexureStage
|
||||||
from openflexure_microscope import Microscope
|
from openflexure_microscope import Microscope
|
||||||
from openflexure_microscope.plugins import PluginMount, load_plugin, search_plugin_dirs
|
from openflexure_microscope.plugins import PluginMount, load_plugin, search_plugin_paths
|
||||||
|
|
||||||
import atexit
|
import atexit
|
||||||
import logging, sys
|
import logging, sys
|
||||||
|
|
@ -11,11 +11,7 @@ logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
microscope = Microscope(StreamingCamera(), OpenFlexureStage("/dev/ttyUSB0"))
|
microscope = Microscope(StreamingCamera(), OpenFlexureStage("/dev/ttyUSB0"))
|
||||||
|
|
||||||
plugins_list = search_plugin_dirs([], include_default=True)
|
microscope.find_plugins() # Automatically find microscope plugins
|
||||||
|
|
||||||
for i in plugins_list:
|
|
||||||
module = load_plugin(i)
|
|
||||||
microscope.plugin.attach(module)
|
|
||||||
|
|
||||||
# Check that default tets plugins have loaded
|
# Check that default tets plugins have loaded
|
||||||
print("RUNNING PLUGIN METHODS:")
|
print("RUNNING PLUGIN METHODS:")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue