Esempio n. 1
0
    def load_projection_angles(self):
        stack_selector = StackSelectorDialog(
            main_window=self,
            title="Stack Selector",
            message=self.LOAD_PROJECTION_ANGLES_DIALOG_MESSAGE)
        # Was closed without accepting (e.g. via x button or ESC)
        if QDialog.DialogCode.Accepted != stack_selector.exec():
            return

        stack_name = stack_selector.selected_stack

        selected_file, _ = QFileDialog.getOpenFileName(
            caption=self.LOAD_PROJECTION_ANGLES_FILE_DIALOG_CAPTION,
            filter="All (*.*)")
        if selected_file == "":
            return

        pafp = ProjectionAngleFileParser(selected_file)
        projection_angles = pafp.get_projection_angles()

        self.presenter.add_projection_angles_to_sample(stack_name,
                                                       projection_angles)
        QMessageBox.information(
            self, "Load complete",
            f"Angles from {selected_file} were loaded into into "
            f"{stack_name}.")
    def test_close_called_on_ok_clicked(self):
        diag = StackSelectorDialog(main_window=FakeMainWindowView())
        diag.done = mock.MagicMock()

        diag.on_ok_clicked()

        diag.done.assert_called_once_with(QDialog.Accepted)
    def test_title_set_when_not_none_given(self):
        given_message = "given_message"

        diag = StackSelectorDialog(main_window=FakeMainWindowView(),
                                   title=given_message)

        self.assertEqual(given_message, diag.windowTitle())
Esempio n. 4
0
    def load_180_deg_dialog(self):
        stack_selector = StackSelectorDialog(
            main_window=self,
            title="Stack Selector",
            message="Which stack is the 180 degree projection being loaded for?"
        )
        # Was closed without accepting (e.g. via x button or ESC)
        if QDialog.Accepted != stack_selector.exec():
            return
        stack_to_add_180_deg_to = stack_selector.selected_stack

        # Open file dialog
        file_filter = "Image File (*.tif *.tiff)"
        selected_file, _ = QFileDialog.getOpenFileName(
            caption="180 Degree Image",
            filter=f"{file_filter};;All (*.*)",
            initialFilter=file_filter)
        # Cancel/Close was clicked
        if selected_file == "":
            return

        _180_dataset = self.presenter.add_180_deg_to_sample(
            stack_name=stack_to_add_180_deg_to, _180_deg_file=selected_file)
        self.create_new_stack(_180_dataset,
                              self.presenter.create_stack_name(selected_file))
Esempio n. 5
0
    def load_sample_log_dialog(self):
        stack_selector = StackSelectorDialog(
            main_window=self,
            title="Stack Selector",
            message="Which stack is the log being loaded for?")
        # Was closed without accepting (e.g. via x button or ESC)
        if QDialog.Accepted != stack_selector.exec():
            return
        stack_to_add_log_to = stack_selector.selected_stack

        # Open file dialog
        file_filter = "Log File (*.txt *.log)"
        selected_file, _ = QFileDialog.getOpenFileName(
            caption="Log to be loaded",
            filter=f"{file_filter};;All (*.*)",
            initialFilter=file_filter)
        # Cancel/Close was clicked
        if selected_file == "":
            return

        self.presenter.add_log_to_sample(stack_name=stack_to_add_log_to,
                                         log_file=selected_file)

        QMessageBox.information(
            self, "Load complete", f"{selected_file} was loaded as a log into "
            f"{stack_to_add_log_to}.")
    def test_selected_stack_called_on_ok_clicked(self):
        diag = StackSelectorDialog(main_window=FakeMainWindowView())
        desired_stack = "Desired_stack"
        diag.stack_selector_widget.currentText = mock.MagicMock(
            return_value=desired_stack)

        diag.on_ok_clicked()

        self.assertEqual(desired_stack, diag.selected_stack)
        diag.stack_selector_widget.currentText.assert_called_once()
    def test_message_label_set_to_given_message(self):
        given_message = "given_message"

        diag = StackSelectorDialog(main_window=FakeMainWindowView(),
                                   message=given_message)

        self.assertEqual(given_message, diag.message_label.text())
Esempio n. 8
0
    def load_sample_log_dialog(self):
        stack_selector = StackSelectorDialog(
            main_window=self,
            title="Stack Selector",
            message="Which stack is the log being loaded for?")
        # Was closed without accepting (e.g. via x button or ESC)
        if QDialog.DialogCode.Accepted != stack_selector.exec():
            return
        stack_to_add_log_to = stack_selector.selected_stack

        # Open file dialog
        selected_file = self._get_file_name("Log to be loaded",
                                            "Log File (*.txt *.log *.csv)")

        # Cancel/Close was clicked
        if selected_file == "":
            return

        self.presenter.add_log_to_sample(stack_name=stack_to_add_log_to,
                                         log_file=selected_file)

        QMessageBox.information(
            self, "Load complete", f"{selected_file} was loaded as a log into "
            f"{stack_to_add_log_to}.")
    def test_title_not_set_when_none_given(self):
        diag = StackSelectorDialog(main_window=FakeMainWindowView(),
                                   title=None)

        self.assertEqual("", diag.windowTitle())
    def test_message_label_set_to_default_given_none(self):
        diag = StackSelectorDialog(main_window=FakeMainWindowView(),
                                   message=None)

        self.assertEqual("Select the stack", diag.message_label.text())