Exemplo n.º 1
0
def key_sequence_item_view(model, view, index, sequence, delay=0):
    """ Perform Key Sequence 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
    sequence : str
        Sequence of characters to be inserted to the widget identifed
        by the row and column.

    Raises
    ------
    Disabled
        If the widget cannot be edited.
    LookupError
        If the index cannot be located.
        Note that the index error provides more
    """
    check_q_model_index_valid(index)
    widget = view.indexWidget(index)
    if widget is None:
        raise Disabled(
            "No editable widget for item at row {!r} and column {!r}".format(
                index.row(), index.column()))
    QTest.keyClicks(widget, sequence, delay=delay)
Exemplo n.º 2
0
def key_click_item_view(model, view, index, key, delay=0):
    """ Perform key press 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 press be performed.
    index : int
    key : str
        Key to be pressed.

    Raises
    ------
    Disabled
        If the widget cannot be edited.
    LookupError
        If the index cannot be located.
        Note that the index error provides more
    """
    check_q_model_index_valid(index)
    widget = view.indexWidget(index)
    if widget is None:
        raise Disabled(
            "No editable widget for item at row {!r} and column {!r}".format(
                index.row(), index.column()))
    key_click(widget, key=key, delay=delay)
Exemplo n.º 3
0
def key_sequence_text_ctrl(control, interaction, delay):
    """ Performs simulated typing of a sequence of keys on the given wxObject
    after a delay.

    Parameters
    ----------
    control : wxTextCtrl
        The wx Object to be acted on.
    interaction : instance of command.KeySequence
        The interaction object holding the sequence of key inputs
        to be simulated being typed
    delay : int
        Time delay (in ms) in which each key click in the sequence will be
        performed.

    Raises
    ------
    Disabled
        If the control is either not enabled or not editable.
    """
    # fail early
    for char in interaction.sequence:
        check_key_compat(char)

    if not (control.IsEnabled() and control.IsEditable()):
        raise Disabled("{!r} is disabled.".format(control))
    if not control.HasFocus():
        control.SetFocus()
        control.SetInsertionPointEnd()
    for char in interaction.sequence:
        wx.MilliSleep(delay)
        control.WriteText(char)
        wx.SafeYield()
Exemplo n.º 4
0
def key_click_text_ctrl(control, interaction, delay):
    """ Performs simulated typing of a key on the given wxObject
    after a delay.

    Parameters
    ----------
    control : wxTextCtrl
        The wx Object to be acted on.
    interaction : instance of command.KeyClick
        The interaction object holding the key input
        to be simulated being typed
    delay : int
        Time delay (in ms) in which the key click will be performed.
    """
    if not control.IsEditable():
        raise Disabled("{!r} is disabled.".format(control))
    if not control.HasFocus():
        control.SetFocus()
        control.SetInsertionPointEnd()
    if interaction.key == "Enter":
        wx.MilliSleep(delay)
        event = wx.CommandEvent(wx.EVT_TEXT_ENTER.typeId, control.GetId())
        control.ProcessEvent(event)
    elif interaction.key == "Backspace":
        wx.MilliSleep(delay)
        if control.GetStringSelection():
            control.Remove(*control.GetSelection())
        else:
            pos = control.GetInsertionPoint()
            control.Remove(max(0, pos - 1), pos)
    else:
        check_key_compat(interaction.key)
        wx.MilliSleep(delay)
        control.WriteText(interaction.key)
Exemplo n.º 5
0
def key_click_text_entry(
        control,
        interaction,
        delay,
        get_selection=lambda control: control.GetSelection(),
):
    """Performs simulated typing of a key on the given wxObject
    after a delay.

    Parameters
    ----------
    control : wxTextEntry
        The wx Object to be acted on.
    interaction : instance of command.KeyClick
        The interaction object holding the key input
        to be simulated being typed
    delay : int
        Time delay (in ms) in which the key click will be performed.
    get_selection: callable(wx.TextEntry) -> tuple(int, int)
        Callable that takes an instance of wx.TextEntry and return the
        current selection span. Default is to call `GetSelection` method.
        Useful for when the TextEntry.GetSelection is overridden by a subclass
        that does not conform to the common API.
    """
    if not (control.IsEnabled() and control.IsEditable()):
        raise Disabled("{!r} is disabled.".format(control))
    if not control.HasFocus():
        control.SetFocus()
        control.SetInsertionPointEnd()
    if interaction.key == "Enter":
        wx.MilliSleep(delay)
        event = wx.CommandEvent(wx.EVT_TEXT_ENTER.typeId, control.GetId())
        control.ProcessEvent(event)
    elif interaction.key == "End":
        wx.MilliSleep(delay)
        control.SetInsertionPointEnd()
    elif interaction.key == "Backspace":
        wx.MilliSleep(delay)
        start, end = get_selection(control)
        if end > start:
            control.Remove(start, end)
        else:
            pos = control.GetInsertionPoint()
            control.Remove(max(0, pos - 1), pos)
    else:
        check_key_compat(interaction.key)
        wx.MilliSleep(delay)
        control.WriteText(interaction.key)
Exemplo n.º 6
0
def key_click_qwidget(control, interaction, delay):
    """ Performs simulated typing of a key on the given widget after a delay.

    Parameters
    ----------
    control : Qwidget
        The Qt widget to be acted on.
    interaction : instance of command.KeyClick
        The interaction object holding the key input
        to be simulated being typed
    delay : int
        Time delay (in ms) in which the key click will be performed.
    """
    if not control.isEnabled():
        raise Disabled("{!r} is disabled.".format(control))
    key_click(control, interaction.key, delay=delay)
Exemplo n.º 7
0
def key_sequence_qwidget(control, interaction, delay):
    """ Performs simulated typing of a sequence of keys on the given widget
    after a delay.

    Parameters
    ----------
    control : Qwidget
        The Qt widget to be acted on.
    interaction : instance of command.KeySequence
        The interaction object holding the sequence of key inputs
        to be simulated being typed
    delay : int
        Time delay (in ms) in which each key click in the sequence will be
        performed.
    """
    if not control.isEnabled():
        raise Disabled("{!r} is disabled.".format(control))
    QTest.keyClicks(control, interaction.sequence, delay=delay)