fix merge conflict
This commit is contained in:
commit
95d36a1792
9 changed files with 224 additions and 42 deletions
85
daemon/core/gui/dialogs/executepython.py
Normal file
85
daemon/core/gui/dialogs/executepython.py
Normal file
|
@ -0,0 +1,85 @@
|
|||
import logging
|
||||
import tkinter as tk
|
||||
from tkinter import filedialog, ttk
|
||||
|
||||
from core.gui.appconfig import SCRIPT_PATH
|
||||
from core.gui.dialogs.dialog import Dialog
|
||||
from core.gui.themes import FRAME_PAD, PADX
|
||||
|
||||
|
||||
class ExecutePythonDialog(Dialog):
|
||||
def __init__(self, master, app):
|
||||
super().__init__(master, app, "Execute Python Script", modal=True)
|
||||
self.app = app
|
||||
self.with_options = tk.IntVar(value=0)
|
||||
self.options = tk.StringVar(value="")
|
||||
self.option_entry = None
|
||||
self.file_entry = None
|
||||
self.draw()
|
||||
|
||||
def draw(self):
|
||||
i = 0
|
||||
frame = ttk.Frame(self.top, padding=FRAME_PAD)
|
||||
frame.columnconfigure(0, weight=1)
|
||||
frame.columnconfigure(1, weight=1)
|
||||
frame.grid(row=i, column=0, sticky="nsew")
|
||||
i = i + 1
|
||||
var = tk.StringVar(value="")
|
||||
self.file_entry = ttk.Entry(frame, textvariable=var)
|
||||
self.file_entry.grid(row=0, column=0, sticky="ew")
|
||||
button = ttk.Button(frame, text="...", command=self.select_file)
|
||||
button.grid(row=0, column=1, sticky="ew")
|
||||
|
||||
self.top.columnconfigure(0, weight=1)
|
||||
button = ttk.Checkbutton(
|
||||
self.top,
|
||||
text="With Options",
|
||||
variable=self.with_options,
|
||||
command=self.add_options,
|
||||
)
|
||||
button.grid(row=i, column=0, sticky="ew")
|
||||
i = i + 1
|
||||
|
||||
label = ttk.Label(
|
||||
self.top, text="Any command-line options for running the Python script"
|
||||
)
|
||||
label.grid(row=i, column=0, sticky="ew")
|
||||
i = i + 1
|
||||
self.option_entry = ttk.Entry(
|
||||
self.top, textvariable=self.options, state="disabled"
|
||||
)
|
||||
self.option_entry.grid(row=i, column=0, sticky="ew")
|
||||
i = i + 1
|
||||
|
||||
frame = ttk.Frame(self.top, padding=FRAME_PAD)
|
||||
frame.columnconfigure(0, weight=1)
|
||||
frame.columnconfigure(1, weight=1)
|
||||
frame.grid(row=i, column=0)
|
||||
button = ttk.Button(frame, text="Execute", command=self.script_execute)
|
||||
button.grid(row=0, column=0, sticky="ew", padx=PADX)
|
||||
button = ttk.Button(frame, text="Cancel", command=self.destroy)
|
||||
button.grid(row=0, column=1, sticky="ew", padx=PADX)
|
||||
|
||||
def add_options(self):
|
||||
if self.with_options.get():
|
||||
self.option_entry.configure(state="normal")
|
||||
else:
|
||||
self.option_entry.configure(state="disabled")
|
||||
|
||||
def select_file(self):
|
||||
file = filedialog.askopenfilename(
|
||||
parent=self.top,
|
||||
initialdir=str(SCRIPT_PATH),
|
||||
title="Open python script",
|
||||
filetypes=((".py Files", "*.py"), ("All Files", "*")),
|
||||
)
|
||||
if file:
|
||||
self.file_entry.delete(0, "end")
|
||||
self.file_entry.insert("end", file)
|
||||
|
||||
def script_execute(self):
|
||||
file = self.file_entry.get()
|
||||
options = self.option_entry.get()
|
||||
logging.info("Execute %s with options %s", file, options)
|
||||
self.app.core.execute_script(file)
|
||||
self.destroy()
|
|
@ -1,9 +1,11 @@
|
|||
import logging
|
||||
import tkinter as tk
|
||||
from functools import partial
|
||||
from tkinter import ttk
|
||||
from tkinter import messagebox, ttk
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import netaddr
|
||||
|
||||
from core.gui import nodeutils
|
||||
from core.gui.appconfig import ICONS_PATH
|
||||
from core.gui.dialogs.dialog import Dialog
|
||||
|
@ -18,6 +20,58 @@ if TYPE_CHECKING:
|
|||
from core.gui.graph.node import CanvasNode
|
||||
|
||||
|
||||
def check_ip6(parent, name: str, value: str) -> bool:
|
||||
title = f"IP6 Error for {name}"
|
||||
if not value:
|
||||
messagebox.showerror(title, "Empty Value", parent=parent)
|
||||
return False
|
||||
values = value.split("/")
|
||||
if len(values) != 2:
|
||||
messagebox.showerror(
|
||||
title, "Must be in the format address/prefix", parent=parent
|
||||
)
|
||||
return False
|
||||
addr, mask = values
|
||||
if not netaddr.valid_ipv6(addr):
|
||||
messagebox.showerror(title, "Invalid IP6 address", parent=parent)
|
||||
return False
|
||||
try:
|
||||
mask = int(mask)
|
||||
if not (0 <= mask <= 128):
|
||||
messagebox.showerror(title, "Mask must be between 0-128", parent=parent)
|
||||
return False
|
||||
except ValueError:
|
||||
messagebox.showerror(title, "Invalid Mask", parent=parent)
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def check_ip4(parent, name: str, value: str) -> bool:
|
||||
title = f"IP4 Error for {name}"
|
||||
if not value:
|
||||
messagebox.showerror(title, "Empty Value", parent=parent)
|
||||
return False
|
||||
values = value.split("/")
|
||||
if len(values) != 2:
|
||||
messagebox.showerror(
|
||||
title, "Must be in the format address/prefix", parent=parent
|
||||
)
|
||||
return False
|
||||
addr, mask = values
|
||||
if not netaddr.valid_ipv4(addr):
|
||||
messagebox.showerror(title, "Invalid IP4 address", parent=parent)
|
||||
return False
|
||||
try:
|
||||
mask = int(mask)
|
||||
if not (0 <= mask <= 32):
|
||||
messagebox.showerror(title, "Mask must be between 0-32", parent=parent)
|
||||
return False
|
||||
except ValueError:
|
||||
messagebox.showerror(title, "Invalid mask", parent=parent)
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def mac_auto(is_auto: tk.BooleanVar, entry: ttk.Entry):
|
||||
logging.info("mac auto clicked")
|
||||
if is_auto.get():
|
||||
|
@ -203,7 +257,6 @@ class NodeConfigDialog(Dialog):
|
|||
label.grid(row=row, column=0, padx=PADX, pady=PADY)
|
||||
ip4 = tk.StringVar(value=f"{interface.ip4}/{interface.ip4mask}")
|
||||
entry = ttk.Entry(tab, textvariable=ip4)
|
||||
entry.bind("<FocusOut>", self.app.validation.ip_focus_out)
|
||||
entry.grid(row=row, column=1, columnspan=2, sticky="ew")
|
||||
row += 1
|
||||
|
||||
|
@ -211,7 +264,6 @@ class NodeConfigDialog(Dialog):
|
|||
label.grid(row=row, column=0, padx=PADX, pady=PADY)
|
||||
ip6 = tk.StringVar(value=f"{interface.ip6}/{interface.ip6mask}")
|
||||
entry = ttk.Entry(tab, textvariable=ip6)
|
||||
entry.bind("<FocusOut>", self.app.validation.ip_focus_out)
|
||||
entry.grid(row=row, column=1, columnspan=2, sticky="ew")
|
||||
|
||||
self.interfaces[interface.id] = InterfaceData(is_auto, mac, ip4, ip6)
|
||||
|
@ -240,6 +292,8 @@ class NodeConfigDialog(Dialog):
|
|||
self.image_file = file_path
|
||||
|
||||
def config_apply(self):
|
||||
error = False
|
||||
|
||||
# update core node
|
||||
self.node.name = self.name.get()
|
||||
if NodeUtils.is_image_node(self.node.type):
|
||||
|
@ -255,9 +309,31 @@ class NodeConfigDialog(Dialog):
|
|||
# update canvas node
|
||||
self.canvas_node.image = self.image
|
||||
|
||||
# update node interface data
|
||||
for interface in self.canvas_node.interfaces:
|
||||
data = self.interfaces[interface.id]
|
||||
if check_ip4(self, interface.name, data.ip4.get()):
|
||||
ip4, ip4mask = data.ip4.get().split("/")
|
||||
interface.ip4 = ip4
|
||||
interface.ip4mask = int(ip4mask)
|
||||
else:
|
||||
error = True
|
||||
data.ip4.set(f"{interface.ip4}/{interface.ip4mask}")
|
||||
break
|
||||
if check_ip6(self, interface.name, data.ip6.get()):
|
||||
ip6, ip6mask = data.ip6.get().split("/")
|
||||
interface.ip6 = ip6
|
||||
interface.ip6mask = int(ip6mask)
|
||||
interface.mac = data.mac.get()
|
||||
else:
|
||||
error = True
|
||||
data.ip6.set(f"{interface.ip6}/{interface.ip6mask}")
|
||||
break
|
||||
|
||||
# redraw
|
||||
self.canvas_node.redraw()
|
||||
self.destroy()
|
||||
if not error:
|
||||
self.canvas_node.redraw()
|
||||
self.destroy()
|
||||
|
||||
def interface_select(self, event: tk.Event):
|
||||
listbox = event.widget
|
||||
|
|
|
@ -56,9 +56,8 @@ class PreferencesDialog(Dialog):
|
|||
|
||||
label = ttk.Label(frame, text="Terminal")
|
||||
label.grid(row=2, column=0, pady=PADY, padx=PADX, sticky="w")
|
||||
combobox = ttk.Combobox(
|
||||
frame, textvariable=self.terminal, values=appconfig.TERMINALS
|
||||
)
|
||||
terminals = sorted(appconfig.TERMINALS.values())
|
||||
combobox = ttk.Combobox(frame, textvariable=self.terminal, values=terminals)
|
||||
combobox.grid(row=2, column=1, sticky="ew")
|
||||
|
||||
label = ttk.Label(frame, text="3D GUI")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue