Beispiel #1
0
    def __init__(self, target):
        """
        Initialize the dialog.

        Args:
            target: Target object.
        """
        super().__init__()
        uic.loadUi(gutils.get_ui_dir() / "ui_target_info.ui", self)

        self.target = target

        self.okPushButton.clicked.connect(self.__accept_settings)
        self.cancelPushButton.clicked.connect(self.close)

        self.fields_are_valid = False
        iv.set_input_field_red(self.nameLineEdit)
        self.nameLineEdit.textChanged.connect(
            lambda: iv.check_text(self.nameLineEdit, qwidget=self))
        self.nameLineEdit.textEdited.connect(
            lambda: iv.sanitize_file_name(self.nameLineEdit))
        self.nameLineEdit.setEnabled(False)

        self.name = ""
        self.nameLineEdit.setText(target.name)
        self.descriptionLineEdit.setPlainText(target.description)
        self.description = ""
        self.isOk = False

        self.dateLabel.setText(time.strftime("%c %z %Z", time.localtime(
            target.modification_time)))

        self.__close = True

        self.exec_()
Beispiel #2
0
    def __init__(self, tmp_foils, tmp_index, icon_manager):
        """ Initializes the Foil Dialog.
        Args:
            tmp_foils: Foil object list.
            tmp_index: Index of the Foil object in tmp_foils.
            icon_manager: Icon manager for TargetCompositionWidget.
        """
        super().__init__()
        uic.loadUi(gutils.get_ui_dir() / "ui_composition_dialog.ui", self)

        self.icon_manager = icon_manager
        self.foils = tmp_foils
        self.index = tmp_index
        self.tmp_foil = copy.deepcopy(tmp_foils[tmp_index])
        self.foil_type = None
        self.foil_type_changed = False

        # Add foil types to combobox.
        self.typeComboBox.addItem("circular")
        self.typeComboBox.addItem("rectangular")

        self.dimension_edits = []
        self.first_dimension_edit = QtWidgets.QDoubleSpinBox()
        self.first_dimension_edit.setMinimum(0.01)
        self.first_dimension_edit.setMaximumWidth(9999.99)
        self.first_dimension_edit.setMaximumWidth(70)
        self.locale = QLocale.c()
        self.first_dimension_edit.setLocale(self.locale)
        self.second_dimension_edit = None
        self.dimension_label = QtWidgets.QLabel("Diameter (mm):")

        self.transmissionEdit.setLocale(self.locale)

        self.dimension_edits.append(self.first_dimension_edit)
        self.dimensionLayout.addWidget(self.dimension_label)
        self.dimensionLayout.addWidget(self.dimension_edits[0])

        self.fields_are_valid = False
        iv.set_input_field_red(self.nameEdit)
        self.nameEdit.textChanged.connect(
            lambda: iv.check_text(self.nameEdit, qwidget=self))
        self.nameEdit.textEdited.connect(
            lambda: iv.sanitize_file_name(self.nameEdit))

        self.show_parameters()

        # This widget adds itself into the matplotlib_layout
        self.composition = FoilCompositionWidget(self, self.tmp_foil,
                                                 self.icon_manager)

        self.typeComboBox.currentIndexChanged.connect(self._change_dimensions)

        self.cancelButton.clicked.connect(self.close)
        self.okButton.clicked.connect(self._save_foil_info_and_close)

        self.__close = True

        self.exec_()
Beispiel #3
0
    def __init__(self,
                 element_simulation: ElementSimulation,
                 preset_folder=None):
        """
        Initializes the widget.

        Args:
            element_simulation: Element simulation object.
        """
        super().__init__()
        uic.loadUi(gutils.get_ui_dir() / "ui_request_simulation_settings.ui",
                   self)

        # By default, disable the widget, so caller has to enable it. Without
        # this, name and description fields would always be enabled when the
        # widget loads.
        self.setEnabled(False)
        self.element_simulation = element_simulation
        self.set_spinbox_maximums()
        gutils.fill_combobox(self.modeComboBox, SimulationMode)
        gutils.fill_combobox(self.typeOfSimulationComboBox, SimulationType)

        self.fields_are_valid = False
        iv.set_input_field_red(self.nameLineEdit)
        self.nameLineEdit.textChanged.connect(
            lambda: iv.check_text(self.nameLineEdit, qwidget=self))
        self.nameLineEdit.textEdited.connect(
            lambda: iv.sanitize_file_name(self.nameLineEdit))
        self.nameLineEdit.setEnabled(False)

        locale = QLocale.c()
        self.minimumScatterAngleDoubleSpinBox.setLocale(locale)
        self.minimumMainScatterAngleDoubleSpinBox.setLocale(locale)
        self.minimumEnergyDoubleSpinBox.setLocale(locale)

        self.__original_property_values = {}

        self.set_properties(
            name=self.element_simulation.name,
            description=self.element_simulation.description,
            modification_time=self.element_simulation.modification_time,
            **self.element_simulation.get_settings())

        if preset_folder is not None:
            self.preset_widget = PresetWidget.add_preset_widget(
                preset_folder / "simulation",
                "sim",
                lambda w: self.layout().insertWidget(0, w),
                save_callback=self.save_properties_to_file,
                load_callback=self.load_properties_from_file)
        else:
            self.preset_widget = None
Beispiel #4
0
    def __init__(self, samples, directory):
        """Inits a load measurement dialog.

        Args:
            samples: Samples of request.
            directory: Directory where to open the file browser.
        """
        super().__init__()
        uic.loadUi(gutils.get_ui_dir() / "ui_new_measurement.ui", self)

        self.browseButton.clicked.connect(self.__browse_files)
        self.addSampleButton.clicked.connect(self.__add_sample)
        self.loadButton.clicked.connect(self.__load_measurement)
        self.cancelButton.clicked.connect(self.close)
        self.name = ""
        self.sample = None
        self.directory = directory
        self.filename = ""
        self.samples = samples

        self.__close = True
        for sample in samples:
            self.samplesComboBox.addItem("Sample " +
                                         "%02d" % sample.serial_number + " " +
                                         sample.name)

        if not samples:
            iv.set_input_field_red(self.samplesComboBox)

        iv.set_input_field_red(self.pathLineEdit)
        self.pathLineEdit.textChanged.connect(
            lambda: iv.check_text(self.pathLineEdit))

        iv.set_input_field_red(self.nameLineEdit)
        self.nameLineEdit.textChanged.connect(
            lambda: iv.check_text(self.nameLineEdit))
        self.nameLineEdit.textEdited.connect(
            lambda: iv.sanitize_file_name(self.nameLineEdit))

        self.exec_()
Beispiel #5
0
    def __init__(self, samples):
        """Inits a new sample dialog.

        Args:
            samples: List of samples.
        """
        super().__init__()
        uic.loadUi(gutils.get_ui_dir() / "ui_new_sample.ui", self)

        self.createButton.clicked.connect(self.__create_sample)
        self.cancelButton.clicked.connect(self.close)
        self.name = ""
        self.description = ""
        self.samples = samples
        self.__close = True

        iv.set_input_field_red(self.nameLineEdit)
        self.nameLineEdit.textChanged.connect(
            lambda: iv.check_text(self.nameLineEdit))
        self.nameLineEdit.textEdited.connect(
            lambda: iv.sanitize_file_name(self.nameLineEdit))

        self.exec_()
Beispiel #6
0
    def __init__(self, parent):
        """Inits energy spectrum dialog.
        
        Args:
            parent: Ibasoft class object.
        """
        super().__init__()
        uic.loadUi(gutils.get_ui_dir() / "ui_new_request.ui", self)

        self.parent = parent
        self.folder = None  # Temporary for browsing folder
        self.directory = None

        self.requestDirectoryLineEdit.setText(
            str(self.parent.settings.get_request_directory()))

        # Connect buttons
        self.pushOk.clicked.connect(self.__create_request)
        self.pushCancel.clicked.connect(self.close)
        self.browseFolderButton.clicked.connect(self.__browser_folder)

        iv.set_input_field_red(self.requestNameLineEdit)
        self.requestNameLineEdit.textChanged.connect(
            lambda: iv.check_text(self.requestNameLineEdit))
        self.requestNameLineEdit.textEdited.connect(
            lambda: iv.sanitize_file_name(self.requestNameLineEdit))

        self.requestDirectoryLineEdit.textChanged.connect(
            lambda: iv.check_text(self.requestDirectoryLineEdit))

        self.__close = True

        if platform.system() == "Darwin":
            self.requestNameLineEdit.setMinimumWidth(310)
            self.requestDirectoryLineEdit.setMinimumWidth(234)

        self.exec_()
Beispiel #7
0
    def __init__(self, samples):
        """Inits a new simulation dialog.

        Args:
            samples: Samples of request.
        """
        super().__init__()
        uic.loadUi(gutils.get_ui_dir() / "ui_new_simulation.ui", self)

        # Add existing samples to view.
        self.samples = samples
        for sample in samples:
            self.samplesComboBox.addItem("Sample " +
                                         "%02d" % sample.serial_number + " " +
                                         sample.name)

        if not samples:
            iv.set_input_field_red(self.samplesComboBox)

        self.addSampleButton.clicked.connect(self.__add_sample)
        self.pushCreate.clicked.connect(self.__create_simulation)
        self.pushCancel.clicked.connect(self.close)
        self.name = None
        self.sample = None
        self.__close = True

        iv.set_input_field_red(self.simulationNameLineEdit)
        self.simulationNameLineEdit.textChanged.connect(
            lambda: iv.check_text(self.simulationNameLineEdit))
        self.simulationNameLineEdit.textEdited.connect(
            lambda: iv.sanitize_file_name(self.simulationNameLineEdit))

        if platform.system() == "Darwin":
            self.samplesComboBox.setMinimumWidth(157)

        self.exec_()
Beispiel #8
0
    def __init__(self, tab, layer=None, modify=False, simulation=None,
                 first_layer=False):
        """Inits a layer dialog.

        Args:
            tab: A SimulationTabWidget
            layer: Layer object to be modified. None if creating a new layer.
            modify: If dialog is used to modify a layer.
            simulation: A Simulation object.
            first_layer: Whether the dialog is used to add the first layer.
        """
        super().__init__()
        uic.loadUi(gutils.get_ui_dir() / "ui_layer_dialog.ui", self)

        self.tab = tab
        self.layer = layer
        self.ok_pressed = False
        self.simulation = simulation
        self.amount_mismatch = True

        self.fields_are_valid = True
        iv.set_input_field_red(self.nameEdit)
        self.nameEdit.textChanged.connect(
            lambda: iv.check_text(self.nameEdit, self))
        self.nameEdit.textEdited.connect(
            lambda: iv.sanitize_file_name(self.nameEdit))

        # Connect buttons to events
        self.addElementButton.clicked.connect(self.__add_element_layout)
        self.okButton.clicked.connect(self.__save_layer)
        self.cancelButton.clicked.connect(self.close)

        self.thicknessEdit.setMinimum(0.01)
        self.densityEdit.setMinimum(0.01)

        self.__original_properties = {}

        if self.layer:
            self.__show_layer_info()
        else:
            self.__add_element_layout()

        if first_layer:
            self.groupBox_2.hide()

        self.__close = True

        self.thicknessEdit.setLocale(QLocale.c())
        self.densityEdit.setLocale(QLocale.c())

        if modify:
            self.groupBox_2.hide()

        self.placement_under = True

        if platform.system() == "Darwin":
            self.setMinimumWidth(450)

        if platform.system() == "Linux":
            self.setMinimumWidth(470)

        self.exec_()
Beispiel #9
0
    def __init__(self,
                 obj: Detector,
                 request: Request,
                 icon_manager,
                 run=None):
        """Initializes a DetectorSettingsWidget object.

        Args:
              obj: a Detector object.
              request: Which request it belongs to.
              icon_manager: IconManager object.
              run: Run object. None if detector is default detector.
        """
        super().__init__()
        uic.loadUi(gutils.get_ui_dir() / "ui_request_detector_settings.ui",
                   self)

        self.obj = obj
        self.request = request
        self.icon_manager = icon_manager
        self.run = run
        self.__original_properties = {}

        # Temporary foils list which holds all the information given in the
        # foil dialog
        # If user presses ok or apply, these values will be saved into
        # request's default detector
        self.tmp_foil_info = []

        # List of foil indexes that are timing foils
        self.tof_foils = []

        # Add foil widgets and foil objects
        self.detector_structure_widgets = []
        self.foils_layout = self._add_default_foils(self.obj)
        self.detectorScrollAreaContents.layout().addLayout(self.foils_layout)
        self.newFoilButton.clicked.connect(
            lambda: self._add_new_foil(self.foils_layout))

        self.addEfficiencyButton.clicked.connect(self.__add_efficiency)
        self.removeEfficiencyButton.clicked.connect(self.__remove_efficiency)
        self.plotEfficiencyButton.clicked.connect(self.__plot_efficiency)

        self.efficiencyListWidget.itemSelectionChanged.connect(
            self._enable_remove_btn)
        self._enable_remove_btn()

        # Calibration settings
        # TODO: Require saving affected cuts if beam setting has been changed
        self.executeCalibrationButton.clicked.connect(
            self.__open_calibration_dialog)
        self.executeCalibrationButton.setEnabled(
            not self.request.samples.measurements.is_empty())

        gutils.fill_combobox(self.typeComboBox, DetectorType)

        self.fields_are_valid = False
        iv.set_input_field_red(self.nameLineEdit)
        self.nameLineEdit.textChanged.connect(
            lambda: iv.check_text(self.nameLineEdit, qwidget=self))
        self.nameLineEdit.textEdited.connect(
            lambda: iv.sanitize_file_name(self.nameLineEdit))
        self.nameLineEdit.setEnabled(False)

        locale = QLocale.c()
        self.timeResSpinBox.setLocale(locale)
        self.virtualSizeXSpinBox.setLocale(locale)
        self.virtualSizeYSpinBox.setLocale(locale)
        self.angleSlopeLineEdit.setLocale(locale)
        self.angleOffsetLineEdit.setLocale(locale)

        # Create scientific spinboxes for tof slope and tof offset
        self.formLayout_2.removeRow(self.slopeLineEdit)
        self.formLayout_2.removeRow(self.offsetLineEdit)

        self.scientific_tof_slope = ScientificSpinBox(minimum=-math.inf,
                                                      maximum=math.inf)
        self.scientific_tof_offset = ScientificSpinBox(minimum=-math.inf,
                                                       maximum=math.inf)

        self.formLayout_2.insertRow(0, "ToF slope [s/channel]:",
                                    self.scientific_tof_slope)
        self.formLayout_2.insertRow(1, "ToF offset[s]:",
                                    self.scientific_tof_offset)

        if platform.system() == "Darwin":
            self.scientific_tof_offset.scientificLineEdit.setFixedWidth(170)
            self.scientific_tof_slope.scientificLineEdit.setFixedWidth(170)

        # Save as and load
        self.saveButton.clicked.connect(self.__save_file)
        self.loadButton.clicked.connect(self.__load_file)

        self.show_settings()