def test_message_dialog_is_shown_on_duplicate_accel_assignment(
        accel_params, expected):
    """
    Tests that a message dialog appears every time a duplicate key binding accelerator
    is attempted to be assigned to a different action in `Preferences > Keybindings`,
    and doesn't appear if a key binding accelerator is not a duplicate.
    """
    from terminatorlib import terminal
    from terminatorlib import prefseditor

    path, key, mods, code = accel_params

    term = terminal.Terminal()
    prefs_editor = prefseditor.PrefsEditor(term=term)
    message_dialog = MessageDialogToken()
    # Check for an active message dialog every second
    GLib.timeout_add_seconds(1, detect_close_message_dialog, prefs_editor,
                             message_dialog)

    widget = prefs_editor.builder.get_object("keybindingtreeview")
    liststore = widget.get_model()

    # Replace default accelerator with a test one
    prefs_editor.on_cellrenderer_accel_edited(liststore=liststore,
                                              path=path,
                                              key=key,
                                              mods=mods,
                                              _code=code)

    assert message_dialog.has_appeared == expected

    reset_config_keybindings()
def test_keybinding_edit_produce_expected_accels(input_key_params,
                                                 expected_accel):
    """
    Tests that editing a key binding using a predefined key combination
    `input_key_params` produces the expected accelerator.
    """
    from terminatorlib import terminal
    from terminatorlib import prefseditor

    term = terminal.Terminal()
    prefs_editor = prefseditor.PrefsEditor(term=term)

    widget = prefs_editor.builder.get_object("keybindingtreeview")
    liststore = widget.get_model()

    path = 0  # Edit the first listed key binding in `Preferences>Keybindings`
    key, mods, hardware_keycode = input_key_params

    prefs_editor.on_cellrenderer_accel_edited(
        liststore=liststore,
        path=str(path),
        key=key,
        mods=mods,
        _code=hardware_keycode,
    )

    liststore_iter = liststore.get_iter(path)
    keyval_after_edit = liststore.get_value(liststore_iter, 2)
    mods_after_edit = Gdk.ModifierType(liststore.get_value(liststore_iter, 3))

    accel_after_edit = (keyval_after_edit, mods_after_edit)

    assert accel_after_edit == expected_accel
Ejemplo n.º 3
0
def test_keybinding_successfully_reassigned_after_clearing(accel_params):
    """
    Tests that a key binding is successfully reassigned after it has been cleared,
    that is no error is thrown at any stage.
    """
    from terminatorlib import terminal
    from terminatorlib import prefseditor

    term = terminal.Terminal()
    prefs_editor = prefseditor.PrefsEditor(term=term)

    widget = prefs_editor.builder.get_object("keybindingtreeview")
    liststore = widget.get_model()

    path, key, mods, hardware_keycode = accel_params
    # Assign a key binding
    prefs_editor.on_cellrenderer_accel_edited(
        liststore=liststore,
        path=path,
        key=key,
        mods=mods,
        _code=hardware_keycode,
    )
    # Clear the key binding
    prefs_editor.on_cellrenderer_accel_cleared(liststore=liststore, path=path)
    # Reassign the key binding
    prefs_editor.on_cellrenderer_accel_edited(
        liststore=liststore,
        path=path,
        key=key,
        mods=mods,
        _code=hardware_keycode,
    )

    reset_config_keybindings()
def test_duplicate_accels_not_possible_to_set(accel_params):
    """
    Tests that a duplicate key binding accelerator, that is a key binding accelerator
    which is already defined in the config cannot be used to refer to more than
    one action.
    """
    from terminatorlib import config
    from terminatorlib import terminal
    from terminatorlib import prefseditor

    path, key, mods, code = accel_params

    term = terminal.Terminal()
    prefs_editor = prefseditor.PrefsEditor(term=term)
    message_dialog = MessageDialogToken()

    # Check for an active message dialog every second
    GLib.timeout_add_seconds(1, detect_close_message_dialog, prefs_editor,
                             message_dialog)

    widget = prefs_editor.builder.get_object("keybindingtreeview")
    liststore = widget.get_model()
    binding = liststore.get_value(liststore.get_iter(path), 0)

    all_default_accelerators = {
        Gtk.accelerator_parse(accel)
        for accel in config.DEFAULTS["keybindings"].values()
        if accel != ""  # ignore empty key bindings
    }
    # Check that a test accelerator is indeed a duplicate
    assert (key, mods) in all_default_accelerators

    default_accelerator = Gtk.accelerator_parse(
        config.DEFAULTS["keybindings"][binding])

    # Replace default accelerator with a test one
    prefs_editor.on_cellrenderer_accel_edited(liststore=liststore,
                                              path=path,
                                              key=key,
                                              mods=mods,
                                              _code=code)

    new_accelerator = Gtk.accelerator_parse(
        prefs_editor.config["keybindings"][binding])

    # Key binding accelerator value shouldn't have changed
    assert default_accelerator == new_accelerator

    reset_config_keybindings()
Ejemplo n.º 5
0
 def make_terminal(**kwargs):
     """Make a Terminal"""
     from terminatorlib import terminal
     return terminal.Terminal()