pygui: added wrapper class for sessions returned by grpc GetSession
This commit is contained in:
parent
82a212d1cf
commit
41a3c5fd7f
3 changed files with 32 additions and 11 deletions
|
@ -48,6 +48,7 @@ from core.gui.wrappers import (
|
|||
NodeServiceData,
|
||||
NodeType,
|
||||
Position,
|
||||
Session,
|
||||
SessionLocation,
|
||||
SessionState,
|
||||
ThroughputsEvent,
|
||||
|
@ -311,8 +312,8 @@ class CoreClient:
|
|||
# get session data
|
||||
try:
|
||||
response = self.client.get_session(self.session_id)
|
||||
session = response.session
|
||||
self.state = SessionState(session.state)
|
||||
session = Session.from_proto(response.session)
|
||||
self.state = session.state
|
||||
self.handling_events = self.client.events(
|
||||
self.session_id, self.handle_events
|
||||
)
|
||||
|
@ -349,9 +350,7 @@ class CoreClient:
|
|||
self.ifaces_manager.joined(session.links)
|
||||
|
||||
# draw session
|
||||
nodes = [Node.from_proto(x) for x in session.nodes]
|
||||
links = [Link.from_proto(x) for x in session.links]
|
||||
self.app.canvas.reset_and_redraw(nodes, links)
|
||||
self.app.canvas.reset_and_redraw(session)
|
||||
|
||||
# get mobility configs
|
||||
response = self.client.get_mobility_configs(self.session_id)
|
||||
|
|
|
@ -22,7 +22,7 @@ from core.gui.graph.shape import Shape
|
|||
from core.gui.graph.shapeutils import ShapeType, is_draw_shape, is_marker
|
||||
from core.gui.images import ImageEnum, TypeToImage
|
||||
from core.gui.nodeutils import NodeDraw, NodeUtils
|
||||
from core.gui.wrappers import Interface, Link, LinkType, Node, ThroughputsEvent
|
||||
from core.gui.wrappers import Interface, Link, LinkType, Node, Session, ThroughputsEvent
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from core.gui.app import Application
|
||||
|
@ -127,7 +127,7 @@ class CanvasGraph(tk.Canvas):
|
|||
)
|
||||
self.configure(scrollregion=self.bbox(tk.ALL))
|
||||
|
||||
def reset_and_redraw(self, nodes: List[Node], links: List[Link]) -> None:
|
||||
def reset_and_redraw(self, session: Session) -> None:
|
||||
# reset view options to default state
|
||||
self.show_node_labels.set(True)
|
||||
self.show_link_labels.set(True)
|
||||
|
@ -152,7 +152,7 @@ class CanvasGraph(tk.Canvas):
|
|||
self.wireless_edges.clear()
|
||||
self.wireless_network.clear()
|
||||
self.drawing_edge = None
|
||||
self.draw_session(nodes, links)
|
||||
self.draw_session(session)
|
||||
|
||||
def setup_bindings(self) -> None:
|
||||
"""
|
||||
|
@ -325,19 +325,20 @@ class CanvasGraph(tk.Canvas):
|
|||
self.nodes[node.id] = node
|
||||
self.core.canvas_nodes[core_node.id] = node
|
||||
|
||||
def draw_session(self, nodes: List[Node], links: List[Link]) -> None:
|
||||
def draw_session(self, session: Session) -> None:
|
||||
"""
|
||||
Draw existing session.
|
||||
"""
|
||||
# draw existing nodes
|
||||
for core_node in nodes:
|
||||
for core_node in session.nodes:
|
||||
logging.debug("drawing node: %s", core_node)
|
||||
# peer to peer node is not drawn on the GUI
|
||||
if NodeUtils.is_ignore_node(core_node.type):
|
||||
continue
|
||||
self.add_core_node(core_node)
|
||||
|
||||
# draw existing links
|
||||
for link in links:
|
||||
for link in session.links:
|
||||
logging.debug("drawing link: %s", link)
|
||||
canvas_node1 = self.core.canvas_nodes[link.node1_id]
|
||||
canvas_node2 = self.core.canvas_nodes[link.node2_id]
|
||||
|
|
|
@ -545,6 +545,27 @@ class Node:
|
|||
)
|
||||
|
||||
|
||||
@dataclass
|
||||
class Session:
|
||||
id: int
|
||||
state: SessionState
|
||||
nodes: List[Node]
|
||||
links: List[Link]
|
||||
dir: str
|
||||
|
||||
@classmethod
|
||||
def from_proto(cls, proto: core_pb2.Session) -> "Session":
|
||||
nodes = [Node.from_proto(x) for x in proto.nodes]
|
||||
links = [Link.from_proto(x) for x in proto.links]
|
||||
return Session(
|
||||
id=proto.id,
|
||||
state=SessionState(proto.state),
|
||||
nodes=nodes,
|
||||
links=links,
|
||||
dir=proto.dir,
|
||||
)
|
||||
|
||||
|
||||
@dataclass
|
||||
class LinkEvent:
|
||||
message_type: MessageType
|
||||
|
|
Loading…
Reference in a new issue