-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathnice.py
More file actions
135 lines (100 loc) · 3.96 KB
/
nice.py
File metadata and controls
135 lines (100 loc) · 3.96 KB
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
import sys
import os
import subprocess
import bpy
from ..utils.Functions import reload_current_blend_file, timer
from ..operators.OT_Settings import TM_OT_Settings_OpenMessageBox
MODULES_FOLDER = bpy.utils.user_resource("SCRIPTS", path="modules") + os.path.sep
PYTHON_BIN = sys.executable
def run_pip_command(*cmds, run_module="pip"):
command = [PYTHON_BIN, "-m", run_module, *cmds]
print(" ".join(command))
return subprocess.run(command, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
classes = None
panel_registered = False
installation_success = False
class TM_PT_NICE_installer(bpy.types.Panel):
bl_label = "NICE"
bl_idname = "TM_PT_NICE_installer"
bl_context = "objectmode"
# bl_parent_id = "TM_PT_Map_Manipulate"
bl_category = "Blendermania"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_options = {"DEFAULT_CLOSED"}
def draw_header(self, context):
layout = self.layout
layout.label(icon="COLLECTION_COLOR_03")
def draw_header_preset(self, context):
layout = self.layout
# tm_props = get_global_props()
row = layout.row(align=True)
col = row.column(align=True)
op = col.operator("view3d.tm_open_messagebox", text="", icon="QUESTION")
op.link = ""
op.title = self.bl_label
op.infos = TM_OT_Settings_OpenMessageBox.get_text(
"Nadeo Importer Community Edition",
"",
"To use NICE, you must install python dependencies.",
"Blender will freeze during the installation, don't worry!",
)
def draw(self, context):
layout = self.layout
box = layout.box()
if installation_success:
col = box.column()
col.label(text="Installation successful!", icon="CHECKMARK")
col.label(text="Reloading blender ...", icon="BLANK1")
else:
box.label(text="Nadeo Importer Community Edition")
col = box.column()
col.alert = True
col.scale_y = 0.7
col.label(text="Dependencies are missing.")
col.alert = False
col.label(text="Install below to use NICE.")
col.label(text="Save your blender file before installing")
col.label(text="(expect freeze & auto restart)")
row = layout.row()
row.scale_y = 1.5
row.operator("view3d.tm_nice_install_deps", text="Install NICE dependencies")
def try_register():
try:
from .blender.importer import TM_OT_NICE_Item_Import, TM_OT_NICE_Map_Import, TM_PT_NICE
global classes
classes = (TM_OT_NICE_Item_Import, TM_OT_NICE_Map_Import, TM_PT_NICE)
for cls in classes:
bpy.utils.register_class(cls)
return True
except ModuleNotFoundError as err:
print("ModuleNotFoundError")
print(err)
return False
class TM_OT_NICE_Item_Install_Deps(bpy.types.Operator):
bl_idname = "view3d.tm_nice_install_deps"
bl_description = "Install NICE dependencies using pip."
bl_label = "Install NICE dependencies"
def execute(self, context):
run_pip_command(run_module="ensurepip")
run_pip_command("install", "--target", MODULES_FOLDER, "construct", "gbx-py", "Pillow")
# display reload text
global installation_success
installation_success = True
def run():
reload_current_blend_file()
timer(run, 2)
return {"FINISHED"}
def NICE_register():
if not try_register():
bpy.utils.register_class(TM_OT_NICE_Item_Install_Deps)
bpy.utils.register_class(TM_PT_NICE_installer)
global panel_registered
panel_registered = True
def NICE_unregister():
if panel_registered:
bpy.utils.unregister_class(TM_OT_NICE_Item_Install_Deps)
bpy.utils.unregister_class(TM_PT_NICE_installer)
if classes is not None:
for cls in reversed(classes):
bpy.utils.unregister_class(cls)