pygui: updates to show wireless edges in details panel, increased edge thickness to be the same as normal edges for selection to be easier

This commit is contained in:
Blake Harnden 2020-06-26 09:13:38 -07:00
parent f4224d1b80
commit eac941ce72
3 changed files with 74 additions and 9 deletions

View file

@ -1,12 +1,26 @@
import tkinter as tk
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Optional
from core.api.grpc.core_pb2 import Interface
from core.gui.frames.base import DetailsFrame, InfoFrameBase
from core.gui.utils import bandwidth_text
if TYPE_CHECKING:
from core.gui.app import Application
from core.gui.graph.edges import CanvasEdge
from core.gui.graph.node import CanvasNode
from core.gui.graph.edges import CanvasWirelessEdge
def get_iface(canvas_node: "CanvasNode", net_id: int) -> Optional[Interface]:
iface = None
for edge in canvas_node.edges:
link = edge.link
if link.node1_id == net_id:
iface = link.iface2
elif link.node2_id == net_id:
iface = link.iface1
return iface
class EdgeInfoFrame(InfoFrameBase):
@ -56,3 +70,44 @@ class EdgeInfoFrame(InfoFrameBase):
frame.add_detail("Jitter", f"\u00B1{options.jitter} us")
frame.add_detail("Loss", f"{options.loss}%")
frame.add_detail("Duplicate", f"{options.dup}%")
class WirelessEdgeInfoFrame(InfoFrameBase):
def __init__(
self, master: tk.BaseWidget, app: "Application", edge: "CanvasWirelessEdge"
) -> None:
super().__init__(master, app)
self.edge: "CanvasWirelessEdge" = edge
def draw(self) -> None:
link = self.edge.link
src_canvas_node = self.app.core.canvas_nodes[link.node1_id]
src_node = src_canvas_node.core_node
dst_canvas_node = self.app.core.canvas_nodes[link.node2_id]
dst_node = dst_canvas_node.core_node
# find interface for each node connected to network
net_id = link.network_id
iface1 = get_iface(src_canvas_node, net_id)
iface2 = get_iface(dst_canvas_node, net_id)
frame = DetailsFrame(self)
frame.grid(sticky="ew")
frame.add_detail("Source", src_node.name)
if iface1:
mac = iface1.mac if iface1.mac else "auto"
frame.add_detail("MAC", mac)
ip4 = f"{iface1.ip4}/{iface1.ip4_mask}" if iface1.ip4 else ""
frame.add_detail("IP4", ip4)
ip6 = f"{iface1.ip6}/{iface1.ip6_mask}" if iface1.ip6 else ""
frame.add_detail("IP6", ip6)
frame.add_separator()
frame.add_detail("Destination", dst_node.name)
if iface2:
mac = iface2.mac if iface2.mac else "auto"
frame.add_detail("MAC", mac)
ip4 = f"{iface2.ip4}/{iface2.ip4_mask}" if iface2.ip4 else ""
frame.add_detail("IP4", ip4)
ip6 = f"{iface2.ip6}/{iface2.ip6_mask}" if iface2.ip6 else ""
frame.add_detail("IP6", ip6)

View file

@ -7,7 +7,7 @@ from core.api.grpc import core_pb2
from core.api.grpc.core_pb2 import Interface, Link
from core.gui import themes
from core.gui.dialogs.linkconfig import LinkConfigurationDialog
from core.gui.frames.link import EdgeInfoFrame
from core.gui.frames.link import EdgeInfoFrame, WirelessEdgeInfoFrame
from core.gui.graph import tags
from core.gui.nodeutils import NodeUtils
from core.gui.utils import bandwidth_text
@ -18,7 +18,7 @@ if TYPE_CHECKING:
TEXT_DISTANCE: float = 0.30
EDGE_WIDTH: int = 3
EDGE_COLOR: str = "#ff0000"
WIRELESS_WIDTH: float = 1.5
WIRELESS_WIDTH: float = 3
WIRELESS_COLOR: str = "#009933"
ARC_DISTANCE: int = 50
@ -241,13 +241,27 @@ class CanvasWirelessEdge(Edge):
src_pos: Tuple[float, float],
dst_pos: Tuple[float, float],
token: Tuple[int, ...],
link: Link,
) -> None:
logging.debug("drawing wireless link from node %s to node %s", src, dst)
super().__init__(canvas, src, dst)
self.link: Link = link
self.token: Tuple[int, ...] = token
self.width: float = WIRELESS_WIDTH
self.color: str = WIRELESS_COLOR
color = link.color if link.color else WIRELESS_COLOR
self.color: str = color
self.draw(src_pos, dst_pos)
if link.label:
self.middle_label_text(link.label)
self.set_binding()
def set_binding(self) -> None:
self.canvas.tag_bind(self.id, "<Button-1>", self.show_info)
def show_info(self, _event: tk.Event) -> None:
self.canvas.app.display_info(
WirelessEdgeInfoFrame, app=self.canvas.app, edge=self
)
class CanvasEdge(Edge):

View file

@ -233,11 +233,7 @@ class CanvasGraph(tk.Canvas):
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)
if link.label:
edge.middle_label_text(link.label)
if link.color:
edge.color = link.color
edge = CanvasWirelessEdge(self, src.id, dst.id, src_pos, dst_pos, token, link)
self.wireless_edges[token] = edge
src.wireless_edges.add(edge)
dst.wireless_edges.add(edge)