-
Notifications
You must be signed in to change notification settings - Fork 55
/
__init__.py
176 lines (154 loc) · 5.77 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
bl_info = {
'name': 'ComfyUI Node Editor',
'author': '幻之境开发小组-会飞的键盘侠、只剩一瓶辣椒酱、a-One-Fan、DorotaLuna、hugeproblem、heredos、ra100',
'version': (1, 6, 0),
'blender': (3, 0, 0),
'location': '3DView->Panel',
'category': 'AI',
'doc_url': "https://shimo.im/docs/Ee32m0w80rfLp4A2"
}
__dict__ = {}
import time
ts = time.time()
def clear_pyc(path=None, depth=2):
# 递归删除 所有文件夹__pycache__
if depth == 0:
return
import shutil
from pathlib import Path
if path is None:
path = Path(__file__).parent
for f in path.iterdir():
if f.is_dir() and f.name == "__pycache__":
try:
shutil.rmtree(f)
except Exception:
...
continue
if f.is_dir():
clear_pyc(f, depth - 1)
clear_pyc()
import bpy
import sys
from addon_utils import disable
from .SDNode import rtnode_unreg, TaskManager
from .MultiLineText import EnableMLT
from .utils import Icon, FSWatcher, ScopeTimer, addon_bl_info
from .timer import timer_reg, timer_unreg
from .preference import pref_register, pref_unregister
from .ops import Ops, Ops_Mask, Load_History, Popup_Load, Copy_Tree, Load_Batch, Fetch_Node_Status, Clear_Node_Cache, Sync_Stencil_Image, NodeSearch, SDNode_To_Image, Image_To_SDNode, Image_Set_Channel_Packed, Open_Log_Window
from .ui import ui_reg, ui_unreg, Panel, HISTORY_UL_UIList, HistoryItem
from .SDNode.history import History
from .SDNode.rt_tracker import reg_tracker, unreg_tracker
from .SDNode.nodegroup import nodegroup_reg, nodegroup_unreg
from .SDNode.operators import ops_register, ops_unregister
from .SDNode.custom_support import custom_support_reg, custom_support_unreg
from .prop import RenderLayerString, MLTWord, Prop
from .Linker import linker_register, linker_unregister
from .hook import use_hook
clss = [Panel, Ops, RenderLayerString, MLTWord, Prop, HISTORY_UL_UIList, HistoryItem, Ops_Mask, Load_History, Popup_Load, Copy_Tree, Load_Batch, Fetch_Node_Status, Clear_Node_Cache, Sync_Stencil_Image, NodeSearch, SDNode_To_Image, Image_To_SDNode, Image_Set_Channel_Packed, Open_Log_Window, EnableMLT]
reg, unreg = bpy.utils.register_classes_factory(clss)
from platform import system
addon_bl_info.update(bl_info)
def dump_info():
import json
import os
from .preference import get_pref
if "--get-blender-ai-node-info" in sys.argv:
model_path = getattr(get_pref(), 'model_path')
info = {"Version": ".".join([str(i) for i in bl_info["version"]]), "ComfyUIPath": model_path}
sys.stderr.write(f"BlenderComfyUIInfo: {json.dumps(info)} BlenderComfyUIend")
sys.stderr.flush()
print(f'Blender {os.getpid()} PID', file=sys.stderr)
def track_ae():
mod = sys.modules.get(__package__, None)
if mod:
__dict__["__addon_enabled__"] = False
return 1
def disable_reload():
for nmod, mod in sys.modules.items():
if nmod == __package__ or not nmod.startswith(__package__):
continue
if not hasattr(mod, "__addon_enabled__"):
mod.__addon_enabled__ = False
if bpy.app.timers.is_registered(track_ae):
return
bpy.app.timers.register(track_ae, persistent=True)
# reset disable
_disable = disable
def hd(mod, *, default_set=False, handle_error=None):
if default_set and mod == __package__:
__dict__["NOT_RELOAD_BUILTIN"] = True
_disable(mod, default_set=default_set, handle_error=handle_error)
if default_set and mod == __package__:
__dict__.pop("NOT_RELOAD_BUILTIN")
sys.modules["addon_utils"].disable = hd
def reload_builtin():
if "NOT_RELOAD_BUILTIN" in __dict__:
return False
return __dict__.get("__addon_enabled__", None) is False
def register():
if reload_builtin():
return
_ = ScopeTimer(f"{__package__} Register")
reg_tracker()
pref_register()
if bpy.app.background:
dump_info()
return
from .translations import translations_dict
bpy.app.translations.register(__name__, translations_dict)
reg()
ui_reg()
Icon.set_hq_preview()
TaskManager.run_server(fake=True)
timer_reg()
# mlt_words注册到 sdn中会导致访问其他属性卡顿 what?
bpy.types.WindowManager.mlt_words = bpy.props.CollectionProperty(type=MLTWord, options={"SKIP_SAVE"})
bpy.types.WindowManager.mlt_words_index = bpy.props.IntProperty()
bpy.types.Scene.sdn = bpy.props.PointerProperty(type=Prop)
bpy.types.Scene.sdn_history_item = bpy.props.CollectionProperty(type=HistoryItem)
bpy.types.Scene.sdn_history_item_index = bpy.props.IntProperty(default=0)
bpy.types.Node.ac_expand = bpy.props.BoolProperty(name="Expand", default=True)
History.register_timer()
linker_register()
use_hook()
FSWatcher.init()
disable_reload()
nodegroup_reg()
ops_register()
custom_support_reg()
print(f"{__package__} Launch Time: {time.time() - ts:.4f}s")
def unregister():
if reload_builtin():
return
unreg_tracker()
pref_unregister()
if bpy.app.background:
return
bpy.app.translations.unregister(__name__)
unreg()
ui_unreg()
rtnode_unreg()
timer_unreg()
del bpy.types.Scene.sdn
del bpy.types.Scene.sdn_history_item
del bpy.types.Scene.sdn_history_item_index
History.unregister_timer()
modules_update()
linker_unregister()
use_hook(False)
ops_unregister()
nodegroup_unreg()
custom_support_unreg()
FSWatcher.stop()
def modules_update():
from .kclogger import logger
logger.close()
modules = []
for i in sys.modules:
if i.startswith(__package__) and i != __package__:
modules.append(i)
for i in modules:
del sys.modules[i]
del sys.modules[__package__]