Commit a1f27b00 authored by Samuel McDermott's avatar Samuel McDermott
Browse files

Move set_stage into a new function

parent d0b79584
Loading
Loading
Loading
Loading
+48 −18
Original line number Diff line number Diff line
@@ -105,10 +105,46 @@ class Microscope:
                    logging.warning("No compatible camera hardware found.")

        ### Stage
        logging.info("Creating stage")
        if configuration.get("stage"):
        self.set_stage(configuration=configuration)
                 

        logging.info("Handling fallbacks")
        ### Fallbacks
        if not self.camera:
            self.camera = MissingCamera()
        if not self.stage:
            self.stage = MissingStage()

        ### Locks
        logging.info("Creating locks")
        if hasattr(self.camera, "lock"):
            self.lock.locks.append(self.camera.lock)
        if hasattr(self.stage, "lock"):
            self.lock.locks.append(self.stage.lock)

    def set_stage(self, configuration=None, stage_type=None):
        """
        Set or change the stage geometry
        """
        if not configuration:
            configuration = self.configuration

        if stage_type:
            if stage_type == configuration["stage"].get("type"):
                    logging.info("Stage already set to that stage type")
                    return
        else:
            stage_type = configuration["stage"].get("type")
        
        ### Close any existing stages
        if self.stage:
                stage_port = self.stage.port
                self.stage.close()


        logging.info("Setting stage")
        stage_port = configuration["stage"].get("port")             
                    
        if stage_type in ("SangaBoard", "SangaStage"):
            try:
                logging.info("Trying SangaStage")
@@ -120,23 +156,16 @@ class Microscope:
            try:
                logging.info("Trying SangaDeltaStage")
                self.stage = SangaDeltaStage(port=stage_port)
                
            except Exception as e:
                logging.error(e)
                logging.warning("No compatible Sangaboard hardware found.")
        else:
            logging.warning("The stage type is incorrectly defined.")   

        logging.info("Handling fallbacks")
        ### Fallbacks
        if not self.camera:
            self.camera = MissingCamera()
        if not self.stage:
            self.stage = MissingStage()

        ### Locks
        logging.info("Creating locks")
        if hasattr(self.camera, "lock"):
            self.lock.locks.append(self.camera.lock)
        if hasattr(self.stage, "lock"):
            self.lock.locks.append(self.stage.lock)
        logging.info("Saving new stage type configuration")
        configuration["stage"]["type"] = stage_type
        self.configuration_file.save(configuration)
        
    def has_real_stage(self) -> bool:
        """
@@ -363,6 +392,7 @@ class Microscope:

            # Capture to output object
            logging.info(f"Starting microscope capture {output.file}")
            print(output)
            self.camera.capture(
                output,
                use_video_port=use_video_port,