Пример #1
0
def mouse_click_item_view(model, view, index, delay):
    """ Perform mouse click on the given QAbstractItemModel (model) and
    QAbstractItemView (view) with the given row and column.

    Parameters
    ----------
    model : QAbstractItemModel
        Model from which QModelIndex will be obtained
    view : QAbstractItemView
        View from which the widget identified by the index will be
        found and key sequence be performed.
    index : QModelIndex

    Raises
    ------
    LookupError
        If the index cannot be located.
        Note that the index error provides more
    """
    check_q_model_index_valid(index)
    rect = view.visualRect(index)
    QTest.mouseClick(
        view.viewport(),
        QtCore.Qt.LeftButton,
        QtCore.Qt.NoModifier,
        rect.center(),
        delay=delay,
    )
Пример #2
0
def mouse_click_qwidget(control, delay):
    """Performs a mouce click on a Qt widget.

    Parameters
    ----------
    control : Qwidget
        The Qt widget to be clicked.
    delay : int
        Time delay (in ms) in which click will be performed.
    """

    # for QAbstractButtons we do not use QTest.mouseClick as it assumes the
    # center of the widget as the location to be clicked, which may be
    # incorrect. For QAbstractButtons we can simply call their click method.
    if isinstance(control, QtGui.QAbstractButton):
        if delay > 0:
            QTest.qSleep(delay)
        control.click()
    elif control is not None:
        QTest.mouseClick(
            control,
            QtCore.Qt.MouseButton.LeftButton,
            delay=delay,
        )
    else:
        raise ValueError("control is None")
Пример #3
0
def mouse_click_tab_index(tab_widget, index, delay):
    """ Performs a mouse click on a tab at an index in a QtGui.QTabWidget.

    Parameters
    ----------
    tab_widget : QtGui.QTabWidget
        The tab widget containing the tab to be clicked.
    index : int
        The index of the tab to be clicked.
    delay : int
        Time delay (in ms) in which click will be performed.

    Raises
    ------
    IndexError
        If the index is out of range.
    """
    if not 0 <= index < tab_widget.count():
        raise IndexError(index)
    tabbar = tab_widget.tabBar()
    rect = tabbar.tabRect(index)
    QTest.mouseClick(
        tabbar,
        QtCore.Qt.LeftButton,
        QtCore.Qt.NoModifier,
        rect.center(),
        delay=delay,
    )
Пример #4
0
def right_click_center(editor):
    """Right click the middle of the widget."""

    if is_wx():
        import wx

        control = editor.control
        event = wx.ListEvent(
            wx.EVT_LIST_ITEM_RIGHT_CLICK.typeId, control.GetId()
        )
        wx.PostEvent(control, event)

    elif is_qt():
        from pyface.qt import QtCore
        from pyface.qt.QtTest import QTest

        view = editor.list_view
        rect = view.rect()
        QTest.mouseClick(
            view.viewport(),
            QtCore.Qt.MouseButton.RightButton,
            QtCore.Qt.KeyboardModifier.NoModifier,
            rect.center(),
        )
    else:
        raise unittest.SkipTest("Test not implemented for this toolkit")
Пример #5
0
def right_click_item(editor, index):
    """Right clicks on the specified item."""

    if is_wx():
        import wx

        control = editor.control
        event = wx.ListEvent(
            wx.EVT_LIST_ITEM_RIGHT_CLICK.typeId, control.GetId()
        )
        event.SetIndex(index)
        wx.PostEvent(control, event)

    elif is_qt():
        from pyface.qt import QtCore
        from pyface.qt.QtTest import QTest

        view = editor.list_view
        q_model_index = view.model().index(index, 0)
        view.scrollTo(q_model_index)
        rect = view.visualRect(q_model_index)
        QTest.mouseClick(
            view.viewport(),
            QtCore.Qt.MouseButton.RightButton,
            QtCore.Qt.KeyboardModifier.NoModifier,
            rect.center(),
        )
    else:
        raise unittest.SkipTest("Test not implemented for this toolkit")
Пример #6
0
def qt_mouse_click_web_view(view, delay):
    """ Perform a mouse click at the center of the web view.

    Note that the page is allowed time to load before and after the mouse
    click.

    Parameters
    ----------
    view : QWebView or QWebEngineView
    """
    from pyface.qt import QtCore
    from pyface.qt.QtTest import QTest

    qt_allow_view_to_load(view)

    if view.focusProxy() is not None:
        # QWebEngineView
        widget = view.focusProxy()
    else:
        # QWebView
        widget = view

    try:
        QTest.mouseClick(
            widget,
            QtCore.Qt.LeftButton,
            QtCore.Qt.NoModifier,
            delay=delay,
        )
    finally:
        qt_allow_view_to_load(view)
Пример #7
0
def mouse_click_qwidget(control, delay):
    """ Performs a mouce click on a Qt widget.

    Parameters
    ----------
    control : Qwidget
        The Qt widget to be clicked.
    delay : int
        Time delay (in ms) in which click will be performed.
    """
    QTest.mouseClick(
        control,
        QtCore.Qt.LeftButton,
        delay=delay,
    )
Пример #8
0
def mouse_click_qlayout(layout, index, delay=0):
    """ Performs a mouse click on a widget at an index in a QLayout.

    Parameters
    ----------
    layout : Qlayout
        The layout containing the widget to be clicked
    index : int
        The index of the widget in the layout to be clicked
    """
    if not 0 <= index < layout.count():
        raise IndexError(index)
    widget = layout.itemAt(index).widget()
    QTest.mouseClick(
        widget,
        QtCore.Qt.LeftButton,
        delay=delay,
    )