Merge pull request #526 from coreemu/feature/pygui-hide-loss-links
pygui: added option to hide/show links with 100% loss, added checks t…
This commit is contained in:
commit
e817a24275
5 changed files with 25 additions and 5 deletions
|
@ -270,6 +270,7 @@ class LinkConfigurationDialog(Dialog):
|
|||
|
||||
# update edge label
|
||||
self.edge.draw_link_options()
|
||||
self.edge.check_options()
|
||||
self.destroy()
|
||||
|
||||
def change_symmetry(self) -> None:
|
||||
|
|
|
@ -17,6 +17,7 @@ if TYPE_CHECKING:
|
|||
TEXT_DISTANCE: int = 60
|
||||
EDGE_WIDTH: int = 3
|
||||
EDGE_COLOR: str = "#ff0000"
|
||||
EDGE_LOSS: float = 100.0
|
||||
WIRELESS_WIDTH: float = 3
|
||||
WIRELESS_COLOR: str = "#009933"
|
||||
ARC_DISTANCE: int = 50
|
||||
|
@ -305,10 +306,6 @@ class CanvasEdge(Edge):
|
|||
self.canvas.tag_bind(self.id, "<ButtonRelease-3>", self.show_context)
|
||||
self.canvas.tag_bind(self.id, "<Button-1>", self.show_info)
|
||||
|
||||
def set_link(self, link: Link) -> None:
|
||||
self.link = link
|
||||
self.draw_labels()
|
||||
|
||||
def iface_label(self, iface: Interface) -> str:
|
||||
label = ""
|
||||
if iface.name and self.canvas.show_iface_names.get():
|
||||
|
@ -341,6 +338,16 @@ class CanvasEdge(Edge):
|
|||
super().redraw()
|
||||
self.draw_labels()
|
||||
|
||||
def check_options(self) -> None:
|
||||
if self.link.options.loss == EDGE_LOSS:
|
||||
state = tk.HIDDEN
|
||||
self.canvas.addtag_withtag(tags.LOSS_EDGES, self.id)
|
||||
else:
|
||||
state = tk.NORMAL
|
||||
self.canvas.dtag(self.id, tags.LOSS_EDGES)
|
||||
if self.canvas.show_loss_links.state() == tk.HIDDEN:
|
||||
self.canvas.itemconfigure(self.id, state=state)
|
||||
|
||||
def set_throughput(self, throughput: float) -> None:
|
||||
throughput = 0.001 * throughput
|
||||
text = f"{throughput:.3f} kbps"
|
||||
|
|
|
@ -110,6 +110,7 @@ class CanvasGraph(tk.Canvas):
|
|||
self.show_wireless: ShowVar = ShowVar(self, tags.WIRELESS_EDGE, value=True)
|
||||
self.show_grid: ShowVar = ShowVar(self, tags.GRIDLINE, value=True)
|
||||
self.show_annotations: ShowVar = ShowVar(self, tags.ANNOTATION, value=True)
|
||||
self.show_loss_links: ShowVar = ShowVar(self, tags.LOSS_EDGES, value=True)
|
||||
self.show_iface_names: BooleanVar = BooleanVar(value=False)
|
||||
self.show_ip4s: BooleanVar = BooleanVar(value=True)
|
||||
self.show_ip6s: BooleanVar = BooleanVar(value=True)
|
||||
|
@ -147,6 +148,7 @@ class CanvasGraph(tk.Canvas):
|
|||
self.show_iface_names.set(False)
|
||||
self.show_ip4s.set(True)
|
||||
self.show_ip6s.set(True)
|
||||
self.show_loss_links.set(True)
|
||||
|
||||
# delete any existing drawn items
|
||||
for tag in tags.RESET_TAGS:
|
||||
|
@ -250,6 +252,8 @@ class CanvasGraph(tk.Canvas):
|
|||
edge = self.edges.get(token)
|
||||
if edge:
|
||||
edge.link.options = deepcopy(link.options)
|
||||
edge.draw_link_options()
|
||||
edge.check_options()
|
||||
|
||||
def add_wireless_edge(self, src: CanvasNode, dst: CanvasNode, link: Link) -> None:
|
||||
network_id = link.network_id if link.network_id else None
|
||||
|
@ -902,6 +906,7 @@ class CanvasGraph(tk.Canvas):
|
|||
edge.complete(dst.id, linked_wireless)
|
||||
if link is None:
|
||||
link = self.core.create_link(edge, src, dst)
|
||||
edge.link = link
|
||||
if link.iface1:
|
||||
iface1 = link.iface1
|
||||
src.ifaces[iface1.id] = iface1
|
||||
|
@ -910,9 +915,10 @@ class CanvasGraph(tk.Canvas):
|
|||
dst.ifaces[iface2.id] = iface2
|
||||
src.edges.add(edge)
|
||||
dst.edges.add(edge)
|
||||
edge.set_link(link)
|
||||
edge.token = create_edge_token(src.id, dst.id, edge.link)
|
||||
self.arc_common_edges(edge)
|
||||
edge.draw_labels()
|
||||
edge.check_options()
|
||||
self.edges[edge.token] = edge
|
||||
self.core.save_edge(edge, src, dst)
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ GRIDLINE: str = "gridline"
|
|||
SHAPE: str = "shape"
|
||||
SHAPE_TEXT: str = "shapetext"
|
||||
EDGE: str = "edge"
|
||||
LOSS_EDGES: str = "loss-edge"
|
||||
LINK_LABEL: str = "linklabel"
|
||||
WIRELESS_EDGE: str = "wireless"
|
||||
ANTENNA: str = "antenna"
|
||||
|
|
|
@ -172,6 +172,11 @@ class Menubar(tk.Menu):
|
|||
command=self.canvas.show_links.click_handler,
|
||||
variable=self.canvas.show_links,
|
||||
)
|
||||
menu.add_checkbutton(
|
||||
label="Loss Links",
|
||||
command=self.canvas.show_loss_links.click_handler,
|
||||
variable=self.canvas.show_loss_links,
|
||||
)
|
||||
menu.add_checkbutton(
|
||||
label="Wireless Links",
|
||||
command=self.canvas.show_wireless.click_handler,
|
||||
|
|
Loading…
Reference in a new issue