Skip to content

Commit 5cb465f

Browse files
author
alexej
committed
improved encapsulation
1 parent 6da044b commit 5cb465f

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

connection_list.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,9 @@ def all(self):
2222

2323
def filter(self, predicate):
2424
return [c for c in self._connections if predicate(c)]
25+
26+
def remove_connections_for_node(self, node):
27+
self._connections = [
28+
c for c in self._connections
29+
if c.start_node != node and c.end_node != node
30+
]

editor.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -296,17 +296,20 @@ def try_delete_connection(self, world_x, world_y):
296296
return True
297297
return False
298298

299-
def try_delete_node(self, world_x, world_y):
299+
def try_delete_node(self, world_x: float, world_y: float) -> bool:
300+
"""
301+
Try to delete the node at the given world coordinates.
302+
Removes all connections to/from the node and updates the graph.
303+
Returns True if a node was deleted, False otherwise.
304+
"""
300305
for node in reversed(self.nodes):
301306
if node.contains_point(world_x, world_y):
302307
# Remove all connections to/from this node
303-
self.connections._connections = [
304-
c for c in self.connections
305-
if c.start_node != node and c.end_node != node
306-
]
308+
self.connections.remove_connections_for_node(node)
307309
self.undo_stack.push(copy.deepcopy(self.nx_graph))
308310
self.nodes.remove(node)
309-
self.nx_graph.remove_node(node.id)
311+
if node.id in self.nx_graph.nodes:
312+
self.nx_graph.remove_node(node.id)
310313
node.selected = False # Deselect the node if it was selected
311314
return True
312315
return False

0 commit comments

Comments
 (0)