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
|
||||
"""
|
||||
import logging
|
||||
import re
|
||||
import tkinter as tk
|
||||
|
||||
import netaddr
|
||||
|
@ -14,12 +14,14 @@ class InputValidation:
|
|||
self.positive_int = None
|
||||
self.positive_float = None
|
||||
self.name = None
|
||||
self.ip4 = None
|
||||
self.register()
|
||||
|
||||
def register(self):
|
||||
self.positive_int = self.master.register(self.check_positive_int)
|
||||
self.positive_float = self.master.register(self.check_positive_float)
|
||||
self.name = self.master.register(self.check_node_name)
|
||||
self.ip4 = self.master.register(self.check_ip4)
|
||||
|
||||
def ip_focus_out(self, event):
|
||||
value = event.widget.get()
|
||||
|
@ -35,7 +37,6 @@ class InputValidation:
|
|||
event.widget.insert(tk.END, default)
|
||||
|
||||
def check_positive_int(self, s):
|
||||
logging.debug("int validation...")
|
||||
if len(s) == 0:
|
||||
return True
|
||||
try:
|
||||
|
@ -47,7 +48,6 @@ class InputValidation:
|
|||
return False
|
||||
|
||||
def check_positive_float(self, s):
|
||||
logging.debug("float validation...")
|
||||
if len(s) == 0:
|
||||
return True
|
||||
try:
|
||||
|
@ -59,7 +59,6 @@ class InputValidation:
|
|||
return False
|
||||
|
||||
def check_node_name(self, s):
|
||||
logging.debug("node name validation...")
|
||||
if len(s) < 0:
|
||||
return False
|
||||
if len(s) == 0:
|
||||
|
@ -70,7 +69,6 @@ class InputValidation:
|
|||
return True
|
||||
|
||||
def check_canvas_int(sefl, s):
|
||||
logging.debug("int validation...")
|
||||
if len(s) == 0:
|
||||
return True
|
||||
try:
|
||||
|
@ -82,7 +80,6 @@ class InputValidation:
|
|||
return False
|
||||
|
||||
def check_canvas_float(self, s):
|
||||
logging.debug("canvas float validation")
|
||||
if not s:
|
||||
return True
|
||||
try:
|
||||
|
@ -92,3 +89,18 @@ class InputValidation:
|
|||
return False
|
||||
except ValueError:
|
||||
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.grid(row=0, column=1)
|
||||
else:
|
||||
entry = ttk.Entry(frame, textvariable=value)
|
||||
entry.grid(row=index, column=1, sticky="ew", pady=pady)
|
||||
if "controlnet" in option.name and "script" not in option.name:
|
||||
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:
|
||||
value.set(option.value)
|
||||
entry = ttk.Entry(
|
||||
|
|
Loading…
Reference in a new issue