def test_get_unselected_item_at_point(view, box):
    box.width = 50
    box.height = 50
    view.selection.select_items(box)

    assert item_at_point(view, (10, 10)) is box
    assert item_at_point(view, (10, 10), exclude=(box, )) is None
def test_get_item_at_point(view, box):
    """Hover tool only reacts on motion-notify events."""
    box.width = 50
    box.height = 50
    view.request_update((box, ))

    assert item_at_point(view, (10, 10)) is box
    assert item_at_point(view, (60, 10)) is None
Esempio n. 3
0
    def move(self, pos):
        """Move the item.

        x and y are in view coordinates.
        """
        super().move(pos)
        item = self.item
        view = self.view
        x, y = pos

        current_parent = item.parent
        over_item = item_at_point(view, (x, y), selected=False)

        if not over_item:
            view.selection.dropzone_item = None
            return

        if current_parent and not over_item:
            # are we going to remove from parent?
            group = Group(current_parent, item)
            if group:
                view.selection.dropzone_item = current_parent
                current_parent.request_update(matrix=False)

        if over_item:
            # are we going to add to parent?
            group = Group(over_item, item)
            if group and group.can_contain():
                view.selection.dropzone_item = over_item
                over_item.request_update(matrix=False)
Esempio n. 4
0
def on_drag_begin(gesture, start_x, start_y, segment_state):
    view = gesture.get_widget()
    pos = (start_x, start_y)
    item = item_at_point(view, pos)
    handle = item and maybe_split_segment(view, item, pos)
    if handle:
        segment_state.moving = HandleMove(item, handle, view)
        gesture.set_state(Gtk.EventSequenceState.CLAIMED)
    else:
        gesture.set_state(Gtk.EventSequenceState.DENIED)
Esempio n. 5
0
def on_motion(controller, x, y, item_class: Type[Presentation]):
    view: GtkView = controller.get_widget()
    model = view.model

    try:
        parent = item_at_point(view, (x, y))
    except KeyError:
        parent = None

    if parent:
        adapter_type = Group.registry.get_registration(type(parent), item_class)
        # No in depth check is done to see if we can actually connect,
        # since we only have the item_class, not an actual item.
        view.selection.dropzone_item = parent if adapter_type else None
        model.request_update(parent, matrix=False)
    else:
        if view.selection.dropzone_item:
            model.request_update(view.selection.dropzone_item)
        view.selection.dropzone_item = None
Esempio n. 6
0
def on_motion(controller, x, y, item_class: Type[Presentation]):
    view: GtkView = controller.get_widget()
    model = view.model

    try:
        parent = item_at_point(view, (x, y))
    except KeyError:
        parent = None

    if parent:
        parent_type = type(parent)
        dropzone = has_registration(Group, parent_type, item_class) or has_registration(  # type: ignore[arg-type]
            Connector, parent_type, item_class  # type: ignore[arg-type]
        )
        view.selection.dropzone_item = parent if dropzone else None
        model.request_update(parent, matrix=False)
    else:
        if view.selection.dropzone_item:
            model.request_update(view.selection.dropzone_item)
        view.selection.dropzone_item = None
Esempio n. 7
0
def on_motion(controller, x, y, item_class):
    view: GtkView = controller.get_widget()
    model = view.model

    try:
        parent = item_at_point(view, (x, y))
    except KeyError:
        parent = None

    if parent:
        # create dummy adapter
        connections = Connections()
        adapter = Group(parent, item_class(connections))
        if adapter and adapter.can_contain():
            view.selection.dropzone_item = parent
        else:
            view.selection.dropzone_item = None
        model.request_update(parent, matrix=False)
    else:
        if view.selection.dropzone_item:
            model.request_update(view.selection.dropzone_item)
        view.selection.dropzone_item = None
Esempio n. 8
0
def find_item_at_point(view: GtkView, pos: Pos) -> Optional[Item]:
    item, handle = handle_at_point(view, pos)
    return item or item_at_point(view, pos)