pygui cleaned up error display by creating top level app methods for displaying exceptions and errors, logging exceptions, and making sure they work for background tasks
This commit is contained in:
parent
0999fabb14
commit
1dd45f4424
14 changed files with 57 additions and 82 deletions
|
@ -16,9 +16,9 @@ from core.api.grpc.mobility_pb2 import MobilityConfig
|
|||
from core.api.grpc.services_pb2 import NodeServiceData, ServiceConfig, ServiceFileConfig
|
||||
from core.api.grpc.wlan_pb2 import WlanConfig
|
||||
from core.gui import appconfig
|
||||
from core.gui.dialogs.error import ErrorDialog
|
||||
from core.gui.dialogs.mobilityplayer import MobilityPlayer
|
||||
from core.gui.dialogs.sessions import SessionsDialog
|
||||
from core.gui.errors import show_grpc_error
|
||||
from core.gui.graph import tags
|
||||
from core.gui.graph.edges import CanvasEdge
|
||||
from core.gui.graph.node import CanvasNode
|
||||
|
@ -343,7 +343,7 @@ class CoreClient:
|
|||
response = self.client.get_session_metadata(self.session_id)
|
||||
self.parse_metadata(response.config)
|
||||
except grpc.RpcError as e:
|
||||
self.app.after(0, show_grpc_error, e, self.app, self.app)
|
||||
self.app.show_grpc_exception("Join Session Error", e)
|
||||
|
||||
# update ui to represent current state
|
||||
self.app.after(0, self.app.joined_session_update)
|
||||
|
@ -426,21 +426,16 @@ class CoreClient:
|
|||
)
|
||||
self.join_session(response.session_id, query_location=False)
|
||||
except grpc.RpcError as e:
|
||||
self.app.after(0, show_grpc_error, e, self.app, self.app)
|
||||
self.app.show_grpc_exception("New Session Error", e)
|
||||
|
||||
def delete_session(self, session_id: int = None, parent_frame=None):
|
||||
def delete_session(self, session_id: int = None):
|
||||
if session_id is None:
|
||||
session_id = self.session_id
|
||||
try:
|
||||
response = self.client.delete_session(session_id)
|
||||
logging.info("deleted session(%s), Result: %s", session_id, response)
|
||||
except grpc.RpcError as e:
|
||||
# use the right master widget so the error dialog displays
|
||||
# right on top of it
|
||||
master = self.app
|
||||
if parent_frame:
|
||||
master = parent_frame
|
||||
self.app.after(0, show_grpc_error, e, master, self.app)
|
||||
self.app.show_grpc_exception("Delete Session Error", e)
|
||||
|
||||
def setup(self):
|
||||
"""
|
||||
|
@ -472,7 +467,9 @@ class CoreClient:
|
|||
dialog = SessionsDialog(self.app, self.app, True)
|
||||
dialog.show()
|
||||
except grpc.RpcError as e:
|
||||
show_grpc_error(e, self.app, self.app)
|
||||
logging.exception("core setup error")
|
||||
dialog = ErrorDialog(self.app, self.app, "Setup Error", e.details())
|
||||
dialog.show()
|
||||
self.app.close()
|
||||
|
||||
def edit_node(self, core_node: core_pb2.Node):
|
||||
|
@ -481,7 +478,7 @@ class CoreClient:
|
|||
self.session_id, core_node.id, core_node.position, source=GUI_SOURCE
|
||||
)
|
||||
except grpc.RpcError as e:
|
||||
self.app.after(0, show_grpc_error, e, self.app, self.app)
|
||||
self.app.show_grpc_exception("Edit Node Error", e)
|
||||
|
||||
def start_session(self) -> core_pb2.StartSessionResponse:
|
||||
self.interfaces_manager.reset_mac()
|
||||
|
@ -532,7 +529,7 @@ class CoreClient:
|
|||
if response.result:
|
||||
self.set_metadata()
|
||||
except grpc.RpcError as e:
|
||||
self.app.after(0, show_grpc_error, e, self.app, self.app)
|
||||
self.app.show_grpc_exception("Start Session Error", e)
|
||||
return response
|
||||
|
||||
def stop_session(self, session_id: int = None) -> core_pb2.StartSessionResponse:
|
||||
|
@ -543,7 +540,7 @@ class CoreClient:
|
|||
response = self.client.stop_session(session_id)
|
||||
logging.info("stopped session(%s), result: %s", session_id, response)
|
||||
except grpc.RpcError as e:
|
||||
self.app.after(0, show_grpc_error, e, self.app, self.app)
|
||||
self.app.show_grpc_exception("Stop Session Error", e)
|
||||
return response
|
||||
|
||||
def show_mobility_players(self):
|
||||
|
@ -597,7 +594,7 @@ class CoreClient:
|
|||
logging.info("launching terminal %s", cmd)
|
||||
os.system(cmd)
|
||||
except grpc.RpcError as e:
|
||||
self.app.after(0, show_grpc_error, e, self.app, self.app)
|
||||
self.app.show_grpc_exception("Node Terminal Error", e)
|
||||
|
||||
def save_xml(self, file_path: str):
|
||||
"""
|
||||
|
@ -610,7 +607,7 @@ class CoreClient:
|
|||
response = self.client.save_xml(self.session_id, file_path)
|
||||
logging.info("saved xml file %s, result: %s", file_path, response)
|
||||
except grpc.RpcError as e:
|
||||
self.app.after(0, show_grpc_error, e, self.app, self.app)
|
||||
self.app.show_grpc_exception("Save XML Error", e)
|
||||
|
||||
def open_xml(self, file_path: str):
|
||||
"""
|
||||
|
@ -621,7 +618,7 @@ class CoreClient:
|
|||
logging.info("open xml file %s, response: %s", file_path, response)
|
||||
self.join_session(response.session_id)
|
||||
except grpc.RpcError as e:
|
||||
self.app.after(0, show_grpc_error, e, self.app, self.app)
|
||||
self.app.show_grpc_exception("Open XML Error", e)
|
||||
|
||||
def get_node_service(self, node_id: int, service_name: str) -> NodeServiceData:
|
||||
response = self.client.get_node_service(self.session_id, node_id, service_name)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue