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.º 2
0
 def test_workspaceCalculator_enterPressed_rhs_scaling(self):
     presenter = WorkspaceCalculator(None, model=self.model)
     QTest.keyClick(presenter.view.rhs_scaling, Qt.Key_Return)
     # check calls
     self.assertEqual(presenter.model.updateParameters.call_count, 1)
     self.assertEqual(presenter.model.validateInputs.call_count, 0)
     self.assertEqual(presenter.model.performOperation.call_count, 0)
Ejemplo n.º 3
0
 def test_run_dialog_opens_on_return_press(self):
     with patch(createDialogFromName_func_name) as createDialog:
         widget = AlgorithmSelectorWidget()
         self._select_in_tree(widget, 'DoStuff v.2')
         QTest.keyClick(widget.search_box, Qt.Key_Return)
         createDialog.assert_called_once_with('DoStuff', 2, None, False, {},
                                              '', [])
Ejemplo n.º 4
0
    def test_select_all(self):
        w = ConsoleWidget()
        w._append_plain_text('Header\n')
        w._prompt = 'prompt>'
        w._show_prompt()
        control = w._control
        app = QtWidgets.QApplication.instance()

        cursor = w._get_cursor()
        w._insert_plain_text_into_buffer(cursor, "if:\n    pass")

        cursor.clearSelection()
        control.setTextCursor(cursor)

        # "select all" action selects cell first
        w.select_all_smart()
        QTest.keyClick(control, QtCore.Qt.Key_C, QtCore.Qt.ControlModifier)
        copied = app.clipboard().text()
        self.assertEqual(copied,  'if:\n>     pass')

        # # "select all" action triggered a second time selects whole document
        w.select_all_smart()
        QTest.keyClick(control, QtCore.Qt.Key_C, QtCore.Qt.ControlModifier)
        copied = app.clipboard().text()
        self.assertEqual(copied,  'Header\nprompt>if:\n>     pass')
Ejemplo n.º 5
0
 def test_execute_on_return_press(self):
     with patch(
             'mantidqt.interfacemanager.InterfaceManager.createDialogFromName'
     ) as createDialog:
         widget = AlgorithmSelectorWidget()
         self._select_in_tree(widget, 'DoStuff v.2')
         QTest.keyClick(widget.search_box, Qt.Key_Return)
         createDialog.assert_called_once_with('DoStuff', 2)
Ejemplo n.º 6
0
def open_file_in_editor(main_window, fname, directory=None):
    """Open a file using the Editor and its open file dialog"""
    top_level_widgets = QApplication.topLevelWidgets()
    for w in top_level_widgets:
        if isinstance(w, QFileDialog):
            if directory is not None:
                w.setDirectory(directory)
            input_field = w.findChildren(QLineEdit)[0]
            input_field.setText(fname)
            QTest.keyClick(w, Qt.Key_Enter)
Ejemplo n.º 7
0
def open_file_in_editor(main_window, fname, directory=None):
    """Open a file using the Editor and its open file dialog"""
    top_level_widgets = QApplication.topLevelWidgets()
    for w in top_level_widgets:
        if isinstance(w, QFileDialog):
            if directory is not None:
                w.setDirectory(directory)
            input_field = w.findChildren(QLineEdit)[0]
            input_field.setText(fname)
            QTest.keyClick(w, Qt.Key_Enter)
Ejemplo n.º 8
0
def test_auto_call(qtbot, magic_func):
    """Test that changing a parameter calls the function."""
    from qtpy.QtTest import QTest

    # TODO: remove qtbot requirement so we can test other backends eventually.
    # changing the widget parameter calls the function
    with qtbot.waitSignal(magic_func.called, timeout=1000):
        magic_func.b.value = 6

    # changing the gui calls the function
    with qtbot.waitSignal(magic_func.called, timeout=1000):
        QTest.keyClick(magic_func.a.native, Qt.Key_A, Qt.ControlModifier)
        QTest.keyClick(magic_func.a.native, Qt.Key_Delete)
Ejemplo n.º 9
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.º 10
0
 def test_common_path_complete(self):
     with TemporaryDirectory() as tmpdir:
         items = [
             os.path.join(tmpdir, "common/common1/item1"),
             os.path.join(tmpdir, "common/common1/item2"),
             os.path.join(tmpdir, "common/common1/item3")
         ]
         for item in items:
             os.makedirs(item)
         w = CompletionWidget(self.console)
         w.show_items(self.text_edit.textCursor(), items)
         self.assertEqual(w.currentItem().text(), '/item1')
         QTest.keyClick(w, QtCore.Qt.Key_Down)
         self.assertEqual(w.currentItem().text(), '/item2')
         QTest.keyClick(w, QtCore.Qt.Key_Down)
         self.assertEqual(w.currentItem().text(), '/item3')
Ejemplo n.º 11
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.º 12
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)
Ejemplo n.º 13
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)
Ejemplo n.º 14
0
    def test_indent(self):
        """Test the event handling code for indent/dedent keypresses ."""
        w = ConsoleWidget()
        w._append_plain_text('Header\n')
        w._prompt = 'prompt>'
        w._show_prompt()
        control = w._control

        # TAB with multiline selection should block-indent
        w._set_input_buffer("")
        c = control.textCursor()
        pos=c.position()
        w._set_input_buffer("If 1:\n    pass")
        c.setPosition(pos, QtGui.QTextCursor.KeepAnchor)
        control.setTextCursor(c)
        QTest.keyClick(control, QtCore.Qt.Key_Tab)
        self.assertEqual(w._get_input_buffer(),"    If 1:\n        pass")

        # TAB with multiline selection, should block-indent to next multiple
        # of 4 spaces, if first line has 0 < indent < 4
        w._set_input_buffer("")
        c = control.textCursor()
        pos=c.position()
        w._set_input_buffer(" If 2:\n     pass")
        c.setPosition(pos, QtGui.QTextCursor.KeepAnchor)
        control.setTextCursor(c)
        QTest.keyClick(control, QtCore.Qt.Key_Tab)
        self.assertEqual(w._get_input_buffer(),"    If 2:\n        pass")

        # Shift-TAB with multiline selection should block-dedent
        w._set_input_buffer("")
        c = control.textCursor()
        pos=c.position()
        w._set_input_buffer("    If 3:\n        pass")
        c.setPosition(pos, QtGui.QTextCursor.KeepAnchor)
        control.setTextCursor(c)
        QTest.keyClick(control, QtCore.Qt.Key_Backtab)
        self.assertEqual(w._get_input_buffer(),"If 3:\n    pass")
Ejemplo n.º 15
0
 def test_droplist_completer_keyboard(self):
     w = CompletionWidget(self.console)
     w.show_items(self.text_edit.textCursor(), ["item1", "item2", "item3"])
     QTest.keyClick(w, QtCore.Qt.Key_PageDown)
     QTest.keyClick(w, QtCore.Qt.Key_Enter)
     self.assertEqual(self.text_edit.toPlainText(), "item3")
Ejemplo n.º 16
0
 def test_execute_on_return_press(self):
     with patch('mantidqt.widgets.interfacemanager.InterfaceManager.createDialogFromName') as createDialog:
         widget = AlgorithmSelectorWidget()
         self._select_in_tree(widget, 'DoStuff v.2')
         QTest.keyClick(widget.search_box, Qt.Key_Return)
         createDialog.assert_called_once_with('DoStuff', 2)
Ejemplo n.º 17
0
 def test_run_dialog_opens_on_return_press(self):
     with patch(createDialogFromName_func_name) as createDialog:
         widget = AlgorithmSelectorWidget()
         self._select_in_tree(widget, 'DoStuff v.2')
         QTest.keyClick(widget.search_box, Qt.Key_Return)
         createDialog.assert_called_once_with('DoStuff', 2)
Ejemplo n.º 18
0
 def test_delete_key_pressed_calls_presenter(self):
     QTest.keyClick(self.view.close_button, Qt.Key_Delete)
     self.assertEquals(self.presenter.close_action_called.call_count, 1)
     QTest.keyClick(self.view.close_button, Qt.Key_Delete)
     self.assertEquals(self.presenter.close_action_called.call_count, 2)
Ejemplo n.º 19
0
 def test_delete_key_pressed_calls_presenter(self):
     QTest.keyClick(self.view.close_button, Qt.Key_Delete)
     self.assertEqual(self.presenter.close_action_called.call_count, 1)
     QTest.keyClick(self.view.close_button, Qt.Key_Delete)
     self.assertEqual(self.presenter.close_action_called.call_count, 2)
Ejemplo n.º 20
0
    def test_keypresses(self):
        """Test the event handling code for keypresses."""
        w = ConsoleWidget()
        w._append_plain_text('Header\n')
        w._prompt = 'prompt>'
        w._show_prompt()
        app = QtWidgets.QApplication.instance()
        control = w._control

        # Test setting the input buffer
        w._set_input_buffer('test input')
        self.assertEqual(w._get_input_buffer(), 'test input')

        # Ctrl+K kills input until EOL
        w._set_input_buffer('test input')
        c = control.textCursor()
        c.setPosition(c.position() - 3)
        control.setTextCursor(c)
        QTest.keyClick(control, QtCore.Qt.Key_K, QtCore.Qt.ControlModifier)
        self.assertEqual(w._get_input_buffer(), 'test in')

        # Ctrl+V pastes
        w._set_input_buffer('test input ')
        app.clipboard().setText('pasted text')
        QTest.keyClick(control, QtCore.Qt.Key_V, QtCore.Qt.ControlModifier)
        self.assertEqual(w._get_input_buffer(), 'test input pasted text')
        self.assertEqual(control.document().blockCount(), 2)

        # Paste should strip indentation
        w._set_input_buffer('test input ')
        app.clipboard().setText('    pasted text')
        QTest.keyClick(control, QtCore.Qt.Key_V, QtCore.Qt.ControlModifier)
        self.assertEqual(w._get_input_buffer(), 'test input pasted text')
        self.assertEqual(control.document().blockCount(), 2)

        # Multiline paste, should also show continuation marks
        w._set_input_buffer('test input ')
        app.clipboard().setText('line1\nline2\nline3')
        QTest.keyClick(control, QtCore.Qt.Key_V, QtCore.Qt.ControlModifier)
        self.assertEqual(w._get_input_buffer(),
                         'test input line1\nline2\nline3')
        self.assertEqual(control.document().blockCount(), 4)
        self.assertEqual(control.document().findBlockByNumber(1).text(),
                         'prompt>test input line1')
        self.assertEqual(control.document().findBlockByNumber(2).text(),
                         '> line2')
        self.assertEqual(control.document().findBlockByNumber(3).text(),
                         '> line3')

        # Multiline paste should strip indentation intelligently
        # in the case where pasted text has leading whitespace on first line
        # and we're pasting into indented position
        w._set_input_buffer('    ')
        app.clipboard().setText('    If 1:\n        pass')
        QTest.keyClick(control, QtCore.Qt.Key_V, QtCore.Qt.ControlModifier)
        self.assertEqual(w._get_input_buffer(),
                         '    If 1:\n        pass')

        # Ctrl+Backspace should intelligently remove the last word
        w._set_input_buffer("foo = ['foo', 'foo', 'foo',    \n"
                            "       'bar', 'bar', 'bar']")
        QTest.keyClick(control, QtCore.Qt.Key_Backspace,
                       QtCore.Qt.ControlModifier)
        self.assertEqual(w._get_input_buffer(),
                         ("foo = ['foo', 'foo', 'foo',    \n"
                          "       'bar', 'bar', '"))
        QTest.keyClick(control, QtCore.Qt.Key_Backspace,
                       QtCore.Qt.ControlModifier)
        QTest.keyClick(control, QtCore.Qt.Key_Backspace,
                       QtCore.Qt.ControlModifier)
        self.assertEqual(w._get_input_buffer(),
                         ("foo = ['foo', 'foo', 'foo',    \n"
                          "       '"))
        QTest.keyClick(control, QtCore.Qt.Key_Backspace,
                       QtCore.Qt.ControlModifier)
        self.assertEqual(w._get_input_buffer(),
                         ("foo = ['foo', 'foo', 'foo',    \n"
                          ""))
        QTest.keyClick(control, QtCore.Qt.Key_Backspace,
                       QtCore.Qt.ControlModifier)
        self.assertEqual(w._get_input_buffer(),
                         "foo = ['foo', 'foo', 'foo',")

        # Ctrl+Delete should intelligently remove the next word
        w._set_input_buffer("foo = ['foo', 'foo', 'foo',    \n"
                            "       'bar', 'bar', 'bar']")
        c = control.textCursor()
        c.setPosition(35)
        control.setTextCursor(c)
        QTest.keyClick(control, QtCore.Qt.Key_Delete,
                       QtCore.Qt.ControlModifier)
        self.assertEqual(w._get_input_buffer(),
                         ("foo = ['foo', 'foo', ',    \n"
                          "       'bar', 'bar', 'bar']"))
        QTest.keyClick(control, QtCore.Qt.Key_Delete,
                       QtCore.Qt.ControlModifier)
        self.assertEqual(w._get_input_buffer(),
                         ("foo = ['foo', 'foo', \n"
                          "       'bar', 'bar', 'bar']"))
        QTest.keyClick(control, QtCore.Qt.Key_Delete,
                       QtCore.Qt.ControlModifier)
        self.assertEqual(w._get_input_buffer(),
                         "foo = ['foo', 'foo', 'bar', 'bar', 'bar']")
        w._set_input_buffer("foo = ['foo', 'foo', 'foo',    \n"
                            "       'bar', 'bar', 'bar']")
        c = control.textCursor()
        c.setPosition(48)
        control.setTextCursor(c)
        QTest.keyClick(control, QtCore.Qt.Key_Delete,
                       QtCore.Qt.ControlModifier)
        self.assertEqual(w._get_input_buffer(),
                         ("foo = ['foo', 'foo', 'foo',    \n"
                          "'bar', 'bar', 'bar']"))

        # Left and right keys should respect the continuation prompt
        w._set_input_buffer("line 1\n"
                            "line 2\n"
                            "line 3")
        c = control.textCursor()
        c.setPosition(20)  # End of line 1
        control.setTextCursor(c)
        QTest.keyClick(control, QtCore.Qt.Key_Right)
        # Cursor should have moved after the continuation prompt
        self.assertEqual(control.textCursor().position(), 23)
        QTest.keyClick(control, QtCore.Qt.Key_Left)
        # Cursor should have moved to the end of the previous line
        self.assertEqual(control.textCursor().position(), 20)