コード例 #1
0
def change_wd_to_root(func):
    """Helper wrapper function that changes the working directory to the root
    directory of Potku for the duration of the wrapped function. After the
    function has run, working directory is changed back so other tests are
    not affected.

    This decorator was originally used to test code that read a file
    using a relative path. Now the file path has been made absolute, so this
    function is no longer needed for its original purpose. However, there may
    be other uses for this.
    """
    # Get old working directory and path to this file. Then traverse to
    # parent directory (i.e. the root)
    old_wd = Path.cwd()
    root = gf.get_root_dir()

    @functools.wraps(func)
    def wrapper(*args, **kwargs):
        # Change the dir, run the func and change back in the finally
        # block
        os.chdir(root)
        try:
            func(*args, **kwargs)
        finally:
            os.chdir(old_wd)

    # Return the wrapper function
    return wrapper
コード例 #2
0
 def __plot_efficiency(self):
     """
     Open efficiency plot widget
     """
     self.eff_folder = gutils.get_potku_setting(
         DetectorSettingsWidget.EFF_FILE_FOLDER_KEY,
         self.request.default_folder)
     self.efficiency_files = self.obj.get_efficiency_files()
     self.efficiency_files_list = []
     i = 0
     for file in self.efficiency_files:
         file_name = gf.get_root_dir() / self.eff_folder / str(
             self.efficiency_files[i])
         self.efficiency_files_list.append(file_name)
         i += 1
     EfficiencyDialog(self.efficiency_files_list, self)
コード例 #3
0
    def __init__(self):
        """Inits the About Dialog.
        """

        super().__init__()
        uic.loadUi(gutils.get_ui_dir() / "ui_about.ui", self)

        self.OKButton.clicked.connect(self.close)
        self.DiscoButton.clicked.connect(self.__disco)

        image = gf.get_root_dir() / "images" / "potku_logo_icon.svg"
        pixmap = QtGui.QPixmap(str(image))
        scaled_pixmap = pixmap.scaled(self.picture.size(),
                                      QtCore.Qt.KeepAspectRatio)
        self.picture.setPixmap(scaled_pixmap)

        self.x = 0
        self.y = 2
        self.z = 3
        self.__timer = None
        self.exec_()
コード例 #4
0
    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()
コード例 #5
0
ファイル: gui_utils.py プロジェクト: aleekaup2/potku
def get_icon_dir() -> Path:
    """Returns absolute path to directory that contains Potku's icons.
    """
    return gf.get_root_dir() / "ui_icons"
コード例 #6
0
ファイル: gui_utils.py プロジェクト: aleekaup2/potku
def get_ui_dir() -> Path:
    """Returns absolute path to directory that contains .ui files.
    """
    return gf.get_root_dir() / "ui_files"
コード例 #7
0
def get_resource_dir() -> Path:
    """Returns the resource directory's absolute path.
    """
    return gf.get_root_dir() / "tests" / "resource"
コード例 #8
0
def get_sample_data_dir() -> Path:
    """Returns the absolute path to the sample data directory.
    """
    return gf.get_root_dir() / "sample_data"