controlnet validation
This commit is contained in:
parent
c4a117a236
commit
6a42748191
2 changed files with 30 additions and 8 deletions
|
@ -1,7 +1,7 @@
|
||||||
"""
|
"""
|
||||||
input validation
|
input validation
|
||||||
"""
|
"""
|
||||||
import logging
|
import re
|
||||||
import tkinter as tk
|
import tkinter as tk
|
||||||
|
|
||||||
import netaddr
|
import netaddr
|
||||||
|
@ -14,12 +14,14 @@ class InputValidation:
|
||||||
self.positive_int = None
|
self.positive_int = None
|
||||||
self.positive_float = None
|
self.positive_float = None
|
||||||
self.name = None
|
self.name = None
|
||||||
|
self.ip4 = None
|
||||||
self.register()
|
self.register()
|
||||||
|
|
||||||
def register(self):
|
def register(self):
|
||||||
self.positive_int = self.master.register(self.check_positive_int)
|
self.positive_int = self.master.register(self.check_positive_int)
|
||||||
self.positive_float = self.master.register(self.check_positive_float)
|
self.positive_float = self.master.register(self.check_positive_float)
|
||||||
self.name = self.master.register(self.check_node_name)
|
self.name = self.master.register(self.check_node_name)
|
||||||
|
self.ip4 = self.master.register(self.check_ip4)
|
||||||
|
|
||||||
def ip_focus_out(self, event):
|
def ip_focus_out(self, event):
|
||||||
value = event.widget.get()
|
value = event.widget.get()
|
||||||
|
@ -35,7 +37,6 @@ class InputValidation:
|
||||||
event.widget.insert(tk.END, default)
|
event.widget.insert(tk.END, default)
|
||||||
|
|
||||||
def check_positive_int(self, s):
|
def check_positive_int(self, s):
|
||||||
logging.debug("int validation...")
|
|
||||||
if len(s) == 0:
|
if len(s) == 0:
|
||||||
return True
|
return True
|
||||||
try:
|
try:
|
||||||
|
@ -47,7 +48,6 @@ class InputValidation:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def check_positive_float(self, s):
|
def check_positive_float(self, s):
|
||||||
logging.debug("float validation...")
|
|
||||||
if len(s) == 0:
|
if len(s) == 0:
|
||||||
return True
|
return True
|
||||||
try:
|
try:
|
||||||
|
@ -59,7 +59,6 @@ class InputValidation:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def check_node_name(self, s):
|
def check_node_name(self, s):
|
||||||
logging.debug("node name validation...")
|
|
||||||
if len(s) < 0:
|
if len(s) < 0:
|
||||||
return False
|
return False
|
||||||
if len(s) == 0:
|
if len(s) == 0:
|
||||||
|
@ -70,7 +69,6 @@ class InputValidation:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def check_canvas_int(sefl, s):
|
def check_canvas_int(sefl, s):
|
||||||
logging.debug("int validation...")
|
|
||||||
if len(s) == 0:
|
if len(s) == 0:
|
||||||
return True
|
return True
|
||||||
try:
|
try:
|
||||||
|
@ -82,7 +80,6 @@ class InputValidation:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def check_canvas_float(self, s):
|
def check_canvas_float(self, s):
|
||||||
logging.debug("canvas float validation")
|
|
||||||
if not s:
|
if not s:
|
||||||
return True
|
return True
|
||||||
try:
|
try:
|
||||||
|
@ -92,3 +89,18 @@ class InputValidation:
|
||||||
return False
|
return False
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def check_ip4(self, s):
|
||||||
|
if not s:
|
||||||
|
return True
|
||||||
|
pat = re.compile("^([0-9]+[.])*[0-9]*$")
|
||||||
|
if pat.match(s) is not None:
|
||||||
|
_32bits = s.split(".")
|
||||||
|
if len(_32bits) > 4:
|
||||||
|
return False
|
||||||
|
for _8bits in _32bits:
|
||||||
|
if (_8bits and int(_8bits) > 255) or len(_8bits) > 3:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
|
@ -117,8 +117,18 @@ class ConfigFrame(FrameScroll):
|
||||||
button = ttk.Button(file_frame, text="...", command=func)
|
button = ttk.Button(file_frame, text="...", command=func)
|
||||||
button.grid(row=0, column=1)
|
button.grid(row=0, column=1)
|
||||||
else:
|
else:
|
||||||
entry = ttk.Entry(frame, textvariable=value)
|
if "controlnet" in option.name and "script" not in option.name:
|
||||||
entry.grid(row=index, column=1, sticky="ew", pady=pady)
|
entry = ttk.Entry(
|
||||||
|
frame,
|
||||||
|
textvariable=value,
|
||||||
|
validate="key",
|
||||||
|
validatecommand=(self.app.validation.ip4, "%P"),
|
||||||
|
)
|
||||||
|
entry.grid(row=index, column=1, sticky="ew", pady=pady)
|
||||||
|
else:
|
||||||
|
entry = ttk.Entry(frame, textvariable=value)
|
||||||
|
entry.grid(row=index, column=1, sticky="ew", pady=pady)
|
||||||
|
|
||||||
elif option.type in INT_TYPES:
|
elif option.type in INT_TYPES:
|
||||||
value.set(option.value)
|
value.set(option.value)
|
||||||
entry = ttk.Entry(
|
entry = ttk.Entry(
|
||||||
|
|
Loading…
Add table
Reference in a new issue