Пример #1
0
    def _start_www(self):
        """Starts web server"""
        self.web_dir = config.get_work_folder_path()
        ip_address = MainWindow.get_ip()
        port_number = config.get_www_server_port_number()
        try:
            self.thread = StoppableServerThread(self.web_dir)
            self.thread.start()

            # Server is now started and listens on specified port on *all* available interfaces.
            # We get the machine ip address and warn user if detected ip is loopback (127.0.0.1)
            # since in this case, the web server won't be reachable by any other machine
            if ip_address == "127.0.0.1":
                log_function = _LOGGER.warning
                title = "Web server access is limited"
                message = "Web server IP address is 127.0.0.1.\n\nServer won't be reachable by other " \
                          "machines. Please check your network connection"
                warning_box(title, message)
            else:
                log_function = _LOGGER.info

            log_function(
                f"Web server started. http://{ip_address}:{port_number}")
            self._ui.action_prefs.setEnabled(False)
        except OSError:
            title = "Could not start web server"
            message = f"The web server needs to listen on port n°{port_number} but this port is already in use.\n\n"
            message += "Please change web server port number in your preferences "
            _LOGGER.error(title)
            error_box(title, message)
            self._stop_www()
            self._ui.cbWww.setChecked(False)
Пример #2
0
    def start_www(self):
        """Starts web server"""

        work_folder = config.get_work_folder_path()
        ip_address = get_ip()
        port_number = config.get_www_server_port_number()

        # setup work folder
        try:
            Controller._setup_web_content()
        except OSError as os_error:
            raise WebServerStartFailure("Work folder could not be prepared",
                                        str(os_error))

        try:
            self._web_server = WebServer(work_folder)
            self._web_server.start()

            if ip_address == "127.0.0.1":
                log_function = _LOGGER.warning
            else:
                log_function = _LOGGER.info

            url = f"http://{ip_address}:{port_number}"
            log_function(f"Web server started. Reachable at {url}")

            DYNAMIC_DATA.web_server_ip = ip_address
            DYNAMIC_DATA.web_server_is_running = True
            self._notify_model_observers()

        except OSError as os_error:
            title = "Could not start web server"
            _LOGGER.error(f"{title} : {os_error}")
            raise WebServerStartFailure(title, str(os_error))
Пример #3
0
 def cb_apply_value(self):
     """Qt slot for clicks on the 'apply' button"""
     work_folder = config.get_work_folder_path()
     if self.counter > 0:
         self.adjust_value(work_folder)
         self.update_image(False)
     self._ui.log.append(_("Define new display value"))
Пример #4
0
 def _setup_work_folder(self):
     """Prepares the work folder."""
     work_dir_path = config.get_work_folder_path()
     resources_dir_path = os.path.dirname(
         os.path.realpath(__file__)) + "/../resources"
     shutil.copy(resources_dir_path + "/index.html", work_dir_path)
     shutil.copy(resources_dir_path + "/waiting.jpg",
                 work_dir_path + "/" + NAME_OF_JPEG_IMAGE)
Пример #5
0
    def __init__(self, parent=None):
        super().__init__(parent)
        self._ui = Ui_PrefsDialog()
        self._ui.setupUi(self)

        self._ui.ln_scan_folder_path.setText(config.get_scan_folder_path())
        self._ui.ln_work_folder_path.setText(config.get_work_folder_path())
        self._ui.ln_web_server_port.setText(str(config.get_www_server_port_number()))
        self._ui.chk_debug_logs.setChecked(config.is_debug_log_on())
Пример #6
0
 def cb_save(self):
     """Qt slot for louse clicks on the 'save' button."""
     timestamp = str(
         datetime.fromtimestamp(datetime.timestamp(datetime.now())))
     self._ui.log.append(
         _("Saving : ") + "stack_image_" + timestamp + ".fit")
     # save stack image in fit
     red = fits.PrimaryHDU(data=self.image_ref_save.image)
     red.writeto(config.get_work_folder_path() + "/" + "stack_image_" +
                 timestamp + ".fit")
     # red.close()
     del red
Пример #7
0
    def cb_save(self):
        """
        Qt slot for mouse clicks on the 'save' button.

        This saves the processed image using user chosen format

        """
        image_to_save = DYNAMIC_DATA.post_processor_result
        if image_to_save is not None:
            self._controller.save_image(
                image_to_save,
                config.get_image_save_format(),
                config.get_work_folder_path(),
                als.model.data.STACKED_IMAGE_FILE_NAME_BASE,
                add_timestamp=True)
Пример #8
0
    def save_post_process_result(self):
        """
        Saves stacking result image to disk
        """

        # we save the image no matter what, then save a jpg for the web server if it is running
        image = DYNAMIC_DATA.post_processor_result

        self.save_image(image, config.get_image_save_format(),
                        config.get_work_folder_path(),
                        als.model.data.STACKED_IMAGE_FILE_NAME_BASE)

        if DYNAMIC_DATA.web_server_is_running:
            self.save_image(image, als.model.data.IMAGE_SAVE_TYPE_JPEG,
                            config.get_work_folder_path(),
                            als.model.data.WEB_SERVED_IMAGE_FILE_NAME_BASE)

        # if user want to save every image, we save a timestamped version
        if self._save_every_image:
            self.save_image(image,
                            config.get_image_save_format(),
                            config.get_work_folder_path(),
                            als.model.data.STACKED_IMAGE_FILE_NAME_BASE,
                            add_timestamp=True)
Пример #9
0
    def start_session(self):
        """
        Starts session
        """
        try:
            if DYNAMIC_DATA.session.is_stopped:

                _LOGGER.info("Starting new session...")

                self._stacker.reset()

                folders_dict = {
                    "scan": config.get_scan_folder_path(),
                    "work": config.get_work_folder_path()
                }

                # checking presence of both scan & work folders
                for role, path in folders_dict.items():
                    if not Path(path).is_dir():
                        title = "Missing critical folder"
                        message = f"Your currently configured {role} folder '{path}' is missing."
                        raise CriticalFolderMissing(title, message)

            else:
                # session was paused when this start was ordered. No need for checks & setup
                _LOGGER.info("Restarting input scanner ...")

            # start input scanner
            try:
                self._input_scanner.start()
                _LOGGER.info("Input scanner started")
            except ScannerStartError as scanner_start_error:
                raise SessionError("Input scanner could not start",
                                   scanner_start_error)

            running_mode = f"{self._stacker.stacking_mode}"
            running_mode += " with alignment" if self._stacker.align_before_stack else " without alignment"
            _LOGGER.info(f"Session running in mode {running_mode}")
            DYNAMIC_DATA.session.set_status(Session.running)

        except SessionError as session_error:
            _LOGGER.error(
                f"Session error. {session_error.message} : {session_error.details}"
            )
            raise
Пример #10
0
    def _setup_web_content():
        """Prepares the work folder."""

        work_dir_path = config.get_work_folder_path()
        resources_dir_path = os.path.dirname(
            os.path.realpath(__file__)) + "/../resources"

        with open(resources_dir_path + "/index.html", 'r') as file:
            index_content = file.read()

        index_content = index_content.replace(
            '##PERIOD##', str(config.get_www_server_refresh_period()))

        with open(work_dir_path + "/index.html", 'w') as file:
            file.write(index_content)

        standby_image_path = work_dir_path + "/" + als.model.data.WEB_SERVED_IMAGE_FILE_NAME_BASE
        standby_image_path += '.' + als.model.data.IMAGE_SAVE_TYPE_JPEG
        shutil.copy(resources_dir_path + "/waiting.jpg", standby_image_path)
Пример #11
0
    def __init__(self, parent=None):
        super().__init__(parent)
        self._ui = Ui_PrefsDialog()
        self._ui.setupUi(self)

        self._ui.ln_scan_folder_path.setText(config.get_scan_folder_path())
        self._ui.ln_work_folder_path.setText(config.get_work_folder_path())
        self._ui.ln_web_server_port.setText(
            str(config.get_www_server_port_number()))
        self._ui.spn_webpage_refresh_period.setValue(
            config.get_www_server_refresh_period())
        self._ui.chk_debug_logs.setChecked(config.is_debug_log_on())

        config_to_image_save_type_mapping = {
            als.model.data.IMAGE_SAVE_TYPE_JPEG: self._ui.radioSaveJpeg,
            als.model.data.IMAGE_SAVE_TYPE_PNG: self._ui.radioSavePng,
            als.model.data.IMAGE_SAVE_TYPE_TIFF: self._ui.radioSaveTiff
        }

        config_to_image_save_type_mapping[
            config.get_image_save_format()].setChecked(True)

        self._show_missing_folders()
Пример #12
0
    def cb_play(self):
        """Qt slot for mouse clicks on the 'play' button"""

        # check existence of work and scan folders
        scan_folder_path = config.get_scan_folder_path()
        if not os.path.exists(scan_folder_path) or not os.path.isdir(
                scan_folder_path):
            if question(
                    "Scan folder issue",
                    f"Your configured scan folder '{scan_folder_path}' is missing.\n"
                    f"Do you want to open preferences screen ?"):
                self.cb_prefs()
            else:
                return

        work_folder_path = config.get_work_folder_path()
        if not os.path.exists(work_folder_path) or not os.path.isdir(
                work_folder_path):
            if question(
                    "Work folder issue",
                    f"Your configured work folder '{work_folder_path}' is missing.\n"
                    f"Do you want to open preferences screen ?"):
                self.cb_prefs()
            else:
                return

        if self.image_ref_save.status == "stop":
            self._ui.white_slider.setEnabled(False)
            self._ui.black_slider.setEnabled(False)
            self._ui.contrast_slider.setEnabled(False)
            self._ui.brightness_slider.setEnabled(False)
            self._ui.R_slider.setEnabled(False)
            self._ui.G_slider.setEnabled(False)
            self._ui.B_slider.setEnabled(False)
            self._ui.pb_apply_value.setEnabled(False)
            self._ui.cbAlign.setEnabled(False)
            self._ui.cmMode.setEnabled(False)
            self._ui.image_stack.setPixmap(QPixmap(":/icons/dslr-camera.svg"))
            self.counter = 0
            self._ui.cnt.setText(str(self.counter))
            # Print scan folder
            self._ui.log.append(
                _("Scan folder : ") + config.get_scan_folder_path())
            # Print work folder
            self._ui.log.append(
                _("Work folder : ") + config.get_work_folder_path())

        # check align
        if self._ui.cbAlign.isChecked():
            self.align = True

        # Print live method
        if self.align:
            self._ui.log.append(
                _("Play with alignement type: ") +
                self._ui.cmMode.currentText())
        else:
            self._ui.log.append(_("Play with NO alignement"))

        self.file_watcher = WatchOutForFileCreations(
            config.get_scan_folder_path(), config.get_work_folder_path(),
            self.align, self._ui.cbKeep.isChecked(),
            self._ui.cmMode.currentText(), self._ui.log, self._ui.white_slider,
            self._ui.black_slider, self._ui.contrast_slider,
            self._ui.brightness_slider, self._ui.R_slider, self._ui.G_slider,
            self._ui.B_slider, self._ui.pb_apply_value, self.image_ref_save,
            self._ui.cbSCNR, self._ui.cmSCNR, self._ui.SCNR_Slider,
            self._ui.cbWavelets, self._ui.cBoxWaveType,
            self._ui.cbLuminanceWavelet, self._ui.wavelet_1_label,
            self._ui.wavelet_2_label, self._ui.wavelet_3_label,
            self._ui.wavelet_4_label, self._ui.wavelet_5_label)

        try:
            self._setup_work_folder()
        except OSError as os_error:
            title = "Work folder could not be prepared"
            message = f"Details : {os_error}"
            error_box(title, message)
            _LOGGER.error(f"{title} : {os_error}")
            self.cb_stop()
            return

        self.file_watcher.start()
        self.file_watcher.print_image.connect(
            lambda: self.update_image(config.get_work_folder_path()))

        self.image_ref_save.status = "play"
        self.image_ref_save.image = None
        self.image_ref_save.stack_image = None
        # deactivate play button
        self._ui.pbPlay.setEnabled(False)
        self._ui.pbReset.setEnabled(False)
        # activate stop button
        self._ui.pbStop.setEnabled(True)
        # activate pause button
        self._ui.pbPause.setEnabled(True)

        self._ui.action_prefs.setEnabled(False)