2019-12-11 17:17:39 +00:00
|
|
|
"""
|
|
|
|
check engine light
|
|
|
|
"""
|
2019-12-12 00:16:59 +00:00
|
|
|
import tkinter as tk
|
2019-12-11 17:17:39 +00:00
|
|
|
from tkinter import ttk
|
2023-04-13 23:53:16 +01:00
|
|
|
from typing import TYPE_CHECKING, Optional
|
2019-12-11 17:17:39 +00:00
|
|
|
|
2020-08-27 19:02:02 +01:00
|
|
|
from core.api.grpc.wrappers import ExceptionEvent, ExceptionLevel
|
2019-12-19 17:30:21 +00:00
|
|
|
from core.gui.dialogs.dialog import Dialog
|
|
|
|
from core.gui.themes import PADX, PADY
|
|
|
|
from core.gui.widgets import CodeText
|
2019-12-11 17:17:39 +00:00
|
|
|
|
2020-01-13 23:31:41 +00:00
|
|
|
if TYPE_CHECKING:
|
|
|
|
from core.gui.app import Application
|
|
|
|
|
2019-12-11 17:17:39 +00:00
|
|
|
|
2019-12-13 05:05:45 +00:00
|
|
|
class AlertsDialog(Dialog):
|
2020-06-22 19:04:33 +01:00
|
|
|
def __init__(self, app: "Application") -> None:
|
2020-05-05 06:50:59 +01:00
|
|
|
super().__init__(app, "Alerts")
|
2020-06-22 19:04:33 +01:00
|
|
|
self.tree: Optional[ttk.Treeview] = None
|
|
|
|
self.codetext: Optional[CodeText] = None
|
2023-04-13 23:53:16 +01:00
|
|
|
self.alarm_map: dict[int, ExceptionEvent] = {}
|
2019-12-11 17:17:39 +00:00
|
|
|
self.draw()
|
|
|
|
|
2020-06-22 19:04:33 +01:00
|
|
|
def draw(self) -> None:
|
2019-12-13 05:05:45 +00:00
|
|
|
self.top.columnconfigure(0, weight=1)
|
|
|
|
self.top.rowconfigure(0, weight=1)
|
|
|
|
self.top.rowconfigure(1, weight=1)
|
2019-12-16 20:34:22 +00:00
|
|
|
|
2019-12-13 05:05:45 +00:00
|
|
|
frame = ttk.Frame(self.top)
|
2019-12-12 18:49:52 +00:00
|
|
|
frame.columnconfigure(0, weight=1)
|
2019-12-16 20:34:22 +00:00
|
|
|
frame.rowconfigure(0, weight=1)
|
2020-08-02 18:36:14 +01:00
|
|
|
frame.grid(sticky=tk.NSEW, pady=PADY)
|
2019-12-12 18:49:52 +00:00
|
|
|
self.tree = ttk.Treeview(
|
2019-12-13 00:17:33 +00:00
|
|
|
frame,
|
|
|
|
columns=("time", "level", "session_id", "node", "source"),
|
|
|
|
show="headings",
|
2019-12-12 18:49:52 +00:00
|
|
|
)
|
2020-08-02 18:36:14 +01:00
|
|
|
self.tree.grid(row=0, column=0, sticky=tk.NSEW)
|
2019-12-12 18:49:52 +00:00
|
|
|
self.tree.column("time", stretch=tk.YES)
|
2019-12-16 20:34:22 +00:00
|
|
|
self.tree.heading("time", text="Time")
|
2019-12-19 19:30:27 +00:00
|
|
|
self.tree.column("level", stretch=tk.YES, width=100)
|
2019-12-16 20:34:22 +00:00
|
|
|
self.tree.heading("level", text="Level")
|
2019-12-19 19:30:27 +00:00
|
|
|
self.tree.column("session_id", stretch=tk.YES, width=100)
|
2019-12-16 20:34:22 +00:00
|
|
|
self.tree.heading("session_id", text="Session ID")
|
2019-12-19 19:30:27 +00:00
|
|
|
self.tree.column("node", stretch=tk.YES, width=100)
|
2019-12-16 20:34:22 +00:00
|
|
|
self.tree.heading("node", text="Node")
|
2019-12-19 19:30:27 +00:00
|
|
|
self.tree.column("source", stretch=tk.YES, width=100)
|
2019-12-16 20:34:22 +00:00
|
|
|
self.tree.heading("source", text="Source")
|
2019-12-13 00:17:33 +00:00
|
|
|
self.tree.bind("<<TreeviewSelect>>", self.click_select)
|
|
|
|
|
2020-07-25 18:30:14 +01:00
|
|
|
for exception in self.app.statusbar.core_alarms:
|
|
|
|
level_name = exception.level.name
|
2020-07-23 03:19:22 +01:00
|
|
|
node_id = exception.node_id if exception.node_id else ""
|
2019-12-20 18:51:52 +00:00
|
|
|
insert_id = self.tree.insert(
|
2019-12-13 00:17:33 +00:00
|
|
|
"",
|
|
|
|
tk.END,
|
2019-12-20 18:51:52 +00:00
|
|
|
text=exception.date,
|
2019-12-13 00:17:33 +00:00
|
|
|
values=(
|
2019-12-20 18:51:52 +00:00
|
|
|
exception.date,
|
|
|
|
level_name,
|
2020-07-25 18:30:14 +01:00
|
|
|
exception.session_id,
|
2020-07-23 03:19:22 +01:00
|
|
|
node_id,
|
2019-12-20 18:51:52 +00:00
|
|
|
exception.source,
|
2019-12-13 00:17:33 +00:00
|
|
|
),
|
2019-12-20 18:51:52 +00:00
|
|
|
tags=(level_name,),
|
2019-12-13 00:17:33 +00:00
|
|
|
)
|
2020-07-25 18:30:14 +01:00
|
|
|
self.alarm_map[insert_id] = exception
|
2019-12-13 00:17:33 +00:00
|
|
|
|
2020-07-25 18:30:14 +01:00
|
|
|
error_name = ExceptionLevel.ERROR.name
|
2019-12-20 18:51:52 +00:00
|
|
|
self.tree.tag_configure(error_name, background="#ff6666")
|
2020-07-25 18:30:14 +01:00
|
|
|
fatal_name = ExceptionLevel.FATAL.name
|
2019-12-20 18:51:52 +00:00
|
|
|
self.tree.tag_configure(fatal_name, background="#d9d9d9")
|
2020-07-25 18:30:14 +01:00
|
|
|
warning_name = ExceptionLevel.WARNING.name
|
2019-12-20 18:51:52 +00:00
|
|
|
self.tree.tag_configure(warning_name, background="#ffff99")
|
2020-07-25 18:30:14 +01:00
|
|
|
notice_name = ExceptionLevel.NOTICE.name
|
2019-12-20 18:51:52 +00:00
|
|
|
self.tree.tag_configure(notice_name, background="#85e085")
|
2019-12-12 18:49:52 +00:00
|
|
|
|
|
|
|
yscrollbar = ttk.Scrollbar(frame, orient="vertical", command=self.tree.yview)
|
2020-08-02 18:36:14 +01:00
|
|
|
yscrollbar.grid(row=0, column=1, sticky=tk.NS)
|
2019-12-12 18:49:52 +00:00
|
|
|
self.tree.configure(yscrollcommand=yscrollbar.set)
|
|
|
|
|
|
|
|
xscrollbar = ttk.Scrollbar(frame, orient="horizontal", command=self.tree.xview)
|
2020-08-02 18:36:14 +01:00
|
|
|
xscrollbar.grid(row=1, sticky=tk.EW)
|
2019-12-12 18:49:52 +00:00
|
|
|
self.tree.configure(xscrollcommand=xscrollbar.set)
|
|
|
|
|
2019-12-17 18:01:25 +00:00
|
|
|
self.codetext = CodeText(self.top)
|
2019-12-19 19:30:27 +00:00
|
|
|
self.codetext.text.config(state=tk.DISABLED, height=11)
|
2020-08-02 18:36:14 +01:00
|
|
|
self.codetext.grid(sticky=tk.NSEW, pady=PADY)
|
2019-12-12 18:49:52 +00:00
|
|
|
|
2019-12-13 05:05:45 +00:00
|
|
|
frame = ttk.Frame(self.top)
|
2020-08-02 18:36:14 +01:00
|
|
|
frame.grid(sticky=tk.EW)
|
2019-12-12 18:49:52 +00:00
|
|
|
frame.columnconfigure(0, weight=1)
|
|
|
|
frame.columnconfigure(1, weight=1)
|
2019-12-13 05:05:45 +00:00
|
|
|
button = ttk.Button(frame, text="Reset", command=self.reset_alerts)
|
2020-08-02 18:36:14 +01:00
|
|
|
button.grid(row=0, column=0, sticky=tk.EW, padx=PADX)
|
2019-12-11 17:17:39 +00:00
|
|
|
button = ttk.Button(frame, text="Close", command=self.destroy)
|
2020-08-02 18:36:14 +01:00
|
|
|
button.grid(row=0, column=1, sticky=tk.EW)
|
2019-12-12 00:16:59 +00:00
|
|
|
|
2020-06-22 19:04:33 +01:00
|
|
|
def reset_alerts(self) -> None:
|
2020-07-23 03:19:22 +01:00
|
|
|
self.codetext.text.config(state=tk.NORMAL)
|
|
|
|
self.codetext.text.delete(1.0, tk.END)
|
|
|
|
self.codetext.text.config(state=tk.DISABLED)
|
2019-12-13 00:17:33 +00:00
|
|
|
for item in self.tree.get_children():
|
|
|
|
self.tree.delete(item)
|
2020-07-23 03:19:22 +01:00
|
|
|
self.app.statusbar.clear_alerts()
|
2019-12-12 19:04:55 +00:00
|
|
|
|
2020-06-22 19:04:33 +01:00
|
|
|
def click_select(self, event: tk.Event) -> None:
|
2019-12-20 18:51:52 +00:00
|
|
|
current = self.tree.selection()[0]
|
2020-07-25 18:30:14 +01:00
|
|
|
exception = self.alarm_map[current]
|
2019-12-20 18:51:52 +00:00
|
|
|
self.codetext.text.config(state=tk.NORMAL)
|
2020-07-23 03:19:22 +01:00
|
|
|
self.codetext.text.delete(1.0, tk.END)
|
2020-07-25 18:30:14 +01:00
|
|
|
self.codetext.text.insert(1.0, exception.text)
|
2019-12-20 18:51:52 +00:00
|
|
|
self.codetext.text.config(state=tk.DISABLED)
|