Module pipettin-piper.piper.plugins.example_tools

Functions

def load_plugin(controller: "'Controller'", **kwargs)
Expand source code
def load_plugin(controller: "Controller", **kwargs):
    """Instantiate the plugin, which also registers the tools.
    Plugins are expected to have a function named 'load_plugin' which will 
    instantiate the plugin's class and returning it to the main Commander class.
    If they fail to load, they must raise a PluginError exception.
    """
    logging.debug(f"load_plugin: loading {plugin_name} plugin.")
    try:
        class_instance = ToolHandler(controller)
    except Exception as e:
        msg = f"Failed to load with error: {e}"
        logging.error(msg)
        raise PluginError(msg) from e

    return class_instance

Instantiate the plugin, which also registers the tools. Plugins are expected to have a function named 'load_plugin' which will instantiate the plugin's class and returning it to the main Commander class. If they fail to load, they must raise a PluginError exception.

Classes

class ToolHandler (controller: Controller = None)
Expand source code
class ToolHandler(Plugin):
    """Generic tool-loading plugin"""
    def __init__(self, controller: Controller = None):

        self.controller: Controller = controller
        self.builder: GcodeBuilder = self.controller.builder
        self.gcode: GcodePrimitives = self.builder.gcode
        self.verbose: bool = self.builder.verbose

        # Dictionary with python 'tool' objects in its values.
        self.tools = {}

        # Register the tool loader function.
        logging.info("Registering tool loader function.")
        self.builder.register_tool_loader(
            tool_type=TOOL_TYPE,
            loader_function=self.load_tool)

        # List of available macros for the requested actions.
        self.action_switch_case = {
            self.example_cmd: self.macroDummy
        }

        # Register each handler in the GcodeBuilder.
        logging.info("Registering action handlers.")
        for name, function in self.action_switch_case.items():
            self.builder.add_action_handler(name, function)

        # Set status.
        self._status = True

    def load_tool(self, tool_data: dict):
        """Instantiate and save one Tool from a parameter set.
        This is a tool loader function for GcodeBuilder.
        """
        tool_name = tool_data["name"]
        logging.info(f"Loading tool '{tool_name}'.")

        # Check if the tool is already registered locally.
        if tool_name in self.tools:
            msg = f"Tool '{tool_name}' is already in the tool handler's list."
            logging.error(msg)
            raise DataError(msg)

        # Load the tool.
        try:
            # Instance the tool and save it internally for reference.
            tool = Tool(tool_data, self.builder)
            self.tools[tool_name] = tool
        except Exception as e:
            msg = f"Failed to initialize tool '{tool_name}' with error: {e}"
            logging.error(msg)
            raise CommanderError(msg) from e

        # Return the tool instance to the gcode builder class.
        return tool

    example_cmd = "DUMMY"
    def macroDummy(self, action, i, operation_time=10.0):
        """Move over a content."""
        try:
            # Move over the target content.
            self.builder.macroGoToTubeXY(action, i)

            # Extend the operation time.
            self.controller.machine.update_exec_opts(action, timeout=operation_time, add_timeout=True)
        except Exception as e:
            raise ProtocolError(f"{self.example_cmd} failed.") from e

Generic tool-loading plugin

Ancestors

Class variables

var example_cmd

Methods

def load_tool(self, tool_data: dict)
Expand source code
def load_tool(self, tool_data: dict):
    """Instantiate and save one Tool from a parameter set.
    This is a tool loader function for GcodeBuilder.
    """
    tool_name = tool_data["name"]
    logging.info(f"Loading tool '{tool_name}'.")

    # Check if the tool is already registered locally.
    if tool_name in self.tools:
        msg = f"Tool '{tool_name}' is already in the tool handler's list."
        logging.error(msg)
        raise DataError(msg)

    # Load the tool.
    try:
        # Instance the tool and save it internally for reference.
        tool = Tool(tool_data, self.builder)
        self.tools[tool_name] = tool
    except Exception as e:
        msg = f"Failed to initialize tool '{tool_name}' with error: {e}"
        logging.error(msg)
        raise CommanderError(msg) from e

    # Return the tool instance to the gcode builder class.
    return tool

Instantiate and save one Tool from a parameter set. This is a tool loader function for GcodeBuilder.

def macroDummy(self, action, i, operation_time=10.0)
Expand source code
def macroDummy(self, action, i, operation_time=10.0):
    """Move over a content."""
    try:
        # Move over the target content.
        self.builder.macroGoToTubeXY(action, i)

        # Extend the operation time.
        self.controller.machine.update_exec_opts(action, timeout=operation_time, add_timeout=True)
    except Exception as e:
        raise ProtocolError(f"{self.example_cmd} failed.") from e

Move over a content.

Inherited members