Skip to content

Commit

Permalink
ai mat; window logger; bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
KarryCharon committed Dec 11, 2024
1 parent c1ca1e6 commit 7c9e3d9
Show file tree
Hide file tree
Showing 49 changed files with 11,333 additions and 135 deletions.
107 changes: 77 additions & 30 deletions SDNode/blueprints.py

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions SDNode/custom_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def f(data, mtype):
Timer.put((f, data, mtype))
return True

def draw(self, layout: bpy.types.UILayout, ctxt=""):
def draw(self, layout: bpy.types.UILayout, ctxt="", use_region_width=True):
from . import TaskManager
if self.enable:
cp = bpy.context.screen.sdn_custom
Expand All @@ -187,9 +187,11 @@ def draw(self, layout: bpy.types.UILayout, ctxt=""):
import blf
per = prog["value"] / prog["max"]
content = f"{per*100:3.0f}% "
lnum = int(bpy.context.region.width / bpy.context.preferences.view.ui_scale / 7 - 21)
lnum = int(lnum * 0.3)
lnum = int((bpy.context.region.width - blf.dimensions(0, content)[0]) / blf.dimensions(0, "█")[0]) - 10
lnum = 20
if use_region_width:
lnum = int(bpy.context.region.width / bpy.context.preferences.view.ui_scale / 7 - 21)
lnum = int(lnum * 0.3)
lnum = int((bpy.context.region.width - blf.dimensions(0, content)[0]) / blf.dimensions(0, "█")[0]) - 10
v = int(per * lnum)
content = content + "█" * v + "░" * (lnum - v)
row = layout.row()
Expand Down
47 changes: 45 additions & 2 deletions SDNode/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import aud
from platform import system
import struct
from ast import literal_eval
from concurrent.futures import ThreadPoolExecutor
from copy import deepcopy
from shutil import rmtree
Expand All @@ -19,6 +20,7 @@
from subprocess import Popen, PIPE, STDOUT
from pathlib import Path
from queue import Queue
from .utils import WindowLogger
from ..utils import rmtree as rt, logger, _T, PkgInstaller, update_screen
from ..timer import Timer
from ..preference import get_pref
Expand Down Expand Up @@ -150,9 +152,18 @@ class ErrType:

def get_print(self, info):
etype = info["type"]
if isinstance(etype, str) and etype.endswith("cup.CupException"):
info = literal_eval(info["message"])
etype = info["type"]
func = getattr(self, etype, self.unknown)
return func(info)

def sdn_no_image_provided(self, info):
return self.__print__(info)

def sdn_image_not_found(self, info):
return self.__print__(info)

def unknown(self, info):
if self.WITH_PRINT:
print(info)
Expand All @@ -179,8 +190,10 @@ def __print__(self, info):
info_list = []
if msg:
info_list.append(msg)
WindowLogger.push_log(msg)
if dt:
info_list.append(dt)
WindowLogger.push_log(dt)
return info_list

def required_input_missing(self, info):
Expand Down Expand Up @@ -412,7 +425,8 @@ def node_error_parse(self):
node_errors = self.error_info["node_errors"]
import bpy
from .utils import get_tree
logger.error("Node Error Parse")
logger.error(_T("Node Error Parse"))
WindowLogger.push_log(_T("Node Error Parse"))
for sc in bpy.data.screens:
try:
tree = get_tree(screen=sc)
Expand Down Expand Up @@ -630,13 +644,16 @@ def run(self) -> bool:
if not model_path or not Path(model_path).exists():
logger.error(_T("ComfyUI Path Not Found"))
TaskManager.put_error_msg(_T("ComfyUI Path Not Found"))
WindowLogger.push_log(_T("ComfyUI Path Not Found"))
return
logger.debug("%s: %s", _T("Model Path"), model_path)
WindowLogger.push_log("%s: %s", _T("Model Path"), model_path)
python = pref.get_python()
if pref.install_deps:
self.run_pre()

logger.warning(_T("Server Launching"))
WindowLogger.push_log(_T("Server Launching"))
if sys.platform == "win32" and not python.exists():
logger.error("%s:", _T("python interpreter not found"))
logger.error(" ↳%s:", _T("Ensure that the python_embeded located in the same level as ComfyUI dir"))
Expand All @@ -646,6 +663,14 @@ def run(self) -> bool:
logger.error(" │ ├─ python.exe")
logger.error(" │ └─ ...")
logger.error(" └─ ...")
WindowLogger.push_log("%s:", _T("python interpreter not found"))
WindowLogger.push_log(" ↳%s:", _T("Ensure that the python_embeded located in the same level as ComfyUI dir"))
WindowLogger.push_log(" SomeDirectory")
WindowLogger.push_log(" ├─ ComfyUI")
WindowLogger.push_log(" ├─ python_embeded")
WindowLogger.push_log(" │ ├─ python.exe")
WindowLogger.push_log(" │ └─ ...")
WindowLogger.push_log(" └─ ...")
return

# custom_nodes
Expand Down Expand Up @@ -961,10 +986,12 @@ def init_server(fake=False, callback=lambda: ...):
running = TaskManager.server.run()
if not TaskManager.server.exited() and running:
logger.warning(_T("Server Launched"))
WindowLogger.push_log(_T("Server Launched"))
TaskManager.start_polling()
callback()
else:
logger.error(_T("Server Launch Failed"))
WindowLogger.push_log(_T("Server Launch Failed"))
TaskManager.server.close()
return running

Expand Down Expand Up @@ -992,10 +1019,14 @@ def close_server():
@staticmethod
def push_task(task, pre=None, post=None, tree=None):
logger.debug(_T('Add Task'))
WindowLogger.push_log(_T('Add Task'))
if not TaskManager.is_launched():
TaskManager.put_error_msg(_T("Server Not Launched, Add Task Failed"))
WindowLogger.push_log(_T("Server Not Launched, Add Task Failed"))
TaskManager.put_error_msg(_T("Please Check ComfyUI Directory"))
WindowLogger.push_log(_T("Please Check ComfyUI Directory"))
logger.error(_T("Server Not Launched"))
WindowLogger.push_log(_T("Server Not Launched"))
return
TaskManager.task_queue.put(Task(task, pre=pre, post=post, tree=tree))

Expand Down Expand Up @@ -1055,6 +1086,7 @@ def poll_task():
task = TaskManager.task_queue.get()
TaskManager.progress = {'value': 0, 'max': 1}
logger.debug(_T("Submit Task"))
WindowLogger.push_log(_T("Submit Task"))
TaskManager.cur_task = task
try:
TaskManager.submit(task)
Expand Down Expand Up @@ -1088,6 +1120,7 @@ def submit(task: Task):
def queue_task(task: dict):
res = TaskManager.query_server_task()
logger.debug("P/R: %s/%s", len(res["queue_pending"]), len(res["queue_running"]))
WindowLogger.push_log("P/R: %s/%s", len(res["queue_pending"]), len(res["queue_running"]))

api = task.get("api")
if api == "prompt":
Expand Down Expand Up @@ -1220,16 +1253,23 @@ def on_message(ws, message):
n = data.get("node", "")
if n:
logger.debug("%s: %s", _T("Executing Node"), n)
WindowLogger.push_log("%s: %s", _T("Executing Node"), n)
elif mtype == "execution_start":
...
elif mtype == "execution_cached":
logger.debug("%s: %s", _T("Execution Cached"), data.get("nodes", ""))
elif mtype == "status":
WindowLogger.push_log("%s: %s", _T("Execution Cached"), data.get("nodes", ""))
elif mtype == "executed":
...
elif mtype == "execution_success":
...
elif mtype == "execution_error":
...
elif mtype == "status":
...
elif mtype != "progress":
logger.debug("%s: %s", _T("Message Type"), mtype)
WindowLogger.push_log("%s: %s", _T("Message Type"), mtype)

Timer.put(update_screen)

Expand Down Expand Up @@ -1273,6 +1313,7 @@ def on_message(ws, message):
TaskManager.progress_bar = 0
tm.push_res(data)
logger.warning("%s: %s", _T("Ran Node"), data["node"])
WindowLogger.push_log("%s: %s", _T("Ran Node"), data["node"])
elif mtype == "execution_error":
_msg = data.get("message", None)
if not _msg:
Expand All @@ -1298,6 +1339,7 @@ def on_message(ws, message):
...
elif mtype == "execution_success":
logger.warning("%s: %s", _T("Execute Node Success"), data["node"])
WindowLogger.push_log("%s: %s", _T("Execute Node Success"), data["node"])
elif mtype == "execution_interrupted":
{"type": "execution_interrupted",
"data": {"prompt_id": "e1f3cbf9-4b83-47cf-95c3-9f9a76ab5508",
Expand Down Expand Up @@ -1331,6 +1373,7 @@ def on_message(ws, message):
except ConnectionClosedError:
...
logger.debug(_T("Poll Result Thread Exit"))
# WindowLogger.push_log(_T("Poll Result Thread Exit")) # 可能是blender退出, 会导致crash
TaskManager.ws = None
if TaskManager.server.is_launched():
Timer.put((TaskManager.restart_server, True))
Expand Down
7 changes: 6 additions & 1 deletion SDNode/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ def get_icon_path(nname):
PREVICONPATH[class_type] = path_list
for name, mpath in pathmap.items():
reg_name = get_reg_name(name)
if mpath not in d:
continue
path_list[reg_name] = d[mpath][0]
return PREVICONPATH.get(nname, {})

Expand Down Expand Up @@ -250,6 +252,9 @@ def wrap(self, context):
if icon_id:
ENUM_ITEMS_CACHE[nname][inp_name] = items
si = str(item)
if si in spec_trans:
items.append((si, spec_trans.get(si, si), ""))
continue
items.append((si, spec_trans.get(si, si), "", icon_id, len(items)))
return items
return wrap
Expand Down Expand Up @@ -294,7 +299,7 @@ def FLOAT(nname, inp_name, reg_name, inp):
{'default': 8.0, 'min': 0.0, 'max': 100.0}
if len(inp) > 1:
if "step" in inp[1]:
inp[1]["step"] *= 100
inp[1]["step"] = min(inp[1]["step"] * 100, 100)
if inp[1].pop("display", False):
inp[1]["subtype"] = "FACTOR"
default = inp[1].pop("default", 0)
Expand Down
Loading

0 comments on commit 7c9e3d9

Please sign in to comment.