forked from regcs/AliceLG
-
Notifications
You must be signed in to change notification settings - Fork 0
/
preferences.py
234 lines (196 loc) · 9.13 KB
/
preferences.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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
# ##### BEGIN GPL LICENSE BLOCK #####
#
# Copyright © 2021 Christian Stolze
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# ##### END GPL LICENSE BLOCK #####
# MODULE DESCRIPTION:
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# This includes everything that is related to the add-on preferences,
# installation of requirements, etc.
# ------------------ INTERNAL MODULES --------------------
from .globals import *
# ------------------- EXTERNAL MODULES -------------------
import bpy
from bpy.types import AddonPreferences
# ---------------- GLOBAL ADDON LOGGER -------------------
import logging
LookingGlassAddonLogger = logging.getLogger('Alice/LG')
# ------------- DEFINE ADDON PREFERENCES ----------------
# an operator that installs the python dependencies
class LOOKINGGLASS_OT_install_dependencies(bpy.types.Operator):
bl_idname = "lookingglass.install_dependencies"
bl_label = "Install Dependencies"
bl_description = "Install all Python dependencies required by this add-on to the add-on directory."
bl_options = {'REGISTER', 'INTERNAL'}
def execute(self, context):
# if dependencies are missing
if not LookingGlassAddon.check_dependecies():
import platform, subprocess
import datetime
# path to python
python_path = bpy.path.abspath(sys.executable)
# generate logfile
logfile = open(bpy.path.abspath(LookingGlassAddon.logpath + 'side-packages-install.log'), 'a')
LookingGlassAddonLogger.info("Installing missing side-packages. See '%s' for details." % (LookingGlassAddon.logpath + 'side-packages-install.log',))
# ensure that pip is installed
# NOTE: This should not be required, but a Linux user reported that
# on Blender 2.93 PIP was not bundled
if platform.system() == 'Linux': subprocess.call([python_path, '-m', 'ensurepip'], stdout=logfile)
# install the dependencies to the add-on's library path
for module in LookingGlassAddon.external_dependecies:
if not LookingGlassAddon.is_installed(module):
# This is a workaround:
# - pynng is currently not maintained anymore
# - we compiled wheels ourselves and include them with Alice/LG
# - pynng will be obsolete in newer versions of Alice/LG
if module[1] == 'pynng':
subprocess.call([python_path, '-m', 'pip', 'download', module[1], '--dest=' + os.path.join(LookingGlassAddon.libpath, 'wheels'), '--no-cache'], stdout=logfile)
subprocess.call([python_path, '-m', 'pip', 'install', '--find-links=' + os.path.join(LookingGlassAddon.libpath, 'wheels'), module[1], '--target', LookingGlassAddon.libpath, '--no-cache', '--no-index'] + module[3], stdout=logfile)
else:
subprocess.call([python_path, '-m', 'pip', 'install', '--upgrade', module[1], '--target', LookingGlassAddon.libpath, '--no-cache'] + module[3], stdout=logfile)
logfile.write("###################################" + '\n')
logfile.write("Installer finished: " + str(datetime.datetime.now()) + '\n')
logfile.write("###################################" + '\n')
# close logfile
logfile.close()
return {'FINISHED'}
# Preferences pane for this Addon in the Blender preferences
class LOOKINGGLASS_PT_install_dependencies(AddonPreferences):
bl_idname = __package__
# render mode
render_mode: bpy.props.EnumProperty(
items = [('0', 'Single Camera Mode', 'The quilt is rendered using a single moving camera.'),
('1', 'Multiview Camera Mode', 'The quilt is rendered using Blenders multiview mechanism.')],
default='0',
name="Render Mode",
)
# logger level
logger_level: bpy.props.EnumProperty(
items = [('0', 'Debug messages', 'All messages are written to the log file. This is for detailed debugging and extended bug reports'),
('1', 'Info, Warnings, and Errors', 'All info, warning, and error messages are written to the log file. This is for standard bug reports'),
('2', 'Only Errors', 'Only error messages are written to the log file. This is for less verbose console outputs')],
default='1',
name="Logging Mode",
update=LookingGlassAddon.update_logger_levels,
)
console_output: bpy.props.BoolProperty(
default=False,
name="Log to console",
description="Additionally log outputs to std out for debugging",
update=LookingGlassAddon.update_logger_levels,
)
# need this here, since the actual logger level property is not initialized
# before the dependencies are installed. but we want to log all details
logger_level = 0
console_output = False
# draw function
def draw(self, context):
# Notify the user and provide an option to install
layout = self.layout
layout.alert = True
# draw an Button for Installation of python dependencies
if not LookingGlassAddon.check_dependecies():
row = layout.row()
row.alignment = 'EXPAND'
row.scale_y = 0.5
row.label(text="Some Python dependencies are missing for Alice/LG to work. These modules are")
row = layout.row(align=True)
row.alignment = 'EXPAND'
row.scale_y = 0.5
row.label(text="required to communicate with HoloPlay Service. If you click the button below,")
row = layout.row(align=True)
row.alignment = 'EXPAND'
row.scale_y = 0.5
row.label(text="the required modules will be installed to the addon's path. This may take a few")
row = layout.row(align=True)
row.alignment = 'EXPAND'
row.scale_y = 0.5
row.label(text="minutes, during which the Blender user interface will be unresponsive.")
row = layout.row(align=True)
row.alignment = 'EXPAND'
row.operator("lookingglass.install_dependencies", icon='PLUS')
else:
row = layout.row()
row.label(text="All required Python modules were installed.")
row = layout.row()
row.label(text="Please restart Blender to activate the changes!", icon='ERROR')
# Preferences pane for this Addon in the Blender preferences
class LOOKINGGLASS_PT_preferences(AddonPreferences):
bl_idname = __package__
bl_label = "Alice/LG Preferences"
# render mode
render_mode: bpy.props.EnumProperty(
items = [('0', 'Current Blender instance', 'The quilt is rendered in the current Blender instance.'),
('1', 'Multiple background instances', 'The quilt is rendered in multiple Blender instances running in the background.')],
default='0',
name="Render Mode",
)
# camera mode for rendering
camera_mode: bpy.props.EnumProperty(
items = [('0', 'Single Camera Mode', 'The quilt is rendered using a single moving camera.'),
('1', 'Multiview Camera Mode', 'The quilt is rendered using Blenders multiview mechanism.')],
default='0',
name="Camera Mode",
)
# logger level
logger_level: bpy.props.EnumProperty(
items = [('0', 'Debug messages', 'All messages are written to the log file. This is for detailed debugging and extended bug reports'),
('1', 'Info, Warnings, and Errors', 'All info, warning, and error messages are written to the log file. This is for standard bug reports'),
('2', 'Only Errors', 'Only error messages are written to the log file. This is for less verbose console outputs')],
default='1',
name="Logging Mode",
update=LookingGlassAddon.update_logger_levels,
)
console_output: bpy.props.BoolProperty(
default=False,
name="Log to console",
description="Additionally log outputs to std out for debugging",
update=LookingGlassAddon.update_logger_levels,
)
# need this here, since the actual logger level property is not initialized
# before the dependencies are installed. but we want to log all details
logger_level = 0
console_output = False
# draw function
def draw(self, context):
layout = self.layout
# # render mode
# row_render_mode = layout.row()
# column_1 = row_render_mode.column()
# column_1.label(text="Render Mode:")
# column_1.scale_x = 0.2
# column_2 = row_render_mode.column()
# column_2.prop(self, "render_mode", text="")
# column_2.scale_x = 0.8
# camera mode for rendering
row_camera_mode = layout.row()
column_1 = row_camera_mode.column()
column_1.label(text="Camera Mode:")
column_1.scale_x = 0.2
column_2 = row_camera_mode.column()
column_2.prop(self, "camera_mode", text="")
column_2.scale_x = 0.8
# logger level
row_logger = layout.row()
column_1 = row_logger.column()
column_1.label(text="Logging Mode:")
column_1.scale_x = 0.2
column_2 = row_logger.column()
column_2.prop(self, "logger_level", text="")
column_2.scale_x = 0.55
column_3 = row_logger.column()
column_3.prop(self, "console_output")
column_3.scale_x = 0.25