Exemplo n.º 1
0
    def startFilm(self, film_settings=None):
        # Disable live mode check box
        self.ui.liveModeCheckBox.setEnabled(False)

        # Pause live view mode (if running)
        if self.ui.liveModeCheckBox.isChecked():
            self.stopCamera()
        self.stopLiveView()

        self.filming = True
        self.film_name = os.path.join(self.parameters.get("film.directory"),
                                      str(self.ui.filenameLabel.text()))
        self.film_name = self.film_name[:-len(self.ui.filetypeComboBox.
                                              currentText())]

        if film_settings is None:
            film_settings = filmSettings.FilmSettings(
                self.parameters.get("film.acq_mode"),
                self.parameters.get("film.frames"))
            save_film = self.ui.saveMovieCheckBox.isChecked()
        else:
            save_film = True

        self.writer = None
        self.ui.recordButton.setText("Stop")
        try:
            # Film file prep
            if save_film:
                self.writer = writers.createFileWriter(
                    self.ui.filetypeComboBox.currentText(), self.film_name,
                    self.parameters, self.camera.getFeedNamesToSave())
                self.camera.startFilm(self.writer, film_settings)
                self.ui.recordButton.setStyleSheet(
                    "QPushButton { color: red }")
            else:
                self.camera.startFilm(None, film_settings)
                self.ui.recordButton.setStyleSheet(
                    "QPushButton { color: orange }")
                self.film_name = False

            # Modules.
            for module in self.modules:
                module.startFilm(self.film_name,
                                 self.ui.autoShuttersCheckBox.isChecked())

        except halModule.StartFilmException as error:  # Handle any start Film errors
            error_message = "startFilm() in HAL encountered an error: \n" + str(
                error)
            hdebug.logText(error_message)

            # Handle error returning to Dave. The subsequent call to stopFilm() will handle sending this message
            if self.tcp_requested_movie:
                message = self.tcp_message
                message.setError(True, error_message)

        # Disable parameters radio buttons.
        self.parameters_box.startFilm()

        # go...
        self.startCamera()
Exemplo n.º 2
0
    def startFilm(self, film_settings = None):
        self.filming = True
        self.film_name = self.parameters.get("directory") + str(self.ui.filenameLabel.text())
        self.film_name = self.film_name[:-len(self.ui.filetypeComboBox.currentText())]

        if not film_settings:
            film_settings = filmSettings.FilmSettings(self.parameters.get("acq_mode"),
                                                      self.parameters.get("frames"))
            save_film = self.ui.saveMovieCheckBox.isChecked()
        else:
            save_film = True

        # Film file prep.
        self.writer = False
        self.ui.recordButton.setText("Stop")
        if save_film:
            if (self.ui_mode == "dual"):
                self.writer = writers.createFileWriter(self.ui.filetypeComboBox.currentText(),
                                                       self.film_name,
                                                       self.parameters,
                                                       ["camera1", "camera2"])
            else:
                self.writer = writers.createFileWriter(self.ui.filetypeComboBox.currentText(),
                                                       self.film_name,
                                                       self.parameters,
                                                       ["camera1"])
            self.camera.startFilm(self.writer, film_settings)
            self.ui.recordButton.setStyleSheet("QPushButton { color: red }")
        else:
            self.camera.startFilm(None, film_settings)
            self.ui.recordButton.setStyleSheet("QPushButton { color: orange }")
            self.film_name = False

        # Modules.
        for module in self.modules:
            module.startFilm(self.film_name, self.ui.autoShuttersCheckBox.isChecked())

        # Disable parameters radio buttons.
        self.parameters_box.startFilm()

        # Enable record button so that TCP requested films can be stopped.
        #if self.tcp_requested_movie:
        #    self.ui.recordButton.setEnabled(True)

        # go...
        self.startCamera()
Exemplo n.º 3
0
    def handleCommMessage(self, message):

        # Handle abort request.
        if (message.getType() == "Abort Movie"):
            if self.tcp_message:
                if self.tcp_message.getType() == "Take Movie":
                    self.tcp_message.addResponse("aborted", True)
            if self.filming:
                self.stopFilm()
            return

        # Reject message if Hal is filming.
        #
        # FIXME: Why? We used to allow this so that we could remotely set
        #    and adjust the power while filming.
        #
        if self.filming:
            message.setError(True, "Hal is filming")
            self.tcpComplete.emit(message)
            return

        # Handle mosaic information request, pass mosaic XML data back:
        elif (message.getType() == "Get Mosaic Settings"):
            #message.addResponse("pixels_to_um", self.parameters.get("mosaic.pixels_to_um"))
            i = 1
            while self.parameters.has("mosaic.obj" + str(i)):
                message.addResponse("obj" + str(i),
                                    self.parameters.get("mosaic.obj" + str(i)))
                i += 1
            self.tcpComplete.emit(message)

        # Return the current objective.
        elif (message.getType() == "Get Objective"):
            obj_data = self.parameters.get(
                "mosaic." + self.parameters.get("mosaic.objective"))
            message.addResponse("objective", obj_data.split(",")[0])
            self.tcpComplete.emit(message)

        # Handle set directory request:
        elif (message.getType() == "Set Directory"):

            if message.isTest():
                # Check that the directory exists.
                self.directory_test_mode = message.getData("directory")
                if not os.path.isdir(self.directory_test_mode):
                    message.setError(
                        True,
                        str(self.directory_test_mode) +
                        " is an invalid directory")

            else:
                # Change directory if requested.
                new_directory = message.getData("directory")
                if not os.path.isdir(new_directory):
                    message.setError(
                        True,
                        str(new_directory) + " is an invalid directory")
                else:
                    self.newDirectory(new_directory)

            self.tcpComplete.emit(message)

        # Handle set parameters request.
        elif (message.getType() == "Set Parameters"):
            param_index = message.getData("parameters")
            if message.isTest():
                if not self.parameters_box.isValidParameters(param_index):
                    message.setError(
                        True,
                        str(param_index) + " is an invalid parameters option")
                    self.tcpComplete.emit(message)

                # Save parameters to keep track of parameter trajectory for accurate time and disk estimates.
                else:
                    self.parameters_test_mode = self.parameters_box.getParameters(
                        param_index)
                    if not self.parameters_test_mode.get("initialized"):
                        self.tcp_message = message  # Store message so that it can be returned.
                        self.parameters_box.setCurrentParameters(param_index)
                    else:
                        self.tcpComplete.emit(message)

            else:
                # Set parameters, double check before filming.
                if self.parameters_box.isValidParameters(param_index):
                    self.tcp_message = message
                    if self.parameters_box.setCurrentParameters(param_index):
                        self.tcp_message = None
                        self.tcpComplete.emit(message)
                else:
                    message.setError(
                        True,
                        str(param_index) + " is an invalid parameters option")
                    self.tcpComplete.emit(message)

        # Handle movie request.
        elif (message.getType() == "Take Movie"):

            # Check length (independent of whether the message is a test).
            if (message.getData("length")
                    == None) or (message.getData("length") < 1):
                message.setError(
                    True,
                    str(message.getData("length")) +
                    "is an invalid movie length")
                self.tcpComplete.emit(message)
                return

            # Check file overwrite (independence of whether the message is a test)
            if not (message.getData("overwrite")
                    == None) and (message.getData("overwrite") == False):
                file_path = self.directory_test_mode + os.sep + message.getData(
                    "name") + self.parameters.get("film.filetype")
                if os.path.exists(file_path):
                    message.setError(True, file_path + " will be overwritten")
                    self.tcpComplete.emit(message)
                    return

            if message.isTest():
                # Set parameters
                if self.parameters_test_mode:
                    parameters = self.parameters_test_mode
                else:
                    parameters = self.parameters

                # Get disk usage and duration.
                num_frames = message.getData("length")
                message.addResponse(
                    "duration",
                    num_frames * parameters.get("seconds_per_frame"))
                mega_bytes_per_frame = parameters.get(
                    "camera1.bytes_per_frame"
                ) * 1.0 / 2**20  # Convert to megabytes.
                message.addResponse("disk_usage",
                                    mega_bytes_per_frame * num_frames)
                self.tcpComplete.emit(message)

            else:  # Take movie.

                # Set filename.
                self.ui.filenameLabel.setText(
                    message.getData("name") +
                    self.parameters.get("film.filetype"))

                # Record current length and set film length spin box to requested length.
                self.current_length = self.parameters.get("film.frames")
                self.ui.lengthSpinBox.setValue(message.getData("length"))

                # Start the film.
                self.tcp_requested_movie = True
                self.tcp_message = message
                self.startFilm(
                    filmSettings.FilmSettings("fixed_length",
                                              message.getData("length")))
Exemplo n.º 4
0
    def handleCommMessage(self, message):

        # Handle abort request.
        if (message.getType() == "Abort Movie"):
            if self.tcp_message:
                if self.tcp_message.getType() == "Take Movie":
                    self.tcp_message.addResponse("aborted", True)
            if self.filming:
                self.stopFilm()
            return

        # Reject message if Hal is filming.
        #
        # FIXME: Why? We used to allow this so that we could remotely set
        #    and adjust the power while filming.
        #
        if self.filming: 
            message.setError(True, "Hal is filming")
            self.tcpComplete.emit(message)
            return

        # Handle set directory request:
        elif (message.getType() == "Set Directory"):

            if message.isTest():
                # Check that the directory exists.
                self.directory_test_mode = message.getData("directory")
                if not os.path.isdir(self.directory_test_mode):
                    message.setError(True, str(self.directory_test_mode) + " is an invalid directory")

            else:
                # Change directory if requested.
                new_directory = message.getData("directory")
                if not os.path.isdir(new_directory):
                    message.setError(True, str(new_directory) + " is an invalid directory")
                else:
                    self.newDirectory(new_directory)

            self.tcpComplete.emit(message)

        # Handle set parameters request.
        elif (message.getType() == "Set Parameters"):
            param_index = message.getData("parameters")
            if message.isTest():
                if not self.parameters_box.isValidParameters(param_index):
                    message.setError(True, str(param_index) + " is an invalid parameters option")
                    self.tcpComplete.emit(message)

                # Save parameters to keep track of parameter trajectory for accurate time and disk estimates.
                else:
                    self.parameters_test_mode = self.parameters_box.getParameters(param_index)
                    if not self.parameters_test_mode.initialized:
                        self.tcp_message = message # Store message so that it can be returned.
                        self.parameters_box.setCurrentParameters(param_index)
                    else:
                        self.tcpComplete.emit(message)

            else:
                # Set parameters, double check before filming.
                if self.parameters_box.isValidParameters(param_index):
                    self.tcp_message = message
                    if self.parameters_box.setCurrentParameters(param_index):
                        self.tcp_message = None
                        self.tcpComplete.emit(message)
                else:
                    message.setError(True, str(param_index) + " is an invalid parameters option")
                    self.tcpComplete.emit(message)
        
        # Handle movie request.
        elif (message.getType() == "Take Movie"):

            if message.isTest():

                #
                # FIXME: Shouldn't we also check these things when we are actually acquiring?
                #

                # Check length.
                if (message.getData("length") == None) or (message.getData("length") < 1):
                    message.setError(True, str(message.getData("length")) + "is an invalid movie length")
                    self.tcpComplete.emit(message)
                    return

                # Check file overwrite.
                if not (message.getData("overwrite") == None) and (message.getData("overwrite") == False):
                    file_path = self.directory_test_mode + os.sep + message.getData("name") + self.parameters.filetype
                    if os.path.exists(file_path):
                        message.setError(True, file_path + " will be overwritten")
                        self.tcpComplete.emit(message)
                        return

                # Set parameters
                if self.parameters_test_mode:
                    parameters = self.parameters_test_mode
                else:
                    parameters = self.parameters
                
                # Get disk usage and duration.
                num_frames = message.getData("length")
                message.addResponse("duration", num_frames * parameters.kinetic_value)
                mega_bytes_per_frame = parameters.bytesPerFrame * 1.0/2**20 # Convert to megabytes.
                message.addResponse("disk_usage", mega_bytes_per_frame * num_frames)
                self.tcpComplete.emit(message)

            else: # Take movie.

                # Set filename.
                self.ui.filenameLabel.setText(message.getData("name") + self.parameters.filetype)
                
                # Record current length and set film length spin box to requested length.
                self.current_length = self.parameters.get("frames")
                self.ui.lengthSpinBox.setValue(message.getData("length"))

                # Start the film.
                self.tcp_requested_movie = True
                self.tcp_message = message
                self.startFilm(filmSettings.FilmSettings("fixed_length", message.getData("length")))