pygui ignore adding/removing duplicate wireless link events, ignore wireless link events for node to itself

This commit is contained in:
Blake Harnden 2020-04-14 17:08:42 -07:00
parent 3c4a908fd5
commit 2b97b311ab
2 changed files with 7 additions and 0 deletions

View file

@ -208,6 +208,9 @@ class CoreClient:
node_one_id = event.link.node_one_id
node_two_id = event.link.node_two_id
network_id = event.link.network_id
if node_one_id == node_two_id:
logging.warning("ignoring invalid link: %s", event)
return
canvas_node_one = self.canvas_nodes[node_one_id]
canvas_node_two = self.canvas_nodes[node_two_id]
if event.message_type == core_pb2.MessageType.ADD:

View file

@ -206,6 +206,8 @@ class CanvasGraph(tk.Canvas):
add a wireless edge between 2 canvas nodes
"""
token = create_edge_token(src.id, dst.id, network_id)
if token in self.wireless_edges:
return
src_pos = self.coords(src.id)
dst_pos = self.coords(dst.id)
edge = CanvasWirelessEdge(self, src.id, dst.id, src_pos, dst_pos, token)
@ -222,6 +224,8 @@ class CanvasGraph(tk.Canvas):
self, src: CanvasNode, dst: CanvasNode, network_id: int = None
):
token = create_edge_token(src.id, dst.id, network_id)
if token not in self.wireless_edges:
return
edge = self.wireless_edges.pop(token)
edge.delete()
src.wireless_edges.remove(edge)