def load_files(self, max_count=MAX_COUNT, selected: Optional[Path] = None): """Loads preset files to combobox. Args: max_count: maximum number of files to load selected: path to a file that will be selected after loading """ def text_func(preset_path: Optional[Path]): if preset_path is None: return PresetWidget.NONE_TEXT return preset_path.stem preset_files = PresetWidget.get_preset_files(self._folder, max_count, keep=selected) if not self._load_btn_enabled: # If load button is not used, add 'None' as the first element in # the combobox preset_files = [None, *preset_files] gutils.fill_combobox(self.preset_combobox, preset_files, text_func=text_func, block_signals=True) self.preset = selected
def __init__(self, settings: GlobalSettings): """Constructor for the program """ super().__init__() uic.loadUi(gutils.get_ui_dir() / "ui_global_settings.ui", self) self.settings = settings self.__added_timings = {} # Placeholder for timings self.setAttribute(QtCore.Qt.WA_DeleteOnClose) gutils.set_min_max_handlers( self.spin_tofe_bin_x_min, self.spin_tofe_bin_x_max ) gutils.set_min_max_handlers( self.spin_tofe_bin_y_min, self.spin_tofe_bin_y_max ) gutils.set_btn_group_data(self.ion_division_radios, IonDivision) gutils.set_btn_group_data(self.cross_section_radios, CrossSection) gutils.fill_combobox(self.combo_tofe_colors, ToFEColorScheme) # Connect UI buttons self.OKButton.clicked.connect(self.__accept_changes) self.cancelButton.clicked.connect(self.close) buttons = self.findChild(QtWidgets.QButtonGroup, "elementButtons") buttons.buttonClicked.connect(self.__change_element_color) self.min_conc_spinbox.setLocale(QtCore.QLocale.c()) if platform.system() == "Darwin": self.gridLayout.setVerticalSpacing(15) self.gridLayout.setHorizontalSpacing(15) self.__set_values()
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
def test_fill_combobox(self): values = [1, {"foo": "bar"}, "foo", [1, 2]] combobox = QtWidgets.QComboBox() gutils.fill_combobox(combobox, values) self.assertEqual(len(values), combobox.count()) for i, value in enumerate(values): self.assertEqual(value, combobox.itemData(i)) self.assertEqual(str(value), combobox.itemText(i)) # Combobox is cleared when fill_combobox is called gutils.fill_combobox(combobox, ["kissa istuu"]) self.assertEqual(1, combobox.count()) self.assertEqual("kissa istuu", combobox.currentData())
def __init__(self, parent, measurement: Measurement, statusbar: Optional[QtWidgets.QStatusBar] = None): """Inits element losses class. Args: parent: A MeasurementTabWidget. """ super().__init__() uic.loadUi(gutils.get_ui_dir() / "ui_element_losses_params.ui", self) self.parent = parent self.measurement = measurement self.statusbar = statusbar self.cuts = [] self.OKButton.clicked.connect(self.__accept_params) self.cancelButton.clicked.connect(self.close) # self.referenceCut.currentIndexChanged.connect(self.__load_targets) # TODO: Reads cut files twice. Requires Refactor. # Reference cuts m_name = self.measurement.name if m_name not in ElementLossesDialog.reference_cut: ElementLossesDialog.reference_cut[m_name] = None cuts, _ = self.measurement.get_cut_files() gutils.fill_combobox(self.referenceCut, cuts, text_func=lambda fp: fp.name) self.used_reference_cut = ElementLossesDialog.reference_cut[m_name] # Cuts and element losses if m_name not in ElementLossesDialog.checked_cuts: ElementLossesDialog.checked_cuts[m_name] = set() gutils.fill_cuts_treewidget(self.measurement, self.targetCutTree.invisibleRootItem(), use_elemloss=True) self.used_cuts = ElementLossesDialog.checked_cuts[m_name] self.partitionCount.setValue(ElementLossesDialog.split_count) self.radioButton_0max.setChecked(ElementLossesDialog.y_scale == 0) self.radioButton_minmax.setChecked(ElementLossesDialog.y_scale == 1) self.exec_()
def __init__(self, recoil_elements: List[RecoilElement], icon_manager, distribution_changed=None, interval_changed=None, get_limits=None): """ Initialize the widget. Args: recoil_elements: List of recoil elements. icon_manager: Icon manager. """ super().__init__() uic.loadUi(gutils.get_ui_dir() / "ui_percentage_widget.ui", self) # Stores the PercentageRow objects for each recoil self._percentage_rows = {recoil: None for recoil in recoil_elements} self.icon_manager = icon_manager self.setWindowTitle("Percentages") gutils.fill_combobox(self.comboBox, IntervalType) self.comboBox.currentIndexChanged.connect( self.__show_percents_and_areas) self.icon_manager.set_icon(self.absRelButton, "depth_profile_rel.svg") self.__relative_values = True self.absRelButton.setToolTip( "Toggle between relative and absolute values.") self.absRelButton.clicked.connect(self.__show_abs_or_rel_values) self.__dist_changed_sig = distribution_changed self.__interval_changed_sig = interval_changed self.get_limits = get_limits if self.get_limits is not None: if distribution_changed is not None: distribution_changed.connect(self._dist_changed) if interval_changed is not None: interval_changed.connect(self._limits_changed) self.__show_percents_and_areas()
def show_yourself(self, dialog): """Show current ToF-E histogram settings in dialog. Args: dialog: A TofeGraphSettingsWidget. """ gutils.fill_combobox(dialog.colorbox, ToFEColorScheme) dialog.color_scheme = self.color_scheme # Get values dialog.bin_x.setValue(self.compression_x) dialog.bin_y.setValue(self.compression_y) dialog.invert_x.setChecked(self.invert_X) dialog.invert_y.setChecked(self.invert_Y) dialog.axes_ticks.setChecked(self.show_axis_ticks) dialog.transposeAxesCheckBox.setChecked(self.transpose_axes) dialog.radio_range_auto.setChecked(self.axes_range_mode == 0) dialog.radio_range_manual.setChecked(self.axes_range_mode == 1) dialog.spin_range_x_min.setValue(self.axes_range[0][0]) dialog.spin_range_x_max.setValue(self.axes_range[0][1]) dialog.spin_range_y_min.setValue(self.axes_range[1][0]) dialog.spin_range_y_max.setValue(self.axes_range[1][1])
def __init__(self, obj: Union[Measurement, Simulation], preset_folder=None): """Initializes the widget. Args: obj: object that uses these settings, either a Measurement or a Simulation. """ super().__init__() uic.loadUi(gutils.get_ui_dir() / "ui_measurement_settings_tab.ui", self) self.fluenceDoubleSpinBox = ScientificSpinBox() image = gf.get_root_dir() / "images" / "measurement_setup_angles.png" pixmap = QtGui.QPixmap(str(image)) self.picture.setScaledContents(True) self.picture.setPixmap(pixmap) self.obj = obj self.__original_property_values = {} locale = QLocale.c() self.energyDoubleSpinBox.setLocale(locale) self.energyDistDoubleSpinBox.setLocale(locale) self.spotSizeXdoubleSpinBox.setLocale(locale) self.spotSizeYdoubleSpinBox.setLocale(locale) self.divergenceDoubleSpinBox.setLocale(locale) self.currentDoubleSpinBox.setLocale(locale) self.timeDoubleSpinBox.setLocale(locale) self.runChargeDoubleSpinBox.setLocale(locale) self.targetThetaDoubleSpinBox.setLocale(locale) self.detectorThetaDoubleSpinBox.setLocale(locale) self.detectorFiiDoubleSpinBox.setLocale(locale) self.targetFiiDoubleSpinBox.setLocale(locale) # Fii angles are currently not used so disable their spin boxes self.detectorFiiDoubleSpinBox.setEnabled(False) self.targetFiiDoubleSpinBox.setEnabled(False) gutils.fill_combobox(self.profileComboBox, Profile) # Copy of measurement's/simulation's run or default run # TODO should default run also be copied? if not self.obj.run: self.tmp_run = self.obj.request.default_run else: self.tmp_run = copy.deepcopy(self.obj.run) self.isotopeInfoLabel.setVisible(False) self.beamIonButton.clicked.connect(self.change_element) 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(self.__validate) self.nameLineEdit.setEnabled(False) self.run_form_layout: QtWidgets.QFormLayout self.run_form_layout.insertRow(3, "Fluence", self.fluenceDoubleSpinBox) self.fluenceDoubleSpinBox.scientificLineEdit.setContextMenuPolicy( Qt.ActionsContextMenu) self.actionMultiply = QtWidgets.QAction( self.fluenceDoubleSpinBox.scientificLineEdit) self.actionMultiply.triggered.connect(self.__multiply_fluence) self.fluenceDoubleSpinBox.scientificLineEdit.addAction( self.actionMultiply) self.actionUndo = QtWidgets.QAction( self.fluenceDoubleSpinBox.scientificLineEdit) self.actionUndo.setText("Undo multiply") self.actionUndo.triggered.connect(self.__undo_fluence) self.actionUndo.setEnabled(bool(self.tmp_run.previous_fluence)) self.fluenceDoubleSpinBox.scientificLineEdit.addAction(self.actionUndo) self.clipboard = QGuiApplication.clipboard() self._ratio = None self.clipboard.changed.connect(self.__update_multiply_action) self.__update_multiply_action() self.energyDoubleSpinBox.setToolTip("Energy set in MeV with.") if preset_folder is not None: self.preset_widget = PresetWidget.add_preset_widget( preset_folder / "measurement", "mea", 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 self.show_settings()
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()