2020-02-05 23:53:14 +00:00
|
|
|
from tkinter import ttk
|
2020-01-14 19:06:52 +00:00
|
|
|
from typing import TYPE_CHECKING
|
2019-12-10 06:50:26 +00:00
|
|
|
|
2020-02-05 23:09:33 +00:00
|
|
|
from core.gui.dialogs.dialog import Dialog
|
2020-02-05 23:53:14 +00:00
|
|
|
from core.gui.images import ImageEnum, Images
|
2020-02-05 23:09:33 +00:00
|
|
|
from core.gui.widgets import CodeText
|
|
|
|
|
2020-01-14 19:06:52 +00:00
|
|
|
if TYPE_CHECKING:
|
|
|
|
import grpc
|
2020-02-05 23:09:33 +00:00
|
|
|
from core.gui.app import Application
|
|
|
|
|
|
|
|
|
|
|
|
class ErrorDialog(Dialog):
|
|
|
|
def __init__(self, master, app: "Application", title: str, details: str):
|
|
|
|
super().__init__(master, app, title, modal=True)
|
|
|
|
self.error_message = None
|
|
|
|
self.details = details
|
|
|
|
self.draw()
|
|
|
|
|
|
|
|
def draw(self):
|
|
|
|
self.top.columnconfigure(0, weight=1)
|
|
|
|
self.top.rowconfigure(0, weight=1)
|
2020-02-05 23:53:14 +00:00
|
|
|
image = Images.get(ImageEnum.ERROR, 36)
|
|
|
|
label = ttk.Label(self.top, image=image)
|
|
|
|
label.image = image
|
|
|
|
label.grid(row=0, column=0)
|
2020-02-05 23:09:33 +00:00
|
|
|
self.error_message = CodeText(self.top)
|
|
|
|
self.error_message.text.insert("1.0", self.details)
|
|
|
|
self.error_message.text.config(state="disabled")
|
2020-02-05 23:53:14 +00:00
|
|
|
self.error_message.grid(row=1, column=0, sticky="nsew")
|
2019-12-10 06:50:26 +00:00
|
|
|
|
2020-01-10 23:32:16 +00:00
|
|
|
|
2020-02-05 23:09:33 +00:00
|
|
|
def show_grpc_error(e: "grpc.RpcError", master, app: "Application"):
|
2019-12-10 06:50:26 +00:00
|
|
|
title = [x.capitalize() for x in e.code().name.lower().split("_")]
|
|
|
|
title = " ".join(title)
|
|
|
|
title = f"GRPC {title}"
|
2020-02-05 23:09:33 +00:00
|
|
|
dialog = ErrorDialog(master, app, title, e.details())
|
|
|
|
dialog.show()
|