pygui: small cleanup to add some utility functions to edges
This commit is contained in:
parent
886b56cf8c
commit
e7c721989f
2 changed files with 35 additions and 22 deletions
|
@ -125,9 +125,7 @@ class ShadowNode:
|
|||
|
||||
def should_delete(self) -> bool:
|
||||
for edge in self.node.edges:
|
||||
other_node = edge.src
|
||||
if self.node == edge.src:
|
||||
other_node = edge.dst
|
||||
other_node = edge.other_node(self.node)
|
||||
if not other_node.is_wireless() and other_node.canvas == self.canvas:
|
||||
return False
|
||||
return True
|
||||
|
@ -181,6 +179,7 @@ class Edge:
|
|||
self.src_shadow: Optional[ShadowNode] = None
|
||||
self.dst: Optional["CanvasNode"] = dst
|
||||
self.dst_shadow: Optional[ShadowNode] = None
|
||||
self.link: Optional[Link] = None
|
||||
self.arc: int = 0
|
||||
self.token: Optional[str] = None
|
||||
self.src_label: Optional[int] = None
|
||||
|
@ -521,6 +520,30 @@ class Edge:
|
|||
self.dst.canvas.itemconfigure(self.dst_label2, state=tk.NORMAL)
|
||||
self.dst.canvas.itemconfigure(self.middle_label2, state=tk.NORMAL)
|
||||
|
||||
def other_node(self, node: "CanvasNode") -> "CanvasNode":
|
||||
if self.src == node:
|
||||
return self.dst
|
||||
elif self.dst == node:
|
||||
return self.src
|
||||
else:
|
||||
raise ValueError(f"node({node.core_node.name}) does not belong to edge")
|
||||
|
||||
def other_iface(self, node: "CanvasNode") -> Optional[Interface]:
|
||||
if self.src == node:
|
||||
return self.link.iface2 if self.link else None
|
||||
elif self.dst == node:
|
||||
return self.link.iface1 if self.link else None
|
||||
else:
|
||||
raise ValueError(f"node({node.core_node.name}) does not belong to edge")
|
||||
|
||||
def iface(self, node: "CanvasNode") -> Optional[Interface]:
|
||||
if self.src == node:
|
||||
return self.link.iface1 if self.link else None
|
||||
elif self.dst == node:
|
||||
return self.link.iface2 if self.link else None
|
||||
else:
|
||||
raise ValueError(f"node({node.core_node.name}) does not belong to edge")
|
||||
|
||||
|
||||
class CanvasWirelessEdge(Edge):
|
||||
tag = tags.WIRELESS_EDGE
|
||||
|
@ -575,7 +598,6 @@ class CanvasEdge(Edge):
|
|||
super().__init__(app, src, dst)
|
||||
self.text_src: Optional[int] = None
|
||||
self.text_dst: Optional[int] = None
|
||||
self.link: Optional[Link] = None
|
||||
self.asymmetric_link: Optional[Link] = None
|
||||
self.throughput: Optional[float] = None
|
||||
self.draw(tk.NORMAL)
|
||||
|
|
|
@ -290,15 +290,11 @@ class CanvasNode:
|
|||
|
||||
unlink_menu = tk.Menu(self.context)
|
||||
for edge in self.edges:
|
||||
link = edge.link
|
||||
if self.id == edge.src.id:
|
||||
other_node = edge.dst
|
||||
other_iface = link.iface2.name if link.iface2 else None
|
||||
else:
|
||||
other_node = edge.src
|
||||
other_iface = link.iface1.name if link.iface1 else None
|
||||
other_name = other_node.core_node.name
|
||||
label = f"{other_name}:{other_iface}" if other_iface else other_name
|
||||
other_node = edge.other_node(self)
|
||||
other_iface = edge.other_iface(self)
|
||||
label = other_node.core_node.name
|
||||
if other_iface:
|
||||
label = f"{label}:{other_iface.name}"
|
||||
func_unlink = functools.partial(self.click_unlink, edge)
|
||||
unlink_menu.add_command(label=label, command=func_unlink)
|
||||
themes.style_menu(unlink_menu)
|
||||
|
@ -368,12 +364,9 @@ class CanvasNode:
|
|||
def has_emane_link(self, iface_id: int) -> Node:
|
||||
result = None
|
||||
for edge in self.edges:
|
||||
if self.id == edge.src.id:
|
||||
other_node = edge.dst
|
||||
edge_iface_id = edge.link.iface1.id
|
||||
else:
|
||||
other_node = edge.src
|
||||
edge_iface_id = edge.link.iface2.id
|
||||
other_node = edge.other_node(self)
|
||||
iface = edge.iface(self)
|
||||
edge_iface_id = iface.id if iface else None
|
||||
if edge_iface_id != iface_id:
|
||||
continue
|
||||
if other_node.core_node.type == NodeType.EMANE:
|
||||
|
@ -442,9 +435,7 @@ class CanvasNode:
|
|||
self.canvas.itemconfig(self.id, state=tk.NORMAL)
|
||||
self.canvas.itemconfig(self.text_id, state=tk.NORMAL)
|
||||
for edge in self.edges:
|
||||
other_node = edge.src
|
||||
if edge.src == self:
|
||||
other_node = edge.dst
|
||||
other_node = edge.other_node(self)
|
||||
if edge.hidden and not other_node.hidden:
|
||||
edge.show()
|
||||
|
||||
|
|
Loading…
Reference in a new issue