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
|
@ -10,7 +10,6 @@ import grpc
|
|||
|
||||
from core.api.grpc.services_pb2 import ServiceValidationMode
|
||||
from core.gui.dialogs.dialog import Dialog
|
||||
from core.gui.errors import show_grpc_error
|
||||
from core.gui.themes import FRAME_PAD, PADX, PADY
|
||||
from core.gui.widgets import CodeText, ConfigFrame, ListboxScroll
|
||||
|
||||
|
@ -116,8 +115,8 @@ class ConfigServiceConfigDialog(Dialog):
|
|||
self.modified_files.add(file)
|
||||
self.temp_service_files[file] = data
|
||||
except grpc.RpcError as e:
|
||||
self.app.show_grpc_exception("Get Config Service Error", e)
|
||||
self.has_error = True
|
||||
show_grpc_error(e, self.app, self.app)
|
||||
|
||||
def draw(self):
|
||||
self.top.columnconfigure(0, weight=1)
|
||||
|
@ -323,22 +322,17 @@ class ConfigServiceConfigDialog(Dialog):
|
|||
self.destroy()
|
||||
return
|
||||
|
||||
try:
|
||||
service_config = self.canvas_node.config_service_configs.setdefault(
|
||||
self.service_name, {}
|
||||
)
|
||||
if self.config_frame:
|
||||
self.config_frame.parse_config()
|
||||
service_config["config"] = {
|
||||
x.name: x.value for x in self.config.values()
|
||||
}
|
||||
templates_config = service_config.setdefault("templates", {})
|
||||
for file in self.modified_files:
|
||||
templates_config[file] = self.temp_service_files[file]
|
||||
all_current = current_listbox.get(0, tk.END)
|
||||
current_listbox.itemconfig(all_current.index(self.service_name), bg="green")
|
||||
except grpc.RpcError as e:
|
||||
show_grpc_error(e, self.top, self.app)
|
||||
service_config = self.canvas_node.config_service_configs.setdefault(
|
||||
self.service_name, {}
|
||||
)
|
||||
if self.config_frame:
|
||||
self.config_frame.parse_config()
|
||||
service_config["config"] = {x.name: x.value for x in self.config.values()}
|
||||
templates_config = service_config.setdefault("templates", {})
|
||||
for file in self.modified_files:
|
||||
templates_config[file] = self.temp_service_files[file]
|
||||
all_current = current_listbox.get(0, tk.END)
|
||||
current_listbox.itemconfig(all_current.index(self.service_name), bg="green")
|
||||
self.destroy()
|
||||
|
||||
def handle_template_changed(self, event: tk.Event):
|
||||
|
|
|
@ -9,7 +9,6 @@ from typing import TYPE_CHECKING, Any
|
|||
import grpc
|
||||
|
||||
from core.gui.dialogs.dialog import Dialog
|
||||
from core.gui.errors import show_grpc_error
|
||||
from core.gui.images import ImageEnum, Images
|
||||
from core.gui.themes import PADX, PADY
|
||||
from core.gui.widgets import ConfigFrame
|
||||
|
@ -78,7 +77,7 @@ class EmaneModelDialog(Dialog):
|
|||
)
|
||||
self.draw()
|
||||
except grpc.RpcError as e:
|
||||
show_grpc_error(e, self.app, self.app)
|
||||
self.app.show_grpc_exception("Get EMANE Config Error", e)
|
||||
self.has_error = True
|
||||
self.destroy()
|
||||
|
||||
|
|
41
daemon/core/gui/dialogs/error.py
Normal file
41
daemon/core/gui/dialogs/error.py
Normal file
|
@ -0,0 +1,41 @@
|
|||
from tkinter import ttk
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from core.gui.dialogs.dialog import Dialog
|
||||
from core.gui.images import ImageEnum, Images
|
||||
from core.gui.themes import FRAME_PAD, PADX, PADY
|
||||
from core.gui.widgets import CodeText
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from core.gui.app import Application
|
||||
|
||||
|
||||
class ErrorDialog(Dialog):
|
||||
def __init__(self, master, app: "Application", title: str, details: str) -> None:
|
||||
super().__init__(master, app, "CORE Exception")
|
||||
self.title = title
|
||||
self.details = details
|
||||
self.error_message = None
|
||||
self.draw()
|
||||
|
||||
def draw(self) -> None:
|
||||
self.top.columnconfigure(0, weight=1)
|
||||
self.top.rowconfigure(1, weight=1)
|
||||
|
||||
frame = ttk.Frame(self.top, padding=FRAME_PAD)
|
||||
frame.grid(pady=PADY, sticky="ew")
|
||||
frame.columnconfigure(1, weight=1)
|
||||
image = Images.get(ImageEnum.ERROR, 36)
|
||||
label = ttk.Label(frame, image=image)
|
||||
label.image = image
|
||||
label.grid(row=0, column=0, padx=PADX)
|
||||
label = ttk.Label(frame, text=self.title)
|
||||
label.grid(row=0, column=1, sticky="ew")
|
||||
|
||||
self.error_message = CodeText(self.top)
|
||||
self.error_message.text.insert("1.0", self.details)
|
||||
self.error_message.text.config(state="disabled")
|
||||
self.error_message.grid(sticky="nsew", pady=PADY)
|
||||
|
||||
button = ttk.Button(self.top, text="Close", command=lambda: self.destroy())
|
||||
button.grid(sticky="ew")
|
|
@ -7,7 +7,6 @@ from typing import TYPE_CHECKING
|
|||
import grpc
|
||||
|
||||
from core.gui.dialogs.dialog import Dialog
|
||||
from core.gui.errors import show_grpc_error
|
||||
from core.gui.themes import PADX, PADY
|
||||
from core.gui.widgets import ConfigFrame
|
||||
|
||||
|
@ -33,8 +32,8 @@ class MobilityConfigDialog(Dialog):
|
|||
self.config = self.app.core.get_mobility_config(self.node.id)
|
||||
self.draw()
|
||||
except grpc.RpcError as e:
|
||||
self.app.show_grpc_exception("Get Mobility Config Error", e)
|
||||
self.has_error = True
|
||||
show_grpc_error(e, self.app, self.app)
|
||||
self.destroy()
|
||||
|
||||
def draw(self):
|
||||
|
|
|
@ -6,7 +6,6 @@ import grpc
|
|||
|
||||
from core.api.grpc.mobility_pb2 import MobilityAction
|
||||
from core.gui.dialogs.dialog import Dialog
|
||||
from core.gui.errors import show_grpc_error
|
||||
from core.gui.images import ImageEnum, Images
|
||||
from core.gui.themes import PADX, PADY
|
||||
|
||||
|
@ -154,7 +153,7 @@ class MobilityPlayerDialog(Dialog):
|
|||
session_id, self.node.id, MobilityAction.START
|
||||
)
|
||||
except grpc.RpcError as e:
|
||||
show_grpc_error(e, self.top, self.app)
|
||||
self.app.show_grpc_exception("Mobility Error", e)
|
||||
|
||||
def click_pause(self):
|
||||
self.set_pause()
|
||||
|
@ -164,7 +163,7 @@ class MobilityPlayerDialog(Dialog):
|
|||
session_id, self.node.id, MobilityAction.PAUSE
|
||||
)
|
||||
except grpc.RpcError as e:
|
||||
show_grpc_error(e, self.top, self.app)
|
||||
self.app.show_grpc_exception("Mobility Error", e)
|
||||
|
||||
def click_stop(self):
|
||||
self.set_stop()
|
||||
|
@ -174,4 +173,4 @@ class MobilityPlayerDialog(Dialog):
|
|||
session_id, self.node.id, MobilityAction.STOP
|
||||
)
|
||||
except grpc.RpcError as e:
|
||||
show_grpc_error(e, self.top, self.app)
|
||||
self.app.show_grpc_exception("Mobility Error", e)
|
||||
|
|
|
@ -9,7 +9,6 @@ import grpc
|
|||
from core.api.grpc.services_pb2 import ServiceValidationMode
|
||||
from core.gui.dialogs.copyserviceconfig import CopyServiceConfigDialog
|
||||
from core.gui.dialogs.dialog import Dialog
|
||||
from core.gui.errors import show_grpc_error
|
||||
from core.gui.images import ImageEnum, Images
|
||||
from core.gui.themes import FRAME_PAD, PADX, PADY
|
||||
from core.gui.widgets import CodeText, ListboxScroll
|
||||
|
@ -119,8 +118,8 @@ class ServiceConfigDialog(Dialog):
|
|||
for file, data in file_configs.items():
|
||||
self.temp_service_files[file] = data
|
||||
except grpc.RpcError as e:
|
||||
self.app.show_grpc_exception("Get Node Service Error", e)
|
||||
self.has_error = True
|
||||
show_grpc_error(e, self.master, self.app)
|
||||
|
||||
def draw(self):
|
||||
self.top.columnconfigure(0, weight=1)
|
||||
|
@ -484,7 +483,7 @@ class ServiceConfigDialog(Dialog):
|
|||
)
|
||||
self.current_service_color("green")
|
||||
except grpc.RpcError as e:
|
||||
show_grpc_error(e, self.top, self.app)
|
||||
self.app.show_grpc_exception("Save Service Config Error", e)
|
||||
self.destroy()
|
||||
|
||||
def display_service_file_data(self, event: tk.Event):
|
||||
|
|
|
@ -5,7 +5,6 @@ from typing import TYPE_CHECKING
|
|||
import grpc
|
||||
|
||||
from core.gui.dialogs.dialog import Dialog
|
||||
from core.gui.errors import show_grpc_error
|
||||
from core.gui.themes import PADX, PADY
|
||||
from core.gui.widgets import ConfigFrame
|
||||
|
||||
|
@ -28,8 +27,8 @@ class SessionOptionsDialog(Dialog):
|
|||
response = self.app.core.client.get_session_options(session_id)
|
||||
return response.config
|
||||
except grpc.RpcError as e:
|
||||
self.app.show_grpc_exception("Get Session Options Error", e)
|
||||
self.has_error = True
|
||||
show_grpc_error(e, self.app, self.app)
|
||||
self.destroy()
|
||||
|
||||
def draw(self):
|
||||
|
@ -56,5 +55,5 @@ class SessionOptionsDialog(Dialog):
|
|||
response = self.app.core.client.set_session_options(session_id, config)
|
||||
logging.info("saved session config: %s", response)
|
||||
except grpc.RpcError as e:
|
||||
show_grpc_error(e, self.top, self.app)
|
||||
self.app.show_grpc_exception("Set Session Options Error", e)
|
||||
self.destroy()
|
||||
|
|
|
@ -7,7 +7,6 @@ import grpc
|
|||
|
||||
from core.api.grpc import core_pb2
|
||||
from core.gui.dialogs.dialog import Dialog
|
||||
from core.gui.errors import show_grpc_error
|
||||
from core.gui.images import ImageEnum, Images
|
||||
from core.gui.task import ProgressTask
|
||||
from core.gui.themes import PADX, PADY
|
||||
|
@ -37,7 +36,7 @@ class SessionsDialog(Dialog):
|
|||
logging.info("sessions: %s", response)
|
||||
return response.sessions
|
||||
except grpc.RpcError as e:
|
||||
show_grpc_error(e, self.app, self.app)
|
||||
self.app.show_grpc_exception("Get Sessions Error", e)
|
||||
self.destroy()
|
||||
|
||||
def draw(self) -> None:
|
||||
|
|
|
@ -4,7 +4,6 @@ from typing import TYPE_CHECKING
|
|||
import grpc
|
||||
|
||||
from core.gui.dialogs.dialog import Dialog
|
||||
from core.gui.errors import show_grpc_error
|
||||
from core.gui.themes import PADX, PADY
|
||||
from core.gui.widgets import ConfigFrame
|
||||
|
||||
|
@ -21,7 +20,7 @@ class WlanConfigDialog(Dialog):
|
|||
self, master: "Application", app: "Application", canvas_node: "CanvasNode"
|
||||
):
|
||||
super().__init__(
|
||||
master, app, f"{canvas_node.core_node.name} Wlan Configuration"
|
||||
master, app, f"{canvas_node.core_node.name} WLAN Configuration"
|
||||
)
|
||||
self.canvas_node = canvas_node
|
||||
self.node = canvas_node.core_node
|
||||
|
@ -38,7 +37,7 @@ class WlanConfigDialog(Dialog):
|
|||
self.init_draw_range()
|
||||
self.draw()
|
||||
except grpc.RpcError as e:
|
||||
show_grpc_error(e, self.app, self.app)
|
||||
self.app.show_grpc_exception("WLAN Config Error", e)
|
||||
self.has_error = True
|
||||
self.destroy()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue