-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathprefs.py
413 lines (325 loc) · 12.9 KB
/
prefs.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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
# ##### BEGIN GPL LICENSE BLOCK #####
#
# <Super Project Manager helps you manage your Blender Projects.>
# Copyright (C) <2023> <Blender Defender>
#
# 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, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####
import bpy
from bpy.props import (
StringProperty,
EnumProperty,
CollectionProperty,
BoolProperty,
IntProperty
)
from bpy.types import (
PropertyGroup,
AddonPreferences,
Context,
UILayout
)
import os
from os import path as p
import re
from . import addon_updater_ops
from .functions.main_functions import (
structure_sets_enum,
structure_sets_enum_update,
active_project_enum,
active_project_enum_update
)
from .objects.path_generator import (
Subfolders,
subfolder_enum,
)
C = bpy.context
D = bpy.data
FOLDER_BOX_PADDING_X = 0.1
FOLDER_BOX_PADDING_Y = 1
WARNING_MARGIN_BOTTOM = 0.2
ADD_FOLDER_BUTTON_MARGIN_TOP = 0.4
class project_folder_props(PropertyGroup):
render_outputpath: BoolProperty(
name="Render Output",
description="Set the last path this folder input results in as output path for your renders",
default=False)
folder_name: StringProperty(
name="Folder Name",
description="Automatic Setup Folder. \
Format for Adding Subfolders: Folder>>Subfolder>>Subsubfolder",
default="")
class FilebrowserEntry(PropertyGroup):
icon: StringProperty(default="FILE_FOLDER")
is_valid: BoolProperty()
"""Whether this path is currently reachable"""
name: StringProperty()
path: StringProperty()
use_save: BoolProperty()
"""Whether this path is saved in bookmarks, or generated from OS"""
def get_active_project_path(self):
active_directory = bpy.context.space_data.params.directory.decode(
encoding="utf-8")
for i, p in enumerate(self.project_paths):
if os.path.normpath(p.path) == os.path.normpath(active_directory):
return i
return -1
def set_active_project_path(self, value):
bpy.context.space_data.params.directory = self.project_paths[value].path.encode(
)
# Custom setter logic
self["active_project_path"] = value
def layout_tab_items(self, context: 'Context'):
items = [
("misc_settings", "General", "General settings of Super Project Manager."),
("folder_structure_sets", "Folder Structures",
"Manage your folder structure settings."),
]
if bpy.app.version < (4, 2):
items.append(
("updater", "Updater", "Check for updates and install them."),
)
return items
class SUPER_PROJECT_MANAGER_APT_Preferences(AddonPreferences):
bl_idname = __package__
previous_set: StringProperty(default="Default Folder Set")
custom_folders: CollectionProperty(type=project_folder_props)
automatic_folders: CollectionProperty(type=project_folder_props)
active_project: EnumProperty(
name="Active Project",
description="Which project should be displayed in the Filebrowser panel.",
items=active_project_enum,
update=active_project_enum_update
)
project_paths: CollectionProperty(type=FilebrowserEntry)
active_project_path: IntProperty(
name="Custom Property",
get=get_active_project_path,
set=set_active_project_path
)
layout_tab: EnumProperty(
name="UI Section",
description="Display the different UI Elements of the Super Project Manager preferences.",
items=layout_tab_items,
default=0)
folder_structure_sets: EnumProperty(
name="Folder Structure Set",
description="A list of all available folder sets.",
items=structure_sets_enum,
update=structure_sets_enum_update
)
prefix_with_project_name: BoolProperty(
name="Project Name Prefix",
description="If enabled, use the project name as prefix for all folders",
default=False,
)
auto_set_render_outputpath: BoolProperty(
name="Auto Set Render Output Path",
description="If enabled, the feature to automatically set the Render Output path can be used",
default=False,
)
default_project_location: StringProperty(
name="Default Project Location",
subtype="DIR_PATH",
default=p.expanduser("~")
)
save_folder: EnumProperty(
name="Save to",
items=subfolder_enum
)
preview_subfolders: BoolProperty(
name="Preview compiled Subfolders",
description="Show the compiled subfolder-strings in the preferences",
default=False
)
enable_additional_rearrange_tools: BoolProperty(
name="Enable additional rearrange operators",
description="Enable the 'Move to top' and 'Move to bottom' operator. This will make the rearrange panel more crowded",
default=False
)
auto_check_update: BoolProperty(
name="Auto-check for Update",
description="If enabled, auto-check for updates using an interval",
default=True,
)
updater_intrval_months: IntProperty(
name="Months",
description="Number of months between checking for updates",
default=0,
min=0
)
updater_intrval_days: IntProperty(
name="Days",
description="Number of days between checking for updates",
default=7,
min=0,
max=31
)
updater_intrval_hours: IntProperty(
name="Hours",
description="Number of hours between checking for updates",
default=0,
min=0,
max=23
)
updater_intrval_minutes: IntProperty(
name="Minutes",
description="Number of minutes between checking for updates",
default=0,
min=0,
max=59
)
def draw(self, context: Context):
layout: UILayout = self.layout
# Layout Tabs to switch between Settings Tabs.
row = layout.row(align=True)
row.scale_y = 1.3
row.prop(self, "layout_tab", expand=True)
if self.layout_tab == "misc_settings":
self.draw_misc_settings(context, layout)
if self.layout_tab == "folder_structure_sets":
self.draw_folder_structure_sets(context, layout)
if self.layout_tab == "updater":
# updater draw function
# could also pass in col as third arg
addon_updater_ops.update_settings_ui(self, context)
# Display warning, if a backup of a corrupted file is in the Addons Data directory
addons_data_dir = p.join(p.expanduser(
"~"), "Blender Addons Data", "blender-project-starter")
corrupted_files = [file for file in os.listdir(
addons_data_dir) if re.match("BPS\.\d\d\d\d-\d\d-\d\d\.json", file)]
if len(corrupted_files) > 0:
layout.separator()
box = layout.box()
box.label(
text="Warning: Corrupted Addon Data files detected", icon="ERROR")
box.label(
text="Click 'Open directory' below to view the corrupted files or click 'Support' for help on Discord.")
box.label(text="Corrupted files:")
for f in corrupted_files:
row = box.row()
row.scale_y = 0.4
row.label(text=f)
box.operator(
"wm.path_open", text="Open directory").filepath = addons_data_dir
# Support URL
layout.separator()
col = layout.column()
op = col.operator("wm.url_open", text="Support", icon="URL")
op.url = "https://bd-links.netlify.app/discord-spm"
def draw_misc_settings(self, context: Context, layout: UILayout):
layout.label(text="Default Project Location")
layout.prop(self, "default_project_location", text="")
layout.separator(factor=0.4)
layout.prop(self, "prefix_with_project_name",
text="Add the Project Name as Folder Prefix")
layout.separator(factor=0.4)
layout.prop(self, "auto_set_render_outputpath",
text="Automatically set the render output path")
layout.separator(factor=0.4)
layout.prop(self, "enable_additional_rearrange_tools")
def draw_folder_structure_sets(self, context: Context, layout: UILayout):
layout.label(text="Folder Structure Set")
row = layout.row(align=True)
row.prop(self, "folder_structure_sets", text="")
row.operator("super_project_manager.add_structure_set",
text="", icon="ADD")
op = row.operator(
"super_project_manager.remove_structure_set", text="", icon="REMOVE")
op.structure_set = self.previous_set
# Layout the Box containing the folder structure properties.
box = layout.box()
box.separator(factor=FOLDER_BOX_PADDING_Y)
compiled_preview_string = ""
for index, folder in enumerate(self.automatic_folders):
self.draw_folder_props(index, folder, box)
compiled_preview_string += "((" + folder.folder_name + "))++"
# Add folder button
box.separator(factor=ADD_FOLDER_BUTTON_MARGIN_TOP)
row = box.row()
row.split(factor=FOLDER_BOX_PADDING_X) # Padding left
op = row.operator("super_project_manager.add_folder",
icon="PLUS")
op.coming_from = "prefs"
row.split(factor=FOLDER_BOX_PADDING_X) # Padding right
box.separator(factor=FOLDER_BOX_PADDING_Y) # Padding bottom
# Expand/Collapse Preview of compiled subfolders
row = box.row()
row.alignment = "LEFT"
icon = "TRIA_DOWN" if self.preview_subfolders else "TRIA_RIGHT"
row.prop(self, "preview_subfolders",
emboss=False, icon=icon, text="Preview")
# Preview complete folder structure
if self.preview_subfolders:
prefix = ""
if self.prefix_with_project_name:
prefix = "Project_Name_"
for line in str(Subfolders(compiled_preview_string, prefix)).split("\n"):
row = box.row()
row.split(factor=FOLDER_BOX_PADDING_X)
row.scale_y = 0.3
row.label(text=line)
def draw_folder_props(self, index: int, folder: 'project_folder_props', layout: UILayout):
render_outpath_active = True in [
e.render_outputpath for e in self.automatic_folders]
row = layout.row()
row.split(factor=FOLDER_BOX_PADDING_X) # Padding left
# # split.label(text="Folder {}".format(index + 1))
# Folder Name/Path Property
row.prop(folder, "folder_name", text="")
# Render Output Path
if self.auto_set_render_outputpath:
col = row.column()
col.enabled = folder.render_outputpath or not render_outpath_active
col.prop(folder, "render_outputpath",
text="", icon="OUTPUT", emboss=folder.render_outputpath)
# Remove Icon
op = row.operator("super_project_manager.remove_folder",
text="",
emboss=False,
icon="PANEL_CLOSE")
op.index = index
op.coming_from = "prefs"
row.split(factor=FOLDER_BOX_PADDING_X) # Padding right
for warning in Subfolders(folder.folder_name).warnings:
row = layout.row()
row.split(factor=FOLDER_BOX_PADDING_X) # Padding left
row.label(text=warning, icon="ERROR")
layout.separator(factor=WARNING_MARGIN_BOTTOM)
row.split(factor=FOLDER_BOX_PADDING_X) # Padding right
classes = (
project_folder_props,
FilebrowserEntry,
SUPER_PROJECT_MANAGER_APT_Preferences
)
def register():
for cls in classes:
bpy.utils.register_class(cls)
def legacy_register(bl_info):
# addon updater code and configurations
# in case of broken version, try to register the updater first
# so that users can revert back to a working version
addon_updater_ops.register(bl_info)
# register the example panel, to show updater buttons
for cls in classes:
addon_updater_ops.make_annotations(cls) # avoid blender 2.8 warnings
bpy.utils.register_class(cls)
def unregister():
# addon updater unregister
addon_updater_ops.unregister()
# register the example panel, to show updater buttons
for cls in reversed(classes):
bpy.utils.unregister_class(cls)