def test_edit_reflection(self):
        col = 0
        row = 1

        previous_d0 = self.phase_model.phases[5].reflections[1].d

        # get x,y position for the cell
        x_pos = self.jcpds_widget.reflection_table_view.columnViewportPosition(col) + 3
        y_pos = self.jcpds_widget.reflection_table_view.rowViewportPosition(row) + 10

        # click then doubleclick  the cell
        self.assertTrue(self.jcpds_widget.reflection_table_view.isVisible())
        viewport = self.jcpds_widget.reflection_table_view.viewport()
        QTest.mouseClick(viewport, QtCore.Qt.LeftButton, pos=QtCore.QPoint(x_pos, y_pos))
        QTest.mouseDClick(viewport, QtCore.Qt.LeftButton, pos=QtCore.QPoint(x_pos, y_pos))

        # type in the new number
        QTest.keyClicks(viewport.focusWidget(), "3")
        QTest.keyPress(viewport.focusWidget(), QtCore.Qt.Key_Enter)
        QtWidgets.QApplication.processEvents()

        self.assertEqual(self.phase_model.phases[5].reflections[1].h, 3)
        print(self.phase_model.phases[5].reflections[1].d)
        self.assertNotEqual(self.phase_model.phases[5].reflections[1].d,
                            previous_d0)
    def test_rename_finishing_editing_makes_line_uneditable_and_calls_presenter(self):
        plot_numbers = [0, 1, 2]
        self.view.set_plot_list(plot_numbers)

        name_widget = self.view.table_widget.cellWidget(1, Column.Name)
        QTest.mouseClick(name_widget.rename_button, Qt.LeftButton)
        QTest.keyPress(name_widget.line_edit, Qt.Key_Return)

        self.presenter.rename_figure.assert_called_once_with(1, "Plot2")

        self.assertTrue(name_widget.line_edit.isReadOnly())
        self.assertFalse(name_widget.rename_button.isChecked())
    def test_rename_finishing_editing_makes_line_uneditable_and_calls_presenter(self):
        plot_numbers = [0, 1, 2]
        self.view.set_plot_list(plot_numbers)

        name_widget = self.view.table_widget.cellWidget(1, Column.Name)
        QTest.mouseClick(name_widget.rename_button, Qt.LeftButton)
        QTest.keyPress(name_widget.line_edit, Qt.Key_Return)

        self.presenter.rename_figure.assert_called_once_with(1, "Plot2")

        self.assertTrue(name_widget.line_edit.isReadOnly())
        self.assertFalse(name_widget.rename_button.isChecked())
    def test_pattern_bkg_txt_fields_change_linear_regions(self):
        self.model.pattern_model.load_pattern(os.path.join(data_path, 'pattern_001.xy'))
        self.widget.bkg_pattern_gb.setChecked(True)
        self.widget.bkg_pattern_inspect_btn.toggle()

        self.widget.bkg_pattern_x_min_txt.setText('5')
        QTest.keyPress(self.widget.bkg_pattern_x_min_txt, QtCore.Qt.Key_Enter)
        self.widget.bkg_pattern_x_max_txt.setText('11')
        QTest.keyPress(self.widget.bkg_pattern_x_max_txt, QtCore.Qt.Key_Enter)

        x_min, x_max = self.widget.pattern_widget.linear_region_item.getRegion()

        self.assertAlmostEqual(x_min, 5,  delta=0.02)
        self.assertAlmostEqual(x_max, 11, delta=0.02)
    def test_pattern_bkg_txt_fields_change_linear_regions(self):
        self.model.pattern_model.load_pattern(
            os.path.join(data_path, 'pattern_001.xy'))
        self.widget.bkg_pattern_gb.setChecked(True)
        self.widget.bkg_pattern_inspect_btn.toggle()

        self.widget.bkg_pattern_x_min_txt.setText('5')
        QTest.keyPress(self.widget.bkg_pattern_x_min_txt, QtCore.Qt.Key_Enter)
        self.widget.bkg_pattern_x_max_txt.setText('11')
        QTest.keyPress(self.widget.bkg_pattern_x_max_txt, QtCore.Qt.Key_Enter)

        x_min, x_max = self.widget.pattern_widget.linear_region_item.getRegion(
        )

        self.assertAlmostEqual(x_min, 5, delta=0.02)
        self.assertAlmostEqual(x_max, 11, delta=0.02)
Exemplo n.º 6
0
    def insert_reflection_table_value(self, row, col, value):
        # get click position
        x_pos = self.jcpds_widget.reflection_table_view.columnViewportPosition(
            col) + 3
        y_pos = self.jcpds_widget.reflection_table_view.rowViewportPosition(
            row) + 10

        # enter the correct cell
        viewport = self.jcpds_widget.reflection_table_view.viewport()
        QTest.mouseClick(viewport,
                         QtCore.Qt.LeftButton,
                         pos=QtCore.QPoint(x_pos, y_pos))
        QTest.mouseDClick(viewport,
                          QtCore.Qt.LeftButton,
                          pos=QtCore.QPoint(x_pos, y_pos))

        # update the value
        QTest.keyClicks(viewport.focusWidget(), str(value))
        QTest.keyPress(viewport.focusWidget(), QtCore.Qt.Key_Enter)
        QtWidgets.QApplication.processEvents()
Exemplo n.º 7
0
    def test_run_prevent_dialog_close_esc(self):
        thread_event = threading.Event()

        class _SampleTarget(object):
            @staticmethod
            def validate(args, limit_to=None):
                return []

            @staticmethod
            def execute(args):
                thread_event.wait()

        target_mod = _SampleTarget().execute
        form = FormTest.make_ui()
        form.run(target=target_mod)
        QTest.keyPress(form.run_dialog, QtCore.Qt.Key_Escape)
        self.assertTrue(form.run_dialog.isVisible())

        # when the execute function finishes, pressing escape should
        # close the window.
        thread_event.set()
        QTest.keyPress(form.run_dialog, QtCore.Qt.Key_Escape)
        self.assertEqual(form.run_dialog.result(), QtWidgets.QDialog.Rejected)
        self.assertEqual(form.run_dialog.result(), QtWidgets.QDialog.Rejected)
Exemplo n.º 8
0
def enter_value_into_text_field(text_field, value):
    text_field.setText('')
    QTest.keyClicks(text_field, str(value))
    QTest.keyPress(text_field, QtCore.Qt.Key_Enter)
    QtWidgets.QApplication.processEvents()
def enter_value_into_text_field(text_field, value):
    text_field.setText('')
    QTest.keyClicks(text_field, str(value))
    QTest.keyPress(text_field, QtCore.Qt.Key_Enter)
    QtWidgets.QApplication.processEvents()
    def test_pressing_return_in_box_activates_completer(self):
        view = AddFunctionDialogView(function_names=self.TEST_FUNCTION_NAMES)

        QTest.keyPress(view.ui.functionBox, Qt.Key_F)
        QTest.keyPress(view.ui.functionBox, Qt.Key_U)
        QTest.keyPress(view.ui.functionBox, Qt.Key_N)
        QTest.keyPress(view.ui.functionBox, Qt.Key_C)
        QTest.keyPress(view.ui.functionBox, Qt.Key_1)
        QTest.keyPress(view.ui.functionBox, Qt.Key_Return)

        self.assertEqual(self.TEST_FUNCTION_NAMES[0], view.ui.functionBox.currentText())
Exemplo n.º 11
0
 def keyPress(self, key, modifier=None, delay=10):
     if modifier is None:
         modifier = QtCore.Qt.NoModifier
     QTest.keyPress(self.window, key, modifier, delay=delay)
     self.window.app.processEvents()