From 961f630acba88a7b26cfc2cd219cb5eea7fb46cc Mon Sep 17 00:00:00 2001 From: Blake Harnden <32446120+bharnden@users.noreply.github.com> Date: Tue, 13 Oct 2020 06:45:37 -0700 Subject: [PATCH] pygui: added option to hide/show links with 100% loss, added checks to flag links for this case --- daemon/core/gui/dialogs/linkconfig.py | 1 + daemon/core/gui/graph/edges.py | 15 +++++++++++---- daemon/core/gui/graph/graph.py | 8 +++++++- daemon/core/gui/graph/tags.py | 1 + daemon/core/gui/menubar.py | 5 +++++ 5 files changed, 25 insertions(+), 5 deletions(-) diff --git a/daemon/core/gui/dialogs/linkconfig.py b/daemon/core/gui/dialogs/linkconfig.py index 68ee8eff..9815a374 100644 --- a/daemon/core/gui/dialogs/linkconfig.py +++ b/daemon/core/gui/dialogs/linkconfig.py @@ -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: diff --git a/daemon/core/gui/graph/edges.py b/daemon/core/gui/graph/edges.py index f16b5576..fdd54358 100644 --- a/daemon/core/gui/graph/edges.py +++ b/daemon/core/gui/graph/edges.py @@ -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, "", self.show_context) self.canvas.tag_bind(self.id, "", 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" diff --git a/daemon/core/gui/graph/graph.py b/daemon/core/gui/graph/graph.py index 9ca978a3..d3e38851 100644 --- a/daemon/core/gui/graph/graph.py +++ b/daemon/core/gui/graph/graph.py @@ -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) diff --git a/daemon/core/gui/graph/tags.py b/daemon/core/gui/graph/tags.py index b7b35517..3d3c3611 100644 --- a/daemon/core/gui/graph/tags.py +++ b/daemon/core/gui/graph/tags.py @@ -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" diff --git a/daemon/core/gui/menubar.py b/daemon/core/gui/menubar.py index ebbac677..fa7853ad 100644 --- a/daemon/core/gui/menubar.py +++ b/daemon/core/gui/menubar.py @@ -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,