2020-01-13 12:03:13 -08:00
|
|
|
"""
|
|
|
|
status bar
|
|
|
|
"""
|
2019-11-25 11:23:04 -08:00
|
|
|
import tkinter as tk
|
2019-11-22 12:59:22 -08:00
|
|
|
from tkinter import ttk
|
2020-06-19 22:08:24 -07:00
|
|
|
from typing import TYPE_CHECKING, List, Optional
|
2019-11-22 12:59:22 -08:00
|
|
|
|
2020-06-19 22:08:24 -07:00
|
|
|
from core.api.grpc.core_pb2 import ExceptionEvent
|
2019-12-19 09:30:21 -08:00
|
|
|
from core.gui.dialogs.alerts import AlertsDialog
|
|
|
|
from core.gui.themes import Styles
|
2019-12-11 09:17:39 -08:00
|
|
|
|
2020-01-14 11:06:52 -08:00
|
|
|
if TYPE_CHECKING:
|
|
|
|
from core.gui.app import Application
|
|
|
|
|
2019-11-22 12:59:22 -08:00
|
|
|
|
|
|
|
class StatusBar(ttk.Frame):
|
2020-06-19 22:08:24 -07:00
|
|
|
def __init__(self, master: tk.Widget, app: "Application") -> None:
|
2020-05-15 14:46:35 -07:00
|
|
|
super().__init__(master)
|
2020-06-19 22:08:24 -07:00
|
|
|
self.app: "Application" = app
|
|
|
|
self.status: Optional[ttk.Label] = None
|
|
|
|
self.statusvar: tk.StringVar = tk.StringVar()
|
|
|
|
self.zoom: Optional[ttk.Label] = None
|
|
|
|
self.cpu_usage: Optional[ttk.Label] = None
|
|
|
|
self.alerts_button: Optional[ttk.Button] = None
|
|
|
|
self.running: bool = False
|
|
|
|
self.core_alarms: List[ExceptionEvent] = []
|
2019-11-22 12:59:22 -08:00
|
|
|
self.draw()
|
|
|
|
|
2020-06-19 22:08:24 -07:00
|
|
|
def draw(self) -> None:
|
2020-05-03 10:41:36 -07:00
|
|
|
self.columnconfigure(0, weight=7)
|
|
|
|
self.columnconfigure(1, weight=1)
|
2019-11-22 12:59:22 -08:00
|
|
|
self.columnconfigure(2, weight=1)
|
|
|
|
self.columnconfigure(3, weight=1)
|
2019-11-25 16:50:44 -08:00
|
|
|
|
2019-12-09 15:27:51 -08:00
|
|
|
frame = ttk.Frame(self, borderwidth=1, relief=tk.RIDGE)
|
|
|
|
frame.grid(row=0, column=0, sticky="ew")
|
|
|
|
frame.columnconfigure(0, weight=1)
|
2019-11-27 16:14:14 -08:00
|
|
|
|
2019-12-09 15:27:51 -08:00
|
|
|
self.status = ttk.Label(
|
|
|
|
self,
|
|
|
|
textvariable=self.statusvar,
|
|
|
|
anchor=tk.CENTER,
|
|
|
|
borderwidth=1,
|
|
|
|
relief=tk.RIDGE,
|
|
|
|
)
|
2020-05-03 10:41:36 -07:00
|
|
|
self.status.grid(row=0, column=0, sticky="ew")
|
2019-11-27 16:14:14 -08:00
|
|
|
|
2019-12-09 15:27:51 -08:00
|
|
|
self.zoom = ttk.Label(
|
2019-12-16 12:04:18 -08:00
|
|
|
self,
|
|
|
|
text="%s" % (int(self.app.canvas.ratio * 100)) + "%",
|
|
|
|
anchor=tk.CENTER,
|
|
|
|
borderwidth=1,
|
|
|
|
relief=tk.RIDGE,
|
2019-12-09 15:27:51 -08:00
|
|
|
)
|
2020-05-03 10:41:36 -07:00
|
|
|
self.zoom.grid(row=0, column=1, sticky="ew")
|
2019-11-27 16:14:14 -08:00
|
|
|
|
2019-12-09 15:27:51 -08:00
|
|
|
self.cpu_usage = ttk.Label(
|
|
|
|
self, text="CPU TBD", anchor=tk.CENTER, borderwidth=1, relief=tk.RIDGE
|
|
|
|
)
|
2020-05-03 10:41:36 -07:00
|
|
|
self.cpu_usage.grid(row=0, column=2, sticky="ew")
|
2019-11-27 16:14:14 -08:00
|
|
|
|
2019-12-12 21:05:45 -08:00
|
|
|
self.alerts_button = ttk.Button(
|
|
|
|
self, text="Alerts", command=self.click_alerts, style=Styles.green_alert
|
2019-12-09 15:27:51 -08:00
|
|
|
)
|
2020-05-03 10:41:36 -07:00
|
|
|
self.alerts_button.grid(row=0, column=3, sticky="ew")
|
2019-11-22 14:55:10 -08:00
|
|
|
|
2020-06-19 22:08:24 -07:00
|
|
|
def click_alerts(self) -> None:
|
2020-05-04 22:50:59 -07:00
|
|
|
dialog = AlertsDialog(self.app)
|
2019-12-11 09:17:39 -08:00
|
|
|
dialog.show()
|
|
|
|
|
2020-06-19 22:08:24 -07:00
|
|
|
def set_status(self, message: str) -> None:
|
2019-12-20 15:11:34 -08:00
|
|
|
self.statusvar.set(message)
|