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 _edit_line_edit(self, key_entry):
     QTest.mouseClick(self.line_edit, Qt.LeftButton)
     self.line_edit.selectAll()
     QTest.keyClick(self.line_edit, Qt.Key_Backspace)
     QTest.keyClicks(self.line_edit, key_entry)
     QTest.keyClick(self.line_edit, Qt.Key_Enter)
     QApplication.sendPostedEvents()
Ejemplo n.º 3
0
 def test_ui_increase_maximum(self):
     low, high = self.stretch.values()
     maximum = self.stretch.maximum()
     delta = 1000 * max(abs(maximum), 1)
     value = maximum + delta
     QTest.keyClicks(self.stretch.maxSpinBox, str(value))
     self.assertEqual(self.stretch.maximum(), value)
     self.assertEqual(low, self.stretch.low())
     self.assertEqual(high, self.stretch.high())
Ejemplo n.º 4
0
 def test_ui_decrease_maximum(self):
     low, high = self.stretch.values()
     maximum = self.stretch.maximum()
     delta = maximum - high
     value = maximum + delta / 2
     QTest.keyClicks(self.stretch.maxSpinBox, str(value))
     self.assertEqual(self.stretch.maximum(), value)
     self.assertEqual(low, self.stretch.low())
     self.assertEqual(high, self.stretch.high())
Ejemplo n.º 5
0
 def test_ui_decrease_maximum_below_high(self):
     low, high = self.stretch.values()
     maximum = 0.5 * (low + high)
     self.assertGreater(maximum, low)
     self.assertLess(maximum, high)
     QTest.keyClicks(self.stretch.maxSpinBox, str(maximum))
     self.assertEqual(self.stretch.maximum(), maximum)
     self.assertEqual(low, self.stretch.low())
     self.assertEqual(self.stretch.high(), maximum)
Ejemplo n.º 6
0
 def test_ui_increase_minimum_above_low(self):
     low, high = self.stretch.values()
     minimum = 0.5 * (low + high)
     self.assertGreater(minimum, low)
     self.assertLess(minimum, high)
     QTest.keyClicks(self.stretch.minSpinBox, str(minimum))
     self.assertEqual(self.stretch.minimum(), minimum)
     self.assertEqual(self.stretch.low(), minimum)
     self.assertEqual(high, self.stretch.high())
Ejemplo n.º 7
0
 def test_ui_increase_minimum(self):
     low, high = self.stretch.values()
     minimum = self.stretch.minimum()
     delta = low - minimum
     value = minimum + delta / 2
     QTest.keyClicks(self.stretch.minSpinBox, str(value))
     self.assertEqual(self.stretch.minimum(), value)
     self.assertEqual(low, self.stretch.low())
     self.assertEqual(high, self.stretch.high())
Ejemplo n.º 8
0
 def test_ui_decrease_maximum_below_low(self):
     low, high = self.stretch.values()
     delta = min(abs(low), abs(high)) / 2
     maximum = low - delta
     self.assertLess(maximum, low)
     self.assertGreater(maximum, self.stretch.minimum())
     QTest.keyClicks(self.stretch.maxSpinBox, str(maximum))
     self.assertEqual(self.stretch.maximum(), maximum)
     self.assertEqual(self.stretch.low(), maximum)
     self.assertEqual(self.stretch.high(), maximum)
Ejemplo n.º 9
0
 def test_ui_increase_minimum_above_high(self):
     low, high = self.stretch.values()
     delta = min(abs(low), abs(high)) / 2
     minimum = high + delta
     self.assertGreater(minimum, high)
     self.assertLess(minimum, self.stretch.maximum())
     QTest.keyClicks(self.stretch.minSpinBox, str(minimum))
     self.assertEqual(self.stretch.minimum(), minimum)
     self.assertEqual(self.stretch.low(), minimum)
     self.assertEqual(self.stretch.high(), minimum)
Ejemplo n.º 10
0
 def view_set_parameter(self, param_name, value):
     view = self.widget.view()
     rect = view.getVisualRectParameterProperty(param_name)
     pos = rect.center()
     if self.is_multi:
         pos -= QPoint(rect.width() / 5, 0)
     else:
         pos += QPoint(rect.width() / 4, 0)
     tree = view.treeWidget().viewport()
     QTest.mouseMove(tree, pos)
     yield
     QTest.mouseClick(tree, Qt.LeftButton, Qt.NoModifier, pos)
     yield
     editor = QApplication.focusWidget()
     QTest.keyClicks(editor, str(value))
     QTest.keyClick(editor, Qt.Key_Return)
Ejemplo n.º 11
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()
Ejemplo n.º 12
0
    def test_dpi(self):
        # save to higher dpi
        # set export dir
        _rewrite_text(self.dialog.ui.comboBox_directory,
                      os.path.abspath(self._temp_dir))
        self.dialog.exec_ = self._fake_export_dialog_exec_export
        self.dialog._msg_box.exec_ = self._fake_msg_dialog_exec_overwrite
        # set open after to false
        self.dialog.ui.checkBox_open_after_export.setChecked(False)

        QTest.keyClicks(self.dialog.ui.spinBox_dpi, '400')
        _rewrite_text(self.dialog.ui.comboBox_fileName, "400dpi.jpg")
        fname = self.dialog.export_to_file(self._fig)
        self.assertTrue(os.path.exists(fname), "File exists")
        new_file_count = len([
            name for name in os.listdir(self._temp_dir)
            if os.path.isfile(os.path.join(self._temp_dir, name))
        ])

        QTest.keyClicks(self.dialog.ui.spinBox_dpi, '600')
        _rewrite_text(self.dialog.ui.comboBox_fileName, "600dpi.jpg")
        fname = self.dialog.export_to_file(self._fig)
        self.assertTrue(os.path.exists(fname), "File exists")
        new_file_count = len([
            name for name in os.listdir(self._temp_dir)
            if os.path.isfile(os.path.join(self._temp_dir, name))
        ])

        QTest.keyClicks(self.dialog.ui.spinBox_dpi, '1000')
        _rewrite_text(self.dialog.ui.comboBox_fileName, "1000dpi.jpg")
        fname = self.dialog.export_to_file(self._fig)
        self.assertTrue(os.path.exists(fname), "File exists")
        new_file_count = len([
            name for name in os.listdir(self._temp_dir)
            if os.path.isfile(os.path.join(self._temp_dir, name))
        ])
Ejemplo n.º 13
0
 def test_filter_text_typing_calls_presenter_and_sets_filter_text(self):
     QTest.keyClicks(self.view.filter_box, 'plot1')
     self.assertEquals(self.presenter.filter_text_changed.call_count, 5)
     self.assertEquals(self.view.get_filter_text(), 'plot1')
Ejemplo n.º 14
0
 def test_ui_increase_minimum_above_maximum(self):
     delta = max(abs(self.stretch.minimum()),
                 abs(self.stretch.maximum()))
     minimum = self.stretch.maximum() + delta
     QTest.keyClicks(self.stretch.minSpinBox, str(minimum))
     self.assertEqual(self.stretch.minimum(), minimum)
Ejemplo n.º 15
0
def _rewrite_text(widget, text):
    QTest.keyEvent(QTest.Click, widget, QtCore.Qt.Key_A,
                   QtCore.Qt.ControlModifier)
    QTest.keyClicks(widget, text)
    QTest.keyEvent(QTest.Click, widget, QtCore.Qt.Key_Enter)
Ejemplo n.º 16
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()
Ejemplo n.º 17
0
 def test_ui_decrease_maximum_below_minimum(self):
     delta = max(abs(self.stretch.minimum()),
                 abs(self.stretch.maximum()))
     maximum = self.stretch.minimum() - delta
     QTest.keyClicks(self.stretch.maxSpinBox, str(maximum))
     self.assertEqual(self.stretch.maximum(), maximum)