added some data for node events to have a source field to help distinguish what originates from the gui or not
This commit is contained in:
parent
354d227cb3
commit
d1db5e4b4e
7 changed files with 32 additions and 20 deletions
|
@ -141,15 +141,19 @@ class CoreClient:
|
|||
else:
|
||||
logging.warning("unknown session event: %s", session_event)
|
||||
elif event.HasField("node_event"):
|
||||
node_event = event.node_event
|
||||
node_id = node_event.node.id
|
||||
x = node_event.node.position.x
|
||||
y = node_event.node.position.y
|
||||
canvas_node = self.canvas_nodes[node_id]
|
||||
canvas_node.move(x, y)
|
||||
self.handle_node_event(event.node_event)
|
||||
else:
|
||||
logging.info("unhandled event: %s", event)
|
||||
|
||||
def handle_node_event(self, event):
|
||||
if event.source == "gui":
|
||||
return
|
||||
node_id = event.node.id
|
||||
x = event.node.position.x
|
||||
y = event.node.position.y
|
||||
canvas_node = self.canvas_nodes[node_id]
|
||||
canvas_node.move(x, y)
|
||||
|
||||
def handle_throughputs(self, event):
|
||||
interface_throughputs = event.interface_throughputs
|
||||
for i in interface_throughputs:
|
||||
|
@ -164,9 +168,6 @@ class CoreClient:
|
|||
)
|
||||
|
||||
def join_session(self, session_id, query_location=True):
|
||||
# self.master.config(cursor="watch")
|
||||
# self.master.update()
|
||||
|
||||
# update session and title
|
||||
self.session_id = session_id
|
||||
self.master.title(f"CORE Session({self.session_id})")
|
||||
|
@ -253,7 +254,6 @@ class CoreClient:
|
|||
self.app.toolbar.runtime_frame.tkraise()
|
||||
else:
|
||||
self.app.toolbar.design_frame.tkraise()
|
||||
# self.master.config(cursor="")
|
||||
self.app.statusbar.progress_bar.stop()
|
||||
|
||||
def is_runtime(self):
|
||||
|
@ -321,8 +321,7 @@ class CoreClient:
|
|||
|
||||
def edit_node(self, node_id, x, y):
|
||||
position = core_pb2.Position(x=x, y=y)
|
||||
response = self.client.edit_node(self.session_id, node_id, position)
|
||||
logging.info("updated node id %s: %s", node_id, response)
|
||||
self.client.edit_node(self.session_id, node_id, position, source="gui")
|
||||
|
||||
def start_session(self):
|
||||
nodes = [x.core_node for x in self.canvas_nodes.values()]
|
||||
|
|
|
@ -600,6 +600,9 @@ class CanvasNode:
|
|||
y_offset = y - old_y
|
||||
self.core_node.position.x = x
|
||||
self.core_node.position.y = y
|
||||
self.canvas.move(self.id, x_offset, y_offset)
|
||||
self.canvas.move(self.text_id, x_offset, y_offset)
|
||||
self.antenna_draw.update_antennas_position(x_offset, y_offset)
|
||||
for edge in self.edges:
|
||||
x1, y1, x2, y2 = self.canvas.coords(edge.id)
|
||||
if edge.src == self.id:
|
||||
|
@ -608,9 +611,6 @@ class CanvasNode:
|
|||
self.canvas.coords(edge.id, x1, y1, x_offset, y_offset)
|
||||
edge.link_info.recalculate_info()
|
||||
self.canvas.helper.update_wlan_connection(old_x, old_y, x, y, self.wlans)
|
||||
self.canvas.move(self.id, x_offset, y_offset)
|
||||
self.canvas.move(self.text_id, x_offset, y_offset)
|
||||
self.antenna_draw.update_antennas_position(x_offset, y_offset)
|
||||
|
||||
def on_enter(self, event):
|
||||
if self.app.core.is_runtime() and self.app.core.observer:
|
||||
|
|
|
@ -428,7 +428,7 @@ class CoreGrpcClient:
|
|||
request = core_pb2.GetNodeRequest(session_id=session_id, node_id=node_id)
|
||||
return self.stub.GetNode(request)
|
||||
|
||||
def edit_node(self, session_id, node_id, position, icon=None):
|
||||
def edit_node(self, session_id, node_id, position, icon=None, source=None):
|
||||
"""
|
||||
Edit a node, currently only changes position.
|
||||
|
||||
|
@ -436,12 +436,17 @@ class CoreGrpcClient:
|
|||
:param int node_id: node id
|
||||
:param core_pb2.Position position: position to set node to
|
||||
:param str icon: path to icon for gui to use for node
|
||||
:param str source: application source editing node
|
||||
:return: response with result of success or failure
|
||||
:rtype: core_pb2.EditNodeResponse
|
||||
:raises grpc.RpcError: when session or node doesn't exist
|
||||
"""
|
||||
request = core_pb2.EditNodeRequest(
|
||||
session_id=session_id, node_id=node_id, position=position, icon=icon
|
||||
session_id=session_id,
|
||||
node_id=node_id,
|
||||
position=position,
|
||||
icon=icon,
|
||||
source=source,
|
||||
)
|
||||
return self.stub.EditNode(request)
|
||||
|
||||
|
|
|
@ -504,7 +504,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
position=position,
|
||||
services=services,
|
||||
)
|
||||
return core_pb2.NodeEvent(node=node_proto)
|
||||
return core_pb2.NodeEvent(node=node_proto, source=event.source)
|
||||
|
||||
def _handle_link_event(self, event):
|
||||
"""
|
||||
|
@ -800,7 +800,10 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
result = True
|
||||
try:
|
||||
session.edit_node(node.id, options)
|
||||
node_data = node.data(0)
|
||||
source = None
|
||||
if request.source:
|
||||
source = request.source
|
||||
node_data = node.data(0, source=source)
|
||||
session.broadcast_node(node_data)
|
||||
except CoreError:
|
||||
result = False
|
||||
|
|
|
@ -76,6 +76,7 @@ NodeData = collections.namedtuple(
|
|||
"altitude",
|
||||
"icon",
|
||||
"opaque",
|
||||
"source",
|
||||
],
|
||||
)
|
||||
NodeData.__new__.__defaults__ = (None,) * len(NodeData._fields)
|
||||
|
|
|
@ -176,7 +176,7 @@ class NodeBase:
|
|||
self.ifindex += 1
|
||||
return ifindex
|
||||
|
||||
def data(self, message_type, lat=None, lon=None, alt=None):
|
||||
def data(self, message_type, lat=None, lon=None, alt=None, source=None):
|
||||
"""
|
||||
Build a data object for this node.
|
||||
|
||||
|
@ -184,6 +184,7 @@ class NodeBase:
|
|||
:param str lat: latitude
|
||||
:param str lon: longitude
|
||||
:param str alt: altitude
|
||||
:param str source: source of node data
|
||||
:return: node data object
|
||||
:rtype: core.emulator.data.NodeData
|
||||
"""
|
||||
|
@ -217,6 +218,7 @@ class NodeBase:
|
|||
model=model,
|
||||
server=server,
|
||||
services=services,
|
||||
source=source,
|
||||
)
|
||||
|
||||
return node_data
|
||||
|
|
|
@ -298,6 +298,7 @@ message Event {
|
|||
|
||||
message NodeEvent {
|
||||
Node node = 1;
|
||||
string source = 2;
|
||||
}
|
||||
|
||||
message LinkEvent {
|
||||
|
@ -378,6 +379,7 @@ message EditNodeRequest {
|
|||
int32 node_id = 2;
|
||||
Position position = 3;
|
||||
string icon = 4;
|
||||
string source = 5;
|
||||
}
|
||||
|
||||
message EditNodeResponse {
|
||||
|
|
Loading…
Reference in a new issue