replace logging.info with logging.debug for unimportant loggings, change the functions inside type checking class into classmethods

This commit is contained in:
Huy Pham 2020-02-03 07:30:25 -08:00
parent 6c89ba1abb
commit 5dd379a2ee
4 changed files with 35 additions and 14 deletions

View file

@ -1,7 +1,6 @@
"""
custom color picker
"""
import logging
import tkinter as tk
from tkinter import ttk
from typing import TYPE_CHECKING, Any
@ -175,7 +174,6 @@ class ColorPickerDialog(Dialog):
self.hex.trace_add("write", self.update_color)
def button_ok(self):
logging.debug("not implemented")
self.color = self.hex.get()
self.destroy()

View file

@ -218,6 +218,12 @@ class CustomNodesDialog(Dialog):
if name not in self.app.core.custom_nodes:
image_file = Path(self.image_file).stem
node_draw = NodeDraw.from_custom(name, image_file, set(self.services))
logging.info(
"Created new custom node (%s), image file (%s), services: (%s)",
name,
image_file,
self.services,
)
self.app.core.custom_nodes[name] = node_draw
self.nodes_list.listbox.insert(tk.END, name)
self.reset_values()
@ -232,6 +238,12 @@ class CustomNodesDialog(Dialog):
node_draw.image_file = Path(self.image_file).stem
node_draw.image = self.image
node_draw.services = self.services
logging.debug(
"Edit custom node (%s), image: (%s), services (%s)",
name,
self.image_file,
self.services,
)
self.app.core.custom_nodes[name] = node_draw
self.nodes_list.listbox.delete(self.selected_index)
self.nodes_list.listbox.insert(self.selected_index, name)
@ -241,6 +253,7 @@ class CustomNodesDialog(Dialog):
if self.selected and self.selected in self.app.core.custom_nodes:
self.nodes_list.listbox.delete(self.selected_index)
del self.app.core.custom_nodes[self.selected]
logging.debug("Delete custom node (%s)", self.selected)
self.reset_values()
self.nodes_list.listbox.selection_clear(0, tk.END)
self.nodes_list.listbox.event_generate("<<ListboxSelect>>")

View file

@ -105,7 +105,7 @@ class Toolbar(ttk.Frame):
self.create_annotation_button()
def design_select(self, button: ttk.Button):
logging.info("selecting design button: %s", button)
logging.debug("selecting design button: %s", button)
self.select_button.state(["!pressed"])
self.link_button.state(["!pressed"])
self.node_button.state(["!pressed"])
@ -114,7 +114,7 @@ class Toolbar(ttk.Frame):
button.state(["pressed"])
def runtime_select(self, button: ttk.Button):
logging.info("selecting runtime button: %s", button)
logging.debug("selecting runtime button: %s", button)
self.runtime_select_button.state(["!pressed"])
self.stop_button.state(["!pressed"])
self.plot_button.state(["!pressed"])

View file

@ -31,7 +31,8 @@ class InputValidation:
self.rgb = self.master.register(self.check_rbg)
self.hex = self.master.register(self.check_hex)
def ip_focus_out(self, event: tk.Event):
@classmethod
def ip_focus_out(cls, event: tk.Event):
value = event.widget.get()
try:
IPNetwork(value)
@ -39,12 +40,14 @@ class InputValidation:
event.widget.delete(0, tk.END)
event.widget.insert(tk.END, "invalid")
def focus_out(self, event: tk.Event, default: str):
@classmethod
def focus_out(cls, event: tk.Event, default: str):
value = event.widget.get()
if value == "":
event.widget.insert(tk.END, default)
def check_positive_int(self, s: str) -> bool:
@classmethod
def check_positive_int(cls, s: str) -> bool:
if len(s) == 0:
return True
try:
@ -55,7 +58,8 @@ class InputValidation:
except ValueError:
return False
def check_positive_float(self, s: str) -> bool:
@classmethod
def check_positive_float(cls, s: str) -> bool:
if len(s) == 0:
return True
try:
@ -66,7 +70,8 @@ class InputValidation:
except ValueError:
return False
def check_node_name(self, s: str) -> bool:
@classmethod
def check_node_name(cls, s: str) -> bool:
if len(s) < 0:
return False
if len(s) == 0:
@ -76,7 +81,8 @@ class InputValidation:
return False
return True
def check_canvas_int(self, s: str) -> bool:
@classmethod
def check_canvas_int(cls, s: str) -> bool:
if len(s) == 0:
return True
try:
@ -87,7 +93,8 @@ class InputValidation:
except ValueError:
return False
def check_canvas_float(self, s: str) -> bool:
@classmethod
def check_canvas_float(cls, s: str) -> bool:
if not s:
return True
try:
@ -98,7 +105,8 @@ class InputValidation:
except ValueError:
return False
def check_ip4(self, s: str) -> bool:
@classmethod
def check_ip4(cls, s: str) -> bool:
if not s:
return True
pat = re.compile("^([0-9]+[.])*[0-9]*$")
@ -117,7 +125,8 @@ class InputValidation:
else:
return False
def check_rbg(self, s: str) -> bool:
@classmethod
def check_rbg(cls, s: str) -> bool:
if not s:
return True
if s.startswith("0") and len(s) >= 2:
@ -131,7 +140,8 @@ class InputValidation:
except ValueError:
return False
def check_hex(self, s: str) -> bool:
@classmethod
def check_hex(cls, s: str) -> bool:
if not s:
return True
pat = re.compile("^([#]([0-9]|[a-f])+)$|^[#]$")