Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/glider/gui/node_graph/graph_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
QWheelEvent,
)
from PyQt6.QtWidgets import (
QGraphicsProxyWidget,
QGraphicsScene,
QGraphicsView,
QHBoxLayout,
Expand Down Expand Up @@ -667,7 +668,11 @@ def _finish_connection_at_port(self, target_port) -> None:

def keyPressEvent(self, event: QKeyEvent) -> None:
"""Handle keyboard shortcuts."""
if event.key() == Qt.Key.Key_Delete:
# macOS keyboards label Backspace "delete"; leave both to an embedded
# node widget that has focus so typing in it still works.
if event.key() in (Qt.Key.Key_Delete, Qt.Key.Key_Backspace) and not isinstance(
self._scene.focusItem(), QGraphicsProxyWidget
):
# Delete selected connections first
from glider.gui.node_graph.connection_item import ConnectionItem

Expand Down
2 changes: 1 addition & 1 deletion src/glider/gui/panels/node_editor_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def setup_node_ports(self, node_item, node_type: str) -> None:
"StartExperiment": ([], [">next"]),
"EndExperiment": ([">exec"], []),
"Delay": ([">exec"], [">next"]),
"Timer": (["Interval", "Enabled"], [">Tick", "Count"]),
"Timer": ([], [">Tick", "Count"]),
"Loop": ([">exec"], [">body", ">done"]),
"WaitForInput": ([">exec"], [">triggered"]),
"Output": ([">exec"], [">next"]),
Expand Down
20 changes: 20 additions & 0 deletions tests/unit/gui/test_graph_delete_key.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""The graph's delete shortcut, including macOS's Backspace-labelled "delete" key (#51)."""

import pytest
from PyQt6.QtCore import Qt

from glider.gui.node_graph.graph_view import NodeGraphView


@pytest.mark.parametrize("key", [Qt.Key.Key_Delete, Qt.Key.Key_Backspace])
def test_delete_keys_remove_the_selected_node(qtbot, key):
view = NodeGraphView()
qtbot.addWidget(view)
deleted = []
view.node_deleted.connect(deleted.append)
view.add_node("n1", "Delay", 0, 0)
view._selected_nodes.append("n1")

qtbot.keyClick(view, key)

assert deleted == ["n1"]
8 changes: 3 additions & 5 deletions tests/unit/gui/test_timer_node_exposure.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,15 @@ def test_node_library_offers_timer_node(qtbot):
assert timer_buttons[0].property("nodeCategory") == "Flow"


def test_timer_node_uses_runtime_port_contract():
def test_timer_node_keeps_its_settings_off_the_canvas():
node_item = SimpleNamespace(inputs=[], outputs=[])
node_item.add_input_port = lambda name, port_type: node_item.inputs.append((name, port_type))
node_item.add_output_port = lambda name, port_type: node_item.outputs.append((name, port_type))

NodeEditorController.setup_node_ports(None, node_item, "Timer")

assert node_item.inputs == [
("Interval", PortType.DATA),
("Enabled", PortType.DATA),
]
# Interval and unit live in the properties panel, like Delay's duration.
assert node_item.inputs == []
assert node_item.outputs == [
("Tick", PortType.EXEC),
("Count", PortType.DATA),
Expand Down
Loading