small updates to new gui exception dialog, fixed error checking and setting interface mac addresses
This commit is contained in:
parent
595e77a1ef
commit
6b5cd95ac2
5 changed files with 49 additions and 20 deletions
|
@ -240,12 +240,17 @@ class NodeConfigDialog(Dialog):
|
|||
|
||||
label = ttk.Label(tab, text="MAC")
|
||||
label.grid(row=row, column=0, padx=PADX, pady=PADY)
|
||||
is_auto = tk.BooleanVar(value=True)
|
||||
auto_set = not interface.mac
|
||||
if auto_set:
|
||||
state = tk.DISABLED
|
||||
else:
|
||||
state = tk.NORMAL
|
||||
is_auto = tk.BooleanVar(value=auto_set)
|
||||
checkbutton = ttk.Checkbutton(tab, text="Auto?", variable=is_auto)
|
||||
checkbutton.var = is_auto
|
||||
checkbutton.grid(row=row, column=1, padx=PADX)
|
||||
mac = tk.StringVar(value=interface.mac)
|
||||
entry = ttk.Entry(tab, textvariable=mac, state=tk.DISABLED)
|
||||
entry = ttk.Entry(tab, textvariable=mac, state=state)
|
||||
entry.grid(row=row, column=2, sticky="ew")
|
||||
func = partial(mac_auto, is_auto, entry)
|
||||
checkbutton.config(command=func)
|
||||
|
@ -345,7 +350,17 @@ class NodeConfigDialog(Dialog):
|
|||
interface.ip6 = ip6
|
||||
interface.ip6mask = ip6mask
|
||||
|
||||
interface.mac = data.mac.get()
|
||||
mac = data.mac.get()
|
||||
if mac and not netaddr.valid_mac(mac):
|
||||
title = f"MAC Error for {interface.name}"
|
||||
messagebox.showerror(title, "Invalid MAC Address")
|
||||
error = True
|
||||
data.mac.set(interface.mac)
|
||||
break
|
||||
else:
|
||||
mac = netaddr.EUI(mac)
|
||||
mac.dialect = netaddr.mac_unix_expanded
|
||||
interface.mac = str(mac)
|
||||
|
||||
# redraw
|
||||
if not error:
|
||||
|
|
|
@ -128,7 +128,9 @@ class NodeConfigServiceDialog(Dialog):
|
|||
dialog.show()
|
||||
else:
|
||||
messagebox.showinfo(
|
||||
"Node service configuration", "Select a service to configure"
|
||||
"Config Service Configuration",
|
||||
"Select a service to configure",
|
||||
parent=self,
|
||||
)
|
||||
|
||||
def click_save(self):
|
||||
|
|
|
@ -148,11 +148,12 @@ class NodeServiceDialog(Dialog):
|
|||
dialog.destroy()
|
||||
else:
|
||||
messagebox.showinfo(
|
||||
"Node service configuration", "Select a service to configure"
|
||||
"Service Configuration", "Select a service to configure", parent=self
|
||||
)
|
||||
|
||||
def click_save(self):
|
||||
# if node is custom type or current services are not the default services then set core node services and add node to modified services node set
|
||||
# if node is custom type or current services are not the default services then
|
||||
# set core node services and add node to modified services node set
|
||||
if (
|
||||
self.canvas_node.core_node.model not in self.app.core.default_services
|
||||
or self.current_services
|
||||
|
|
|
@ -1,36 +1,49 @@
|
|||
from tkinter import ttk
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import grpc
|
||||
|
||||
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:
|
||||
import grpc
|
||||
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
|
||||
def __init__(self, master, app: "Application", title: str, details: str) -> None:
|
||||
super().__init__(master, app, "CORE Exception", modal=True)
|
||||
self.title = title
|
||||
self.details = details
|
||||
self.error_message = None
|
||||
self.draw()
|
||||
|
||||
def draw(self):
|
||||
def draw(self) -> None:
|
||||
self.top.columnconfigure(0, weight=1)
|
||||
self.top.rowconfigure(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(self.top, image=image)
|
||||
label = ttk.Label(frame, image=image)
|
||||
label.image = image
|
||||
label.grid(row=0, column=0)
|
||||
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(row=1, column=0, sticky="nsew")
|
||||
self.error_message.grid(sticky="nsew", pady=PADY)
|
||||
|
||||
button = ttk.Button(self.top, text="Close", command=lambda: self.destroy())
|
||||
button.grid(sticky="ew")
|
||||
|
||||
|
||||
def show_grpc_error(e: "grpc.RpcError", master, app: "Application"):
|
||||
def show_grpc_error(e: grpc.RpcError, master, app: "Application"):
|
||||
title = [x.capitalize() for x in e.code().name.lower().split("_")]
|
||||
title = " ".join(title)
|
||||
title = f"GRPC {title}"
|
||||
|
@ -40,8 +53,6 @@ def show_grpc_error(e: "grpc.RpcError", master, app: "Application"):
|
|||
|
||||
def show_grpc_response_exceptions(class_name, exceptions, master, app: "Application"):
|
||||
title = f"Exceptions from {class_name}"
|
||||
detail = ""
|
||||
for e in exceptions:
|
||||
detail = detail + f"{e}\n"
|
||||
detail = "\n".join([str(x) for x in exceptions])
|
||||
dialog = ErrorDialog(master, app, title, detail)
|
||||
dialog.show()
|
||||
|
|
|
@ -444,7 +444,7 @@ def random_mac() -> str:
|
|||
value = random.randint(0, 0xFFFFFF)
|
||||
value |= 0x00163E << 24
|
||||
mac = netaddr.EUI(value)
|
||||
mac.dialect = netaddr.mac_unix
|
||||
mac.dialect = netaddr.mac_unix_expanded
|
||||
return str(mac)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue