def create_work_item_list(
            self, data_model: DataModel,
            table_model: SessionPlanTableModel) -> [WorkItem]:
        """Create the list of work items from the session plan"""

        result: [WorkItem] = []
        model_rows: int = table_model.rowCount(
            QModelIndex(), ) if data_model.get_use_filter_wheel() else 1
        model_columns: int = table_model.columnCount(QModelIndex())

        # Every combination of row and column with a nonzero entry is a work item
        for row_index in range(model_rows):
            for column_index in range(model_columns):
                index = table_model.createIndex(row_index, column_index)
                cell_value = int(table_model.data(index, Qt.DisplayRole))
                if cell_value != 0:
                    raw_row_index: int = data_model.map_display_to_raw_filter_index(
                        row_index)
                    raw_column_index: int = data_model.map_display_to_raw_binning_index(
                        column_index)
                    filter_spec: FilterSpec = data_model.get_filter_specs(
                    )[raw_row_index]

                    binning: BinningSpec = data_model.get_binning_specs(
                    )[raw_column_index]

                    work_item = WorkItem(cell_value, filter_spec,
                                         binning.get_binning_value(),
                                         data_model.get_target_adus(),
                                         data_model.get_adu_tolerance(),
                                         self._preferences)
                    result.append(work_item)
        return result
Exemple #2
0
    def set_ui_from_data_model(self, data_model: DataModel):
        """Set the fields in the UI from the given data model"""
        # Server address and port
        self.ui.serverAddress.setText(data_model.get_server_address())
        self.ui.portNumber.setText(str(data_model.get_port_number()))
        self.respond_to_server_locality(data_model.get_server_address())

        # Target ADU and tolerance
        self.ui.targetAdus.setText(str(data_model.get_target_adus()))
        adu_tol = data_model.get_adu_tolerance()
        self.ui.aduTolerance.setText(str(adu_tol * 100.0))

        # Warm up when done?
        self.ui.warmWhenDone.setChecked(data_model.get_warm_when_done())

        # Filter wheel
        self.ui.useFilterWheel.setChecked(data_model.get_use_filter_wheel())

        # Remote or local server?
        self.ui.useLocal.setChecked(data_model.get_save_files_locally())
        self.ui.useAutosave.setChecked(not data_model.get_save_files_locally())
        self.ui.pathName.setText(data_model.get_local_path() if data_model.
                                 get_save_files_locally() else "")

        # Mount control
        self.ui.controlMount.setChecked(data_model.get_control_mount())
        self.ui.homeMount.setChecked(data_model.get_home_mount())
        self.ui.parkWhenDone.setChecked(data_model.get_park_when_done())
        self.ui.trackingOff.setChecked(data_model.get_tracking_off())

        # Dithering
        self.ui.ditherFlats.setChecked(data_model.get_dither_flats())
        self.ui.ditherRadius.setText(str(data_model.get_dither_radius()))
        self.ui.ditherMaxRadius.setText(str(
            data_model.get_dither_max_radius()))

        # Slew to light source before acquiring frames?
        slew_to_source = data_model.get_slew_to_light_source()
        self.ui.slewToSource.setChecked(slew_to_source)
        self.ui.sourceAlt.setText(str(round(data_model.get_source_alt(), 5)))
        self.ui.sourceAz.setText(str(round(data_model.get_source_az(), 5)))

        # Set up table model representing the session plan, and connect it to the table

        self._table_model = SessionPlanTableModel(data_model,
                                                  self._preferences,
                                                  self.set_is_dirty,
                                                  self.set_field_validity)
        self.ui.sessionPlanTable.setModel(self._table_model)

        self.enable_proceed_button()
        self.enable_slew_button()
        self.enable_mount_controls()