-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathoperators.py
More file actions
835 lines (600 loc) · 27.5 KB
/
operators.py
File metadata and controls
835 lines (600 loc) · 27.5 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
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
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
# ##### 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,
IntProperty,
EnumProperty
)
from bpy.types import (
Context,
Event,
UILayout,
Operator
)
from bpy_extras.io_utils import ImportHelper, ExportHelper
import os
from os import path as p
import time
from .addon_types import AddonPreferences
from .functions.main_functions import (
generate_file_version_number,
is_file_in_project_folder,
save_filepath,
add_unfinished_project,
finish_project,
write_project_info,
set_file_hidden
)
from .functions.json_functions import (
decode_json,
encode_json
)
from .functions.register_functions import (
register_automatic_folders,
unregister_automatic_folders,
register_project_folders
)
from .objects.path_generator import (
Subfolders,
)
C = bpy.context
BPS_DATA_DIR = p.join(p.expanduser(
"~"), "Blender Addons Data", "blender-project-starter")
BPS_DATA_FILE = p.join(BPS_DATA_DIR, "BPS.json")
class SUPER_PROJECT_MANAGER_OT_Build_Project(Operator):
bl_idname = "super_project_manager.build_project"
bl_label = "Build Project"
bl_description = "Build Project Operator "
bl_options = {"REGISTER", "UNDO"}
def execute(self, context: Context):
D = bpy.data
scene = context.scene
prefs: 'AddonPreferences' = C.preferences.addons[__package__].preferences
projectpath = p.join(context.scene.project_location,
context.scene.project_name)
filename = context.scene.save_file_name
# Set the prefix.
prefix = ""
if prefs.prefix_with_project_name:
prefix = context.scene.project_name + "_"
# Set the list of Subfolders.
folders = prefs.automatic_folders
if context.scene.project_setup == "Custom_Setup":
folders = prefs.custom_folders
# Set the render outputfolder FULL path.
is_render_outputfolder_set = [e.render_outputpath for e in folders]
render_outputfolder = None
if True in is_render_outputfolder_set:
unparsed_string = folders[is_render_outputfolder_set.index(
True)].folder_name
render_outputfolder = Subfolders(
unparsed_string, prefix).compile_paths(p.join(context.scene.project_location,
# Use last path.
context.scene.project_name))[-1]
# Create the Project Folder.
if not p.isdir(projectpath):
os.makedirs(projectpath)
# Build all Project Folders
for folder in folders:
try:
s = Subfolders(folder.folder_name, prefix)
s.build_folders(p.join(context.scene.project_location,
context.scene.project_name))
except:
pass
# Set the subfolder of the Blender file.
subfolder: str = prefs.save_folder.strip()
# Set the path the Blender File gets saved to.
filepath = D.filepath
old_filepath = None
if filepath == "":
filepath = save_filepath(context, filename, subfolder)
elif not is_file_in_project_folder(context, D.filepath):
old_filepath = D.filepath
filepath = save_filepath(context, filename, subfolder)
if not context.scene.save_file_with_new_name:
filepath = save_filepath(context, p.basename(
D.filepath).split(".blend")[0], subfolder)
elif context.scene.save_blender_file_versioned:
filepath = generate_file_version_number(
D.filepath.split(".blen")[0].split("_v0")[0])
# Set the render Output path automatically.
if prefs.auto_set_render_outputpath and render_outputfolder and context.scene.set_render_output:
context.scene.render.filepath = "//" + \
p.relpath(render_outputfolder, p.dirname(filepath)) + "\\"
if context.scene.save_blender_file:
bpy.ops.wm.save_as_mainfile(filepath=filepath,
compress=scene.compress_save,
relative_remap=scene.remap_relative
)
if context.scene.cut_or_copy and old_filepath:
os.remove(old_filepath)
# Add the project to the list of unfinished projects.
if context.scene.add_new_project:
add_unfinished_project(projectpath)
# Store all the necessary data in the project info file
write_project_info(projectpath, filepath)
# Open the project directory in the explorer, if wanted.
if context.scene.open_directory:
open_location = p.join(context.scene.project_location,
context.scene.project_name)
open_location = p.realpath(open_location)
bpy.ops.wm.path_open(filepath=open_location)
return {"FINISHED"}
class SUPER_PROJECT_MANAGER_OT_add_folder(Operator):
bl_idname = "super_project_manager.add_folder"
bl_label = "Add Folder"
bl_description = "Add a Folder with the subfolder \
Layout Folder>>Subfolder>>Subsubfolder."
coming_from: StringProperty()
def execute(self, context: Context):
pref: 'AddonPreferences' = context.preferences.addons[__package__].preferences
if self.coming_from == "prefs":
folder = pref.automatic_folders.add()
else:
folder = pref.custom_folders.add()
return {"FINISHED"}
class SUPER_PROJECT_MANAGER_OT_remove_folder(Operator):
bl_idname = "super_project_manager.remove_folder"
bl_label = "Remove Folder"
bl_description = "Remove the selected Folder."
index: IntProperty()
coming_from: StringProperty()
def execute(self, context: Context):
pref: 'AddonPreferences' = context.preferences.addons[__package__].preferences
if self.coming_from == "prefs":
folder = pref.automatic_folders.remove(self.index)
else:
folder = pref.custom_folders.remove(self.index)
return {"FINISHED"}
class SUPER_PROJECT_MANAGER_OT_add_project(Operator, ImportHelper):
bl_idname = "super_project_manager.add_project"
bl_label = "Add Project"
bl_description = "Add a Project"
filter_glob: StringProperty(default='*.filterall', options={'HIDDEN'})
def execute(self, context: Context):
projectpath = p.dirname(self.filepath)
message_type, message = add_unfinished_project(projectpath)
self.report(message_type, message)
return {"FINISHED"}
def draw(self, context: Context):
layout = self.layout
layout.label(text="Please select a project Directory")
class SUPER_PROJECT_MANAGER_OT_finish_project(Operator):
bl_idname = "super_project_manager.finish_project"
bl_label = "Finish Project"
bl_description = "Finish the selected Project."
bl_options = {'REGISTER', 'UNDO'}
index: IntProperty()
project_name: StringProperty()
def execute(self, context: Context):
finish_project(self.index)
return {'FINISHED'}
def invoke(self, context: Context, event: Event):
return context.window_manager.invoke_props_dialog(self)
def draw(self, context: Context):
layout: UILayout = self.layout
# layout.prop(self, "disable")
layout.label(
text="Congratulations, you've finished your project!")
layout.separator()
confirmation_text = f"Click OK below to remove '{self.project_name}' from your ToDo List."
if len(confirmation_text) > 55:
# Break up the confirmation text, if it is longer than 55 characters.
pieces = confirmation_text.split(" ")
confirmation_lines = []
line = ""
for p in pieces:
if len(line + p) > 55:
confirmation_lines.append(line)
line = ""
line += p + " "
confirmation_lines.append(line)
# Display the confirmation text line by line
for line in confirmation_lines:
row = layout.row()
row.scale_y = 0.6
row.label(text=line)
else:
layout.label(text=confirmation_text)
class SUPER_PROJECT_MANAGER_OT_redefine_project_path(Operator, ImportHelper):
bl_idname = "super_project_manager.redefine_project_path"
bl_label = "Update Project path"
bl_description = "Your project has changed location - \
please update the project path"
name: StringProperty()
filter_glob: StringProperty(default='*.filterall', options={'HIDDEN'})
index: IntProperty()
def execute(self, context: Context):
projectpath = p.dirname(self.filepath)
self.redefine_project_path(self.index, projectpath)
message = "Successfully changed project path: " + \
p.basename(projectpath)
self.report({'INFO'}, message)
return {"FINISHED"}
def draw(self, context: Context):
name = self.name
layout = self.layout
layout.label(text="Please select your project Directory for:")
layout.label(text=name)
def redefine_project_path(self, index, new_path):
data = decode_json(BPS_DATA_FILE)
data["unfinished_projects"][index][1] = new_path
encode_json(data, BPS_DATA_FILE)
class SUPER_PROJECT_MANAGER_OT_open_blender_file(Operator):
"""Open the latest Blender-File of a project"""
bl_idname = "super_project_manager.open_blender_file"
bl_label = "Open Blender File"
bl_options = {'REGISTER', 'UNDO'}
filepath: StringProperty()
message_type: StringProperty()
message: StringProperty()
def execute(self, context: Context):
bpy.ops.wm.open_mainfile(filepath=self.filepath)
self.report(
{self.message_type}, self.message)
return {"FINISHED"}
class SUPER_PROJECT_MANAGER_ot_define_blend_file_location(Operator, ImportHelper):
"""This Operator is used to (re)define the location of the projects main Blender File"""
bl_idname = "super_project_manager.define_blend_file_location"
bl_label = "Define Project Blender File Path"
bl_options = {'REGISTER', 'UNDO'}
bl_description = "Can't find the right path to the Blender File. \
Please select the latest Blender File of you Project."
filter_glob: StringProperty(default='*.blend', options={'HIDDEN'})
message_type: StringProperty()
message: StringProperty()
projectpath: StringProperty()
def execute(self, context: Context):
# print(self.filepath)
write_project_info(self.projectpath, self.filepath)
message = "Successfully defined Blender Filepath: " + \
p.basename(self.filepath)
self.report({'INFO'}, message)
bpy.ops.super_project_manager.open_blender_file(
filepath=self.filepath, message_type="INFO", message=f"Opened the project file found in {self.filepath}")
return {"FINISHED"}
def draw(self, context: Context):
name = p.basename(self.projectpath)
layout = self.layout
layout.label(text=self.message_type + ": " + self.message)
layout.label(text="Please select your project Directory for:")
layout.label(text=name)
class SUPER_PROJECT_MANAGER_ot_rearrange_up(Operator):
"""Rearrange a Project or Label one step up."""
bl_idname = "super_project_manager.rearrange_up"
bl_label = "Rearrange Up"
bl_options = {'REGISTER', 'UNDO'}
index: IntProperty()
def execute(self, context: Context):
index = self.index
data = decode_json(BPS_DATA_FILE)
data["unfinished_projects"][index], data["unfinished_projects"][index -
1] = data["unfinished_projects"][index - 1], data["unfinished_projects"][index]
encode_json(data, BPS_DATA_FILE)
return {'FINISHED'}
class SUPER_PROJECT_MANAGER_ot_rearrange_down(Operator):
"""Rearrange a Project or Label one step down."""
bl_idname = "super_project_manager.rearrange_down"
bl_label = "Rearrange Down"
bl_options = {'REGISTER', 'UNDO'}
index: IntProperty()
def execute(self, context: Context):
index = self.index
data = decode_json(BPS_DATA_FILE)
data["unfinished_projects"][index], data["unfinished_projects"][index +
1] = data["unfinished_projects"][index + 1], data["unfinished_projects"][index]
encode_json(data, BPS_DATA_FILE)
return {'FINISHED'}
class SUPER_PROJECT_MANAGER_ot_rearrange_to_top(Operator):
"""Rearrange a Project or Label to the top."""
bl_idname = "super_project_manager.rearrange_to_top"
bl_label = "Rearrange to Top"
bl_options = {'REGISTER', 'UNDO'}
index: IntProperty()
def execute(self, context: Context):
index = self.index
data = decode_json(BPS_DATA_FILE)
element = data["unfinished_projects"].pop(index)
data["unfinished_projects"].insert(0, element)
encode_json(data, BPS_DATA_FILE)
return {'FINISHED'}
class SUPER_PROJECT_MANAGER_ot_rearrange_to_bottom(Operator):
"""Rearrange a Project or Label to the bottom."""
bl_idname = "super_project_manager.rearrange_to_bottom"
bl_label = "Rearrange to Bottom"
bl_options = {'REGISTER', 'UNDO'}
index: IntProperty()
def execute(self, context: Context):
index = self.index
data = decode_json(BPS_DATA_FILE)
element = data["unfinished_projects"].pop(index)
data["unfinished_projects"].append(element)
encode_json(data, BPS_DATA_FILE)
return {'FINISHED'}
class SUPER_PROJECT_MANAGER_ot_add_label(Operator):
"""Add a category Label to the open projects list."""
bl_idname = "super_project_manager.add_label"
bl_label = "Add Label"
bl_options = {'REGISTER', 'UNDO'}
label: StringProperty()
def execute(self, context: Context):
data = decode_json(BPS_DATA_FILE)
data["unfinished_projects"].append(["label", self.label])
encode_json(data, BPS_DATA_FILE)
return {'FINISHED'}
def invoke(self, context: Context, event: Event):
return context.window_manager.invoke_props_dialog(self)
def draw(self, context: Context):
layout: UILayout = self.layout
layout.prop(self, "label", text="Category Label Text:")
class SUPER_PROJECT_MANAGER_ot_remove_label(Operator):
"""Remove a category Label from the open projects list."""
bl_idname = "super_project_manager.remove_label"
bl_label = "Remove Label"
bl_options = {'REGISTER', 'UNDO'}
index: IntProperty()
def execute(self, context: Context):
data = decode_json(BPS_DATA_FILE)
data["unfinished_projects"].pop(self.index)
encode_json(data, BPS_DATA_FILE)
return {'FINISHED'}
class SUPER_PROJECT_MANAGER_ot_change_label(Operator):
"""Change a category Label from the open projects list."""
bl_idname = "super_project_manager.change_label"
bl_label = "Change Label"
bl_options = {'REGISTER', 'UNDO'}
index: IntProperty()
label: StringProperty()
def execute(self, context: Context):
data = decode_json(BPS_DATA_FILE)
data["unfinished_projects"][self.index] = ["label", self.label]
encode_json(data, BPS_DATA_FILE)
return {'FINISHED'}
def invoke(self, context: Context, event: Event):
return context.window_manager.invoke_props_dialog(self)
def draw(self, context: Context):
layout: UILayout = self.layout
layout.prop(self, "label", text="Category Label Text:")
class SUPER_PROJECT_MANAGER_ot_add_structure_set(Operator):
"""Adds a new folder structure set."""
bl_idname = "super_project_manager.add_structure_set"
bl_label = "Add Folder Structure Set"
bl_options = {'REGISTER', 'UNDO'}
name: StringProperty()
def execute(self, context: Context):
prefs: 'AddonPreferences' = context.preferences.addons[__package__].preferences
data = decode_json(BPS_DATA_FILE)
data["automatic_folders"][self.name] = []
encode_json(data, BPS_DATA_FILE)
prefs.folder_structure_sets = self.name
return {'FINISHED'}
def invoke(self, context: Context, event: Event):
return context.window_manager.invoke_props_dialog(self)
def draw(self, context: Context):
layout = self.layout
layout.prop(self, "name", text="Folder Structure Set Name:")
class SUPER_PROJECT_MANAGER_ot_remove_structure_set(Operator):
"""Remove a folder structure set"""
bl_idname = "super_project_manager.remove_structure_set"
bl_label = "Remove Set"
bl_options = {'REGISTER', 'UNDO'}
structure_set: StringProperty()
def execute(self, context: Context):
prefs: 'AddonPreferences' = context.preferences.addons[__package__].preferences
prefs.folder_structure_sets = "Default Folder Set"
if self.structure_set == "Default Folder Set":
return {'FINISHED'}
data = decode_json(BPS_DATA_FILE)
data["automatic_folders"].pop(self.structure_set)
encode_json(data, BPS_DATA_FILE)
return {'FINISHED'}
class SUPER_PROJECT_MANAGER_OT_add_panel_project(Operator):
"""Add a project to the project panel."""
bl_idname = "super_project_manager.add_panel_project"
bl_label = "Add"
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context: 'Context'):
data: dict = decode_json(BPS_DATA_FILE)
prefs: 'AddonPreferences' = context.preferences.addons[__package__].preferences
project_path = p.normpath(
context.space_data.params.directory.decode("utf-8"))
options = data.get("filebrowser_panel_options", [])[:]
options.append(project_path)
data["filebrowser_panel_options"] = options
encode_json(data, BPS_DATA_FILE)
prefs.active_project = project_path
return {'FINISHED'}
class SUPER_PROJECT_MANAGER_OT_remove_panel_project(Operator):
"""Remove a project from the project panel."""
bl_idname = "super_project_manager.remove_panel_project"
bl_label = "remove"
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context: 'Context'):
data: dict = decode_json(BPS_DATA_FILE)
prefs: 'AddonPreferences' = context.preferences.addons[__package__].preferences
options = data.get("filebrowser_panel_options", [])[:]
options.remove(prefs.active_project)
data["filebrowser_panel_options"] = options
encode_json(data, BPS_DATA_FILE)
prefs.active_project = options[0]
return {'FINISHED'}
class SUPER_PROJECT_MANAGER_OT_panel_folder_base(Operator):
"""Base operator for panel folder operations"""
bl_idname = "super_project_manager.panel_folder_base"
bl_label = "Panel Folder Base"
bl_options = {'REGISTER', 'UNDO'}
def invoke(self, context: Context, event: Event):
prefs: 'AddonPreferences' = context.preferences.addons[__package__].preferences
if p.exists(p.join(prefs.active_project, ".blender_pm")):
return self.execute(context)
return context.window_manager.invoke_props_dialog(self)
def draw(self, context: Context):
layout: 'UILayout' = self.layout
layout.label(text="This project is missing important metadata.")
layout.label(
text="Do you want to continue? (Metadata will be added now)")
def execute(self, context: 'Context'):
prefs: 'AddonPreferences' = context.preferences.addons[__package__].preferences
project_metadata_file = p.join(prefs.active_project, ".blender_pm")
if not p.exists(project_metadata_file):
encode_json({"blender_files": {
"main_file": "",
"other_files": []
}, "build_date": time.time()}, project_metadata_file)
set_file_hidden(project_metadata_file, False)
data: dict = decode_json(project_metadata_file)
folders = data.get("displayed_project_folders", [])[:]
if len(folders) == 0:
for f in prefs.project_paths:
folders.append({"folder_path": f.path})
data["displayed_project_folders"] = self.manipulate_folders(
context, folders)
encode_json(data, project_metadata_file)
register_project_folders(prefs.project_paths, prefs.active_project)
set_file_hidden(project_metadata_file)
return {'FINISHED'}
def manipulate_folders(self, context: 'Context', folders: 'list') -> list:
return folders
class SUPER_PROJECT_MANAGER_OT_add_panel_project_folder(SUPER_PROJECT_MANAGER_OT_panel_folder_base):
"""Add the current folder path to the project panel."""
bl_idname = "super_project_manager.add_panel_project_folder"
bl_label = "Add Folder"
bl_options = {'REGISTER', 'UNDO'}
def manipulate_folders(self, context: Context, folders: list) -> list:
folders = folders[:]
folder_path = p.normpath(
context.space_data.params.directory.decode("utf-8"))
folders.append({"folder_path": folder_path})
paths = []
i = 0
while i < len(folders):
if folders[i].get("folder_path", "") in paths:
folders.pop(i)
continue
paths.append(folders[i].get("folder_path", ""))
i += 1
return folders
class SUPER_PROJECT_MANAGER_OT_remove_panel_project_folder(SUPER_PROJECT_MANAGER_OT_panel_folder_base):
"""Remove a folder from the project panel."""
bl_idname = "super_project_manager.remove_panel_project_folder"
bl_label = "remove"
bl_options = {'REGISTER', 'UNDO'}
index: IntProperty()
def manipulate_folders(self, context: Context, folders: list) -> list:
folders = folders[:]
folders.pop(self.index)
return folders
class SUPER_PROJECT_MANAGER_OT_move_panel_project_folder(SUPER_PROJECT_MANAGER_OT_panel_folder_base):
"""Rearrange the project panel"""
bl_idname = "super_project_manager.move_panel_project_folder"
bl_label = "Move"
bl_options = {'REGISTER', 'UNDO'}
index: IntProperty()
direction: IntProperty()
def manipulate_folders(self, context: Context, folders: list) -> list:
folders = folders[:]
f = folders.pop(self.index)
folders.insert(self.index + self.direction, f)
return folders
class SUPER_PROJECT_MANAGER_OT_import_settings(Operator, ImportHelper):
bl_idname = "super_project_manager.import_settings"
bl_label = "Import Settings"
bl_description = "Import SPM Settings"
filter_glob: StringProperty(default='*.json', options={'HIDDEN'})
def execute(self, context: Context):
file_to_import: str | None = self.filepath
prefs: 'AddonPreferences' = context.preferences.addons[__package__].preferences
if not file_to_import:
self.report({"WARNING"}, "No file to import")
return {"CANCELLED"}
imported_prefs = decode_json(file_to_import)
prefs.prefix_with_project_name = imported_prefs["prefix_with_project_name"]
prefs.auto_set_render_outputpath = imported_prefs["auto_set_render_outputpath"]
prefs.default_project_location = imported_prefs["default_project_location"]
prefs.preview_subfolders = imported_prefs["preview_subfolders"]
prefs.enable_additional_rearrange_tools = imported_prefs["enable_additional_rearrange_tools"]
prefs.previous_set = imported_prefs["previous_set"]
encode_json(imported_prefs["bps_data"], BPS_DATA_FILE)
register_automatic_folders(prefs.automatic_folders, prefs.previous_set)
prefs.folder_structure_sets = imported_prefs["folder_structure_sets"]
return {"FINISHED"}
class SUPER_PROJECT_MANAGER_OT_export_settings(Operator, ExportHelper):
bl_idname = "super_project_manager.export_settings"
bl_label = "Export Settings"
bl_description = "Export SPM Settings"
filename_ext = ".json"
def execute(self, context: Context):
file_to_export: str | None = self.filepath
prefs: 'AddonPreferences' = context.preferences.addons[__package__].preferences
if not file_to_export:
self.report({"WARNING"}, "No file to export")
return {"CANCELLED"}
unregister_automatic_folders(
prefs.automatic_folders, prefs.previous_set)
exported_prefs = {}
exported_prefs["prefix_with_project_name"] = prefs.prefix_with_project_name
exported_prefs["auto_set_render_outputpath"] = prefs.auto_set_render_outputpath
exported_prefs["default_project_location"] = prefs.default_project_location
exported_prefs["preview_subfolders"] = prefs.preview_subfolders
exported_prefs["previous_set"] = prefs.previous_set
exported_prefs["enable_additional_rearrange_tools"] = prefs.enable_additional_rearrange_tools
exported_prefs["folder_structure_sets"] = prefs.folder_structure_sets
exported_prefs["bps_data"] = decode_json(BPS_DATA_FILE)
encode_json(exported_prefs, file_to_export)
return {"FINISHED"}
classes = (
SUPER_PROJECT_MANAGER_OT_add_folder,
SUPER_PROJECT_MANAGER_OT_remove_folder,
SUPER_PROJECT_MANAGER_OT_Build_Project,
SUPER_PROJECT_MANAGER_OT_add_project,
SUPER_PROJECT_MANAGER_OT_finish_project,
SUPER_PROJECT_MANAGER_OT_redefine_project_path,
SUPER_PROJECT_MANAGER_OT_open_blender_file,
SUPER_PROJECT_MANAGER_ot_define_blend_file_location,
SUPER_PROJECT_MANAGER_ot_rearrange_up,
SUPER_PROJECT_MANAGER_ot_rearrange_down,
SUPER_PROJECT_MANAGER_ot_rearrange_to_top,
SUPER_PROJECT_MANAGER_ot_rearrange_to_bottom,
SUPER_PROJECT_MANAGER_ot_add_label,
SUPER_PROJECT_MANAGER_ot_remove_label,
SUPER_PROJECT_MANAGER_ot_change_label,
SUPER_PROJECT_MANAGER_ot_add_structure_set,
SUPER_PROJECT_MANAGER_ot_remove_structure_set,
SUPER_PROJECT_MANAGER_OT_add_panel_project,
SUPER_PROJECT_MANAGER_OT_remove_panel_project,
SUPER_PROJECT_MANAGER_OT_add_panel_project_folder,
SUPER_PROJECT_MANAGER_OT_remove_panel_project_folder,
SUPER_PROJECT_MANAGER_OT_move_panel_project_folder,
SUPER_PROJECT_MANAGER_OT_import_settings,
SUPER_PROJECT_MANAGER_OT_export_settings,
)
def register():
prefs: 'AddonPreferences' = C.preferences.addons[__package__].preferences
register_automatic_folders(prefs.automatic_folders, prefs.previous_set)
for cls in classes:
bpy.utils.register_class(cls)
def unregister():
prefs: 'AddonPreferences' = C.preferences.addons[__package__].preferences
unregister_automatic_folders(prefs.automatic_folders, prefs.previous_set)
for cls in reversed(classes):
bpy.utils.unregister_class(cls)