grpc/pygui: updated delete_node to use the source, updated pygui to support delete node events
This commit is contained in:
parent
adf28f6b55
commit
e79645013b
6 changed files with 31 additions and 9 deletions
|
@ -536,16 +536,21 @@ class CoreGrpcClient:
|
|||
"""
|
||||
return self.stub.MoveNodes(move_iterator)
|
||||
|
||||
def delete_node(self, session_id: int, node_id: int) -> core_pb2.DeleteNodeResponse:
|
||||
def delete_node(
|
||||
self, session_id: int, node_id: int, source: str = None
|
||||
) -> core_pb2.DeleteNodeResponse:
|
||||
"""
|
||||
Delete node from session.
|
||||
|
||||
:param session_id: session id
|
||||
:param node_id: node id
|
||||
:param source: application source
|
||||
:return: response with result of success or failure
|
||||
:raises grpc.RpcError: when session doesn't exist
|
||||
"""
|
||||
request = core_pb2.DeleteNodeRequest(session_id=session_id, node_id=node_id)
|
||||
request = core_pb2.DeleteNodeRequest(
|
||||
session_id=session_id, node_id=node_id, source=source
|
||||
)
|
||||
return self.stub.DeleteNode(request)
|
||||
|
||||
def node_command(
|
||||
|
|
|
@ -36,7 +36,8 @@ def handle_node_event(node_data: NodeData) -> core_pb2.Event:
|
|||
geo=geo,
|
||||
services=services,
|
||||
)
|
||||
node_event = core_pb2.NodeEvent(node=node_proto)
|
||||
message_type = node_data.message_type.value
|
||||
node_event = core_pb2.NodeEvent(message_type=message_type, node=node_proto)
|
||||
return core_pb2.Event(node_event=node_event, source=node_data.source)
|
||||
|
||||
|
||||
|
|
|
@ -775,7 +775,14 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
"""
|
||||
logging.debug("delete node: %s", request)
|
||||
session = self.get_session(request.session_id, context)
|
||||
result = session.delete_node(request.node_id)
|
||||
result = False
|
||||
try:
|
||||
node = self.get_node(session, request.node_id, context, NodeBase)
|
||||
result = session.delete_node(node.id)
|
||||
source = request.source if request.source else None
|
||||
session.broadcast_node(node, MessageFlags.DELETE, source)
|
||||
except grpc.RpcError:
|
||||
pass
|
||||
return core_pb2.DeleteNodeResponse(result=result)
|
||||
|
||||
def NodeCommand(
|
||||
|
|
|
@ -226,10 +226,17 @@ class CoreClient:
|
|||
def handle_node_event(self, event: NodeEvent) -> None:
|
||||
logging.debug("node event: %s", event)
|
||||
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)
|
||||
if event.message_type == MessageType.NONE:
|
||||
x = event.node.position.x
|
||||
y = event.node.position.y
|
||||
canvas_node.move(x, y)
|
||||
elif event.message_type == MessageType.DELETE:
|
||||
self.app.canvas.clear_selection()
|
||||
self.app.canvas.select_object(canvas_node.id)
|
||||
self.app.canvas.delete_selected_objects()
|
||||
else:
|
||||
logging.warning("unknown node event: %s", event)
|
||||
|
||||
def enable_throughputs(self) -> None:
|
||||
self.handling_throughputs = self.client.throughputs(
|
||||
|
|
|
@ -271,12 +271,12 @@ class CanvasNode:
|
|||
|
||||
def canvas_delete(self) -> None:
|
||||
self.canvas.clear_selection()
|
||||
self.canvas.selection[self.id] = self
|
||||
self.canvas.select_object(self.id)
|
||||
self.canvas.delete_selected_objects()
|
||||
|
||||
def canvas_copy(self) -> None:
|
||||
self.canvas.clear_selection()
|
||||
self.canvas.selection[self.id] = self
|
||||
self.canvas.select_object(self.id)
|
||||
self.canvas.copy()
|
||||
|
||||
def show_config(self) -> None:
|
||||
|
|
|
@ -348,6 +348,7 @@ message Event {
|
|||
|
||||
message NodeEvent {
|
||||
Node node = 1;
|
||||
MessageType.Enum message_type = 2;
|
||||
}
|
||||
|
||||
message LinkEvent {
|
||||
|
@ -435,6 +436,7 @@ message EditNodeResponse {
|
|||
message DeleteNodeRequest {
|
||||
int32 session_id = 1;
|
||||
int32 node_id = 2;
|
||||
string source = 3;
|
||||
}
|
||||
|
||||
message DeleteNodeResponse {
|
||||
|
|
Loading…
Reference in a new issue