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)
Exemplo n.º 2
0
 def test_run_dialog_opens_on_double_click(self):
     with patch(createDialogFromName_func_name) as createDialog:
         widget = AlgorithmSelectorWidget()
         self._select_in_tree(widget, 'Load v.1')
         selected_item = widget.tree.selectedItems()[0]
         item_pos = widget.tree.visualItemRect(selected_item).center()
         QTest.mouseDClick(widget.tree.viewport(), Qt.LeftButton,
                           Qt.NoModifier, pos=item_pos)
         createDialog.assert_called_once_with('Load', 1, None, False, {}, '', [])
 def test_run_dialog_opens_on_double_click(self):
     with patch(createDialogFromName_func_name) as createDialog:
         widget = AlgorithmSelectorWidget()
         self._select_in_tree(widget, 'Load v.1')
         selected_item = widget.tree.selectedItems()[0]
         item_pos = widget.tree.visualItemRect(selected_item).center()
         QTest.mouseDClick(widget.tree.viewport(), Qt.LeftButton,
                           Qt.NoModifier, pos=item_pos)
         createDialog.assert_called_once_with('Load', 1)
Exemplo n.º 4
0
    def test_droplist_completer_mousepick(self):
        leftButton = QtCore.Qt.LeftButton

        w = CompletionWidget(self.console)
        w.show_items(self.text_edit.textCursor(), ["item1", "item2", "item3"])

        QTest.mouseClick(w.viewport(), leftButton, pos=QtCore.QPoint(19, 8))
        QTest.mouseRelease(w.viewport(), leftButton, pos=QtCore.QPoint(19, 8))
        QTest.mouseDClick(w.viewport(), leftButton, pos=QtCore.QPoint(19, 8))

        self.assertEqual(self.text_edit.toPlainText(), "item1")
        self.assertFalse(w.isVisible())
Exemplo n.º 5
0
 def equipment_click(self, field: str):
     listw = self.myapp.ui.EquipmentTemplatesListWidget
     self.myapp.ui.EquipmentTemplatesStackedWidget.setCurrentIndex(0)
     item = listw.findItems(field, Qt.MatchStartsWith)[0]
     listw.setCurrentItem(item)
     self.assertEqual(field, item.text())
     rect = listw.visualItemRect(item)
     QTest.mouseDClick(listw.viewport(), Qt.LeftButton, Qt.NoModifier,
                       rect.center())
     app.processEvents()
     # This is necessary:
     self.myapp.equipment.load_selected_equipment()
Exemplo n.º 6
0
    def editCell(self, row, column):
        """
        Enter in cell editing mode (cell double click).

        Args:
            row (int): row index
            column (int): column index
        """
        y = self.view.table.rowViewportPosition(row) + 1
        x = self.view.table.columnViewportPosition(column) + 1
        QTest.mouseClick(self.view.table.viewport(),
                         Qt.LeftButton, Qt.NoModifier, QPoint(x, y))
        QTest.mouseDClick(self.view.table.viewport(),
                          Qt.LeftButton, Qt.NoModifier, QPoint(x, y))
    def test_plot_name_double_clicked_calls_presenter_and_makes_plot_current(self):
        plot_numbers = [0, 1, 2]
        self.view.set_plot_list(plot_numbers)

        item = self.view.table_widget.item(1, 1)
        item_center = self.view.table_widget.visualItemRect(item).center()
        # This single click should not be required, but otherwise the double click is not registered
        QTest.mouseClick(self.view.table_widget.viewport(), Qt.LeftButton, pos=item_center)
        QTest.mouseDClick(self.view.table_widget.viewport(), Qt.LeftButton, pos=item_center)

        self.assertEqual(self.presenter.show_single_selected.call_count, 1)
        # Expected result: 1
        # Something goes wrong in QTest here and the selection is
        # always the first plot.
        self.assertEqual(self.view.get_currently_selected_plot_number(), 0)
    def test_plot_name_double_clicked_calls_presenter_and_makes_plot_current(self):
        plot_numbers = [0, 1, 2]
        self.view.set_plot_list(plot_numbers)

        item = self.view.table_widget.item(1, 1)
        item_center = self.view.table_widget.visualItemRect(item).center()
        # This single click should not be required, but otherwise the double click is not registered
        QTest.mouseClick(self.view.table_widget.viewport(), Qt.LeftButton, pos=item_center)
        QTest.mouseDClick(self.view.table_widget.viewport(), Qt.LeftButton, pos=item_center)

        self.assertEqual(self.presenter.show_single_selected.call_count, 1)
        # Expected result: 1
        # Something goes wrong in QTest here and the selection is
        # always the first plot.
        self.assertEqual(self.view.get_currently_selected_plot_number(), 0)
Exemplo n.º 9
0
    def editCell(self, row, column, text):
        """
        Edit a specific cell of the DrILL table.

        Args:
            row (int): row index
            column (int): column index
            text (str): string to be written in the cell
        """
        columnIndex = self.drill.table.columns.index(column)
        y = self.drill.table.rowViewportPosition(row) + 5
        x = self.drill.table.columnViewportPosition(columnIndex) + 5
        QTest.mouseClick(self.drill.table.viewport(),
                         Qt.LeftButton, Qt.NoModifier, QPoint(x, y))
        QTest.mouseDClick(self.drill.table.viewport(),
                          Qt.LeftButton, Qt.NoModifier, QPoint(x, y))
        QTest.keyClicks(self.drill.table.viewport().focusWidget(), text)
        QTest.keyClick(self.drill.table.viewport().focusWidget(), Qt.Key_Tab)
Exemplo n.º 10
0
    def test_plot_name_double_clicked_calls_presenter_and_makes_plot_current(
            self):
        plot_names = ["Plot1", "Plot2", "Plot3"]
        self.widget.set_plot_list(plot_names)

        model_index = self.widget.list_view.model().index(1, 0)
        item_center = self.widget.list_view.visualRect(model_index).center()
        # This single click should not be required, but otherwise the double click is not registered
        QTest.mouseClick(self.widget.list_view.viewport(),
                         Qt.LeftButton,
                         pos=item_center)
        QTest.mouseDClick(self.widget.list_view.viewport(),
                          Qt.LeftButton,
                          pos=item_center)

        self.assertEqual(self.presenter.list_double_clicked.call_count, 1)
        self.assertEqual(self.widget.get_currently_selected_plot_name(),
                         plot_names[1])
Exemplo 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()
Exemplo n.º 12
0
    def editSettings(self, settingValues, mDialog):
        """
        Edit the settings window. This method will edit all the provided
        settings and set them to their correcponding value.

        Args:
            settingValues (dict(str:str)): setting name and value to be set
        """
        QTest.mouseClick(self.drill.settings, Qt.LeftButton)
        sw = self.drill.children()[-1]
        form = sw.formLayout
        widgets = dict()
        for i in range(0, sw.formLayout.rowCount()):
            label = form.itemAt(i, QFormLayout.LabelRole).widget().text()
            widget = form.itemAt(i, QFormLayout.FieldRole).widget()
            widgets[label] = widget
        for name,value in settingValues.items():
            if name in widgets:
                if isinstance(widgets[name], QLineEdit):
                    QTest.mouseClick(widgets[name], Qt.LeftButton)
                    QTest.mouseDClick(widgets[name], Qt.LeftButton)
                    widgets[name].clear()
                    QTest.keyClicks(widgets[name], value)
                    QTest.keyClick(widgets[name], Qt.Key_Tab)
                elif isinstance(widgets[name], QComboBox):
                    v = widgets[name].view()
                    m = widgets[name].model()
                    for i in range(m.rowCount()):
                        index = m.index(i, 0)
                        text = index.data(Qt.DisplayRole)
                        if text == name:
                            v.scrollTo(index)
                            pos = index.center()
                            Qt.mouseClick(v.viewport(), Qt.LeftButton, 0, pos)
                            break
        QTest.mouseClick(sw.okButton, Qt.LeftButton)