2023-05-02 18:38:16 +02:00
|
|
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
|
|
|
import importlib
|
|
|
|
import os
|
|
|
|
|
|
|
|
import bpy
|
|
|
|
from bpy.types import Operator
|
|
|
|
|
|
|
|
import vse_toolbox
|
|
|
|
|
|
|
|
|
|
|
|
from vse_toolbox.bl_utils import (get_addon_prefs, get_scene_settings)
|
|
|
|
from vse_toolbox.file_utils import (read_file, )
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class VSETB_OT_reload_addon(Operator):
|
|
|
|
bl_idname = "vse_toolbox.reload_addon"
|
|
|
|
bl_options = {"UNDO"}
|
|
|
|
bl_label = 'Reload VSE ToolBox Addon'
|
|
|
|
bl_description = 'Reload The VSE ToolBox Addon'
|
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
|
|
|
|
print('Execute reload')
|
|
|
|
|
|
|
|
vse_toolbox.unregister()
|
|
|
|
importlib.reload(vse_toolbox)
|
|
|
|
vse_toolbox.register()
|
|
|
|
|
|
|
|
return {'FINISHED'}
|
|
|
|
|
|
|
|
|
|
|
|
class VSETB_OT_load_settings(Operator):
|
|
|
|
bl_idname = "vse_toolbox.load_settings"
|
|
|
|
bl_options = {"UNDO"}
|
|
|
|
bl_label = 'Load Settings'
|
|
|
|
bl_description = 'Load VSE ToolBox settings from config file'
|
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
prefs = get_addon_prefs()
|
|
|
|
settings = get_scene_settings()
|
|
|
|
project = settings.active_project
|
|
|
|
|
|
|
|
if not prefs.config_path:
|
2023-05-03 14:40:07 +02:00
|
|
|
return {'FINISHED'}
|
2023-05-02 18:38:16 +02:00
|
|
|
|
|
|
|
addon_config = read_file(os.path.expandvars(prefs.config_path))
|
|
|
|
|
|
|
|
addon_config['trackers'] = addon_config.get('trackers')
|
|
|
|
trackers = addon_config.pop('trackers')
|
|
|
|
|
2023-05-02 20:46:45 +02:00
|
|
|
addon_config['spreadsheet_export'] = addon_config.get('spreadsheet_export')
|
|
|
|
spreadsheet_export_config = addon_config.pop('spreadsheet_export')
|
2023-05-02 18:38:16 +02:00
|
|
|
|
|
|
|
project_name = addon_config.get('project_name')
|
|
|
|
if project_name:
|
|
|
|
settings.project_name = project_name
|
|
|
|
|
|
|
|
# Project Properties
|
|
|
|
for k, v in addon_config.items():
|
|
|
|
try:
|
|
|
|
setattr(project, k, v)
|
|
|
|
except Exception:
|
|
|
|
print(f'Could not set property {k} with value {v} to project {settings.project_name}')
|
|
|
|
|
2023-05-02 20:46:45 +02:00
|
|
|
|
|
|
|
export_cells = project.spreadsheet_export.cells
|
|
|
|
for k, v in spreadsheet_export_config.items():
|
|
|
|
if k == 'cells':
|
|
|
|
#project.spreadsheet.clear()
|
2023-05-02 18:38:16 +02:00
|
|
|
|
2023-05-02 20:46:45 +02:00
|
|
|
for i, cell_data in enumerate(v):
|
|
|
|
if not 'name' in cell_data:
|
|
|
|
print(f'cell_data {cell_data} need to have a attribute name')
|
|
|
|
continue
|
2023-05-02 18:38:16 +02:00
|
|
|
|
2023-05-02 20:46:45 +02:00
|
|
|
cell = export_cells.get(cell_data['name'])
|
2023-05-02 18:38:16 +02:00
|
|
|
|
2023-05-02 20:46:45 +02:00
|
|
|
if not cell:
|
|
|
|
print(f"cell {cell_data['name']} not in spreadsheet")
|
|
|
|
continue
|
2023-05-02 18:38:16 +02:00
|
|
|
|
2023-05-02 20:46:45 +02:00
|
|
|
export_cells.move(list(export_cells).index(cell), i)
|
2023-05-02 18:38:16 +02:00
|
|
|
|
2023-05-02 20:46:45 +02:00
|
|
|
for prop_name in ('export_name', 'enabled'):
|
|
|
|
if prop_name in cell_data:
|
|
|
|
setattr(cell, prop_name, cell_data[prop_name])
|
2023-05-02 18:38:16 +02:00
|
|
|
|
2023-05-02 20:46:45 +02:00
|
|
|
else:
|
2023-05-02 18:38:16 +02:00
|
|
|
try:
|
2023-05-02 20:46:45 +02:00
|
|
|
setattr(project.spreadsheet_export, k, v)
|
2023-05-02 18:38:16 +02:00
|
|
|
except Exception:
|
|
|
|
print(f'Could not set option {k} with value {v} to spreadsheet')
|
|
|
|
|
|
|
|
return {'FINISHED'}
|
|
|
|
|
|
|
|
|
|
|
|
classes = (
|
|
|
|
VSETB_OT_reload_addon,
|
|
|
|
VSETB_OT_load_settings
|
|
|
|
)
|
|
|
|
|
|
|
|
def register():
|
|
|
|
for cls in classes:
|
|
|
|
bpy.utils.register_class(cls)
|
|
|
|
|
|
|
|
def unregister():
|
|
|
|
for cls in reversed(classes):
|
|
|
|
bpy.utils.unregister_class(cls)
|