From bb2ceaf99307ca75e21018712faf658c29187064 Mon Sep 17 00:00:00 2001 From: Blake Harnden <32446120+bharnden@users.noreply.github.com> Date: Tue, 23 Jun 2020 22:53:48 -0700 Subject: [PATCH] pygui: draw link options on edges --- daemon/core/gui/dialogs/linkconfig.py | 2 ++ daemon/core/gui/graph/edges.py | 35 +++++++++++++++++++++++++++ daemon/core/gui/graph/graph.py | 1 + 3 files changed, 38 insertions(+) diff --git a/daemon/core/gui/dialogs/linkconfig.py b/daemon/core/gui/dialogs/linkconfig.py index b7c618a3..28798ec1 100644 --- a/daemon/core/gui/dialogs/linkconfig.py +++ b/daemon/core/gui/dialogs/linkconfig.py @@ -287,6 +287,8 @@ class LinkConfigurationDialog(Dialog): iface2_id, ) + # update edge label + self.edge.draw_link_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 29632086..6c79787f 100644 --- a/daemon/core/gui/graph/edges.py +++ b/daemon/core/gui/graph/edges.py @@ -57,6 +57,18 @@ def arc_edges(edges) -> None: edge.redraw() +def bandwidth_label(bandwidth: int) -> str: + size = {0: "bps", 1: "Kbps", 2: "Mbps", 3: "Gbps"} + unit = 1000 + i = 0 + while bandwidth > unit: + bandwidth /= unit + i += 1 + if i == 3: + break + return f"{bandwidth} {size[i]}" + + class Edge: tag: str = tags.EDGE @@ -140,6 +152,7 @@ class Edge: font=self.canvas.app.edge_font, text=text, tags=tags.LINK_LABEL, + justify=tk.CENTER, state=self.canvas.show_link_labels.state(), ) else: @@ -312,6 +325,7 @@ class CanvasEdge(Edge): src_text, dst_text = self.create_node_labels() self.src_label_text(src_text) self.dst_label_text(dst_text) + self.draw_link_options() def redraw(self) -> None: super().redraw() @@ -393,3 +407,24 @@ class CanvasEdge(Edge): def click_configure(self) -> None: dialog = LinkConfigurationDialog(self.canvas.app, self) dialog.show() + + def draw_link_options(self): + options = self.link.options + lines = [] + bandwidth = options.bandwidth + if bandwidth > 0: + lines.append(bandwidth_label(bandwidth)) + delay = options.delay + jitter = options.jitter + if delay > 0 and jitter > 0: + lines.append(f"{delay} us (\u00B1{jitter} us)") + elif jitter > 0: + lines.append(f"0 us (\u00B1{jitter} us)") + loss = options.loss + if loss > 0: + lines.append(f"loss={loss}%") + dup = options.dup + if dup > 0: + lines.append(f"dup={dup}%") + label = "\n".join(lines) + self.middle_label_text(label) diff --git a/daemon/core/gui/graph/graph.py b/daemon/core/gui/graph/graph.py index 07519c3f..7d8ec019 100644 --- a/daemon/core/gui/graph/graph.py +++ b/daemon/core/gui/graph/graph.py @@ -1000,6 +1000,7 @@ class CanvasGraph(tk.Canvas): def clear_throughputs(self) -> None: for edge in self.edges.values(): edge.clear_middle_label() + edge.draw_link_options() def scale_graph(self) -> None: for nid, canvas_node in self.nodes.items():