fix refacto
parent
41a4c7a3a4
commit
4a3042030f
|
@ -15,7 +15,7 @@ bl_info = {
|
|||
|
||||
import sys
|
||||
from pathlib import Path
|
||||
sys.modules['vse_toolbox'] = sys.modules.pop(Path(__file__).parent.name)
|
||||
#sys.modules['vse_toolbox'] = sys.modules.pop(Path(__file__).parent.name)
|
||||
|
||||
from vse_toolbox import ui
|
||||
from vse_toolbox import operators
|
||||
|
|
|
@ -50,8 +50,8 @@ class VSETB_OT_load_settings(Operator):
|
|||
addon_config['trackers'] = addon_config.get('trackers')
|
||||
trackers = addon_config.pop('trackers')
|
||||
|
||||
addon_config['spreadsheet'] = addon_config.get('spreadsheet')
|
||||
spreadsheet = addon_config.pop('spreadsheet')
|
||||
addon_config['spreadsheet_export'] = addon_config.get('spreadsheet_export')
|
||||
spreadsheet_export_config = addon_config.pop('spreadsheet_export')
|
||||
|
||||
project_name = addon_config.get('project_name')
|
||||
if project_name:
|
||||
|
@ -64,30 +64,32 @@ class VSETB_OT_load_settings(Operator):
|
|||
except Exception:
|
||||
print(f'Could not set property {k} with value {v} to project {settings.project_name}')
|
||||
|
||||
if spreadsheet.get('cells'):
|
||||
#project.spreadsheet.clear()
|
||||
|
||||
export_cells = project.spreadsheet_export.cells
|
||||
for k, v in spreadsheet_export_config.items():
|
||||
if k == 'cells':
|
||||
#project.spreadsheet.clear()
|
||||
|
||||
for i, cell_data in enumerate(spreadsheet['cells']):
|
||||
if not 'name' in cell_data:
|
||||
print(f'cell_data {cell_data} need to have a attribute name')
|
||||
continue
|
||||
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
|
||||
|
||||
cell = project.spreadsheet.get(cell_data['name'])
|
||||
cell = export_cells.get(cell_data['name'])
|
||||
|
||||
if not cell:
|
||||
print(f"cell {cell_data['name']} not in spreadsheet")
|
||||
continue
|
||||
if not cell:
|
||||
print(f"cell {cell_data['name']} not in spreadsheet")
|
||||
continue
|
||||
|
||||
project.spreadsheet.move(list(project.spreadsheet).index(cell), i)
|
||||
export_cells.move(list(export_cells).index(cell), i)
|
||||
|
||||
for prop_name in ('export_name', 'enabled'):
|
||||
if prop_name in cell_data:
|
||||
setattr(cell, prop_name, cell_data[prop_name])
|
||||
for prop_name in ('export_name', 'enabled'):
|
||||
if prop_name in cell_data:
|
||||
setattr(cell, prop_name, cell_data[prop_name])
|
||||
|
||||
if spreadsheet.get('options'):
|
||||
for k, v in spreadsheet['options'].items():
|
||||
else:
|
||||
try:
|
||||
setattr(project.spreadsheet_options, k, v)
|
||||
setattr(project.spreadsheet_export, k, v)
|
||||
except Exception:
|
||||
print(f'Could not set option {k} with value {v} to spreadsheet')
|
||||
|
||||
|
|
|
@ -17,21 +17,21 @@ from vse_toolbox.bl_utils import (get_addon_prefs, get_scene_settings)
|
|||
from vse_toolbox.file_utils import open_file, install_module
|
||||
|
||||
|
||||
class VSETB_MT_spreadsheet_presets(Menu):
|
||||
class VSETB_MT_export_spreadsheet_presets(Menu):
|
||||
bl_label = 'Presets'
|
||||
preset_subdir = 'vse_toolbox'
|
||||
preset_operator = 'script.execute_preset'
|
||||
draw = Menu.draw_preset
|
||||
|
||||
|
||||
class VSETB_OT_add_spreadsheet_preset(AddPresetBase, Operator):
|
||||
class VSETB_OT_add_export_spreadsheet_preset(AddPresetBase, Operator):
|
||||
|
||||
bl_idname = "vse_toolbox.add_spreadsheet_preset"
|
||||
bl_label = "Add Spreadsheet Preset"
|
||||
bl_description = "Add Spreadsheet Preset"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
||||
preset_menu = 'VSETB_MT_spreadsheet_presets'
|
||||
preset_menu = 'VSETB_MT_export_spreadsheet_presets'
|
||||
|
||||
#preset_menu = 'VSETB_OT_MT_spreadsheet_presets'
|
||||
|
||||
|
@ -45,16 +45,15 @@ class VSETB_OT_add_spreadsheet_preset(AddPresetBase, Operator):
|
|||
|
||||
# Properties to store in the preset
|
||||
preset_values = [
|
||||
'project.spreadsheet',
|
||||
'project.spreadsheet_options'
|
||||
'project.spreadsheet_export',
|
||||
]
|
||||
|
||||
# Directory to store the presets
|
||||
preset_subdir = 'vse_toolbox'
|
||||
preset_subdir = 'vse_toolbox/spreadsheet_export'
|
||||
|
||||
|
||||
|
||||
class VSETB_OT_spreadsheet_move(Operator):
|
||||
class VSETB_OT_spreadsheet_cell_move(Operator):
|
||||
bl_idname = "vse_toolbox.spreadsheet_move"
|
||||
bl_label = "Move Spreadsheet items"
|
||||
bl_description = "Move Spreadsheet items"
|
||||
|
@ -71,22 +70,24 @@ class VSETB_OT_spreadsheet_move(Operator):
|
|||
scn = context.scene
|
||||
project = get_scene_settings().active_project
|
||||
|
||||
idx = project.spreadsheet_index
|
||||
spreadsheet = project.spreadsheet_export
|
||||
cells = spreadsheet.cells
|
||||
idx = spreadsheet.cell_index
|
||||
|
||||
try:
|
||||
item = project.spreadsheet[idx]
|
||||
item = cells[idx]
|
||||
except IndexError:
|
||||
pass
|
||||
else:
|
||||
if self.direction == 'DOWN' and idx < len(project.spreadsheet) - 1:
|
||||
item_next = project.spreadsheet[idx+1].name
|
||||
project.spreadsheet.move(idx, idx+1)
|
||||
project.spreadsheet_index += 1
|
||||
if self.direction == 'DOWN' and idx < len(cells) - 1:
|
||||
item_next = cells[idx+1].name
|
||||
cells.move(idx, idx+1)
|
||||
spreadsheet.cell_index += 1
|
||||
|
||||
elif self.direction == 'UP' and idx >= 1:
|
||||
item_prev = project.spreadsheet[idx-1].name
|
||||
project.spreadsheet.move(idx, idx-1)
|
||||
project.spreadsheet_index -= 1
|
||||
item_prev = cells[idx-1].name
|
||||
cells.move(idx, idx-1)
|
||||
spreadsheet.cell_index -= 1
|
||||
|
||||
return {"FINISHED"}
|
||||
|
||||
|
@ -112,12 +113,13 @@ class VSETB_OT_export_spreadsheet(Operator):
|
|||
scn = context.scene
|
||||
settings = get_scene_settings()
|
||||
project = settings.active_project
|
||||
options = project.spreadsheet_options
|
||||
spreadsheet = project.spreadsheet_export
|
||||
#options = project.spreadsheet_options
|
||||
|
||||
layout = self.layout
|
||||
|
||||
row = layout.row()
|
||||
row.template_list("VSETB_UL_spreadsheet", "spreadsheet", project, "spreadsheet", project, "spreadsheet_index", rows=8)
|
||||
row.template_list("VSETB_UL_spreadsheet", "spreadsheet_export", spreadsheet, "cells", spreadsheet, "cell_index", rows=8)
|
||||
|
||||
col_tool = row.column(align=True)
|
||||
|
||||
|
@ -137,31 +139,31 @@ class VSETB_OT_export_spreadsheet(Operator):
|
|||
|
||||
row = col.row(align=True, heading='Custom Name')
|
||||
#row.use_property_split = True
|
||||
row.prop(options, 'use_custom_name', text='')
|
||||
row.prop(spreadsheet, 'use_custom_name', text='')
|
||||
sub = row.row(align=True)
|
||||
sub.enabled = options.use_custom_name
|
||||
sub.prop(options, 'custom_name', text='')
|
||||
sub.enabled = spreadsheet.use_custom_name
|
||||
sub.prop(spreadsheet, 'custom_name', text='')
|
||||
|
||||
col.separator()
|
||||
|
||||
row = col.row(align=False)
|
||||
row.prop(options, "format", expand=True, text='Format')
|
||||
row.prop(options, 'show_settings', text='', icon='PREFERENCES')
|
||||
if options.show_settings:
|
||||
col.prop(options, "separator", expand=True, text='Separator')
|
||||
if options.format == 'CSV':
|
||||
col.prop(options, "delimiter", expand=True, text='Delimiter')
|
||||
row.prop(spreadsheet, "format", expand=True, text='Format')
|
||||
row.prop(spreadsheet, 'show_settings', text='', icon='PREFERENCES')
|
||||
if spreadsheet.show_settings:
|
||||
col.prop(spreadsheet, "separator", expand=True, text='Separator')
|
||||
if spreadsheet.format == 'CSV':
|
||||
col.prop(spreadsheet, "delimiter", expand=True, text='Delimiter')
|
||||
|
||||
col.separator()
|
||||
col.prop(options, 'open_folder', text='Open Folder')
|
||||
col.prop(options, 'export_path', text='Export Path')
|
||||
col.prop(spreadsheet, 'open_folder', text='Open Folder')
|
||||
col.prop(spreadsheet, 'export_path', text='Export Path')
|
||||
|
||||
def execute(self, context):
|
||||
#self.report({'ERROR'}, f'Export not implemented yet.')
|
||||
prefs = get_addon_prefs()
|
||||
settings = get_scene_settings()
|
||||
project = settings.active_project
|
||||
options = project.spreadsheet_options
|
||||
spreadsheet = project.spreadsheet_export
|
||||
episode = settings.active_episode
|
||||
|
||||
cells = [cell for cell in project.spreadsheet if cell.enabled]
|
||||
|
@ -170,8 +172,8 @@ class VSETB_OT_export_spreadsheet(Operator):
|
|||
# Header
|
||||
rows.append([cell.export_name for cell in cells])
|
||||
|
||||
separator = options.separator.replace('\\n', '\n').replace('\\t', '\t').replace('\\r', '\r')
|
||||
delimiter = options.delimiter.replace('\\n', '\n').replace('\\t', '\t').replace('\\r', '\r')
|
||||
separator = spreadsheet.separator.replace('\\n', '\n').replace('\\t', '\t').replace('\\r', '\r')
|
||||
delimiter = spreadsheet.delimiter.replace('\\n', '\n').replace('\\t', '\t').replace('\\r', '\r')
|
||||
|
||||
for strip in get_strips('Shots'):
|
||||
row = []
|
||||
|
@ -185,11 +187,11 @@ class VSETB_OT_export_spreadsheet(Operator):
|
|||
if not asset.asset_type == cell.name:
|
||||
continue
|
||||
|
||||
if options.use_custom_name:
|
||||
if asset.get('metadata', {}).get(options.custom_name):
|
||||
asset_castings.append(asset['metadata'][options.custom_name])
|
||||
if spreadsheet.use_custom_name:
|
||||
if asset.get('metadata', {}).get(spreadsheet.custom_name):
|
||||
asset_castings.append(asset['metadata'][spreadsheet.custom_name])
|
||||
else:
|
||||
self.report({'ERROR'}, f'The asset {asset.tracker_name} has no data {options.custom_name}')
|
||||
self.report({'ERROR'}, f'The asset {asset.tracker_name} has no data {spreadsheet.custom_name}')
|
||||
else:
|
||||
asset_castings.append(asset.tracker_name)
|
||||
|
||||
|
@ -209,7 +211,7 @@ class VSETB_OT_export_spreadsheet(Operator):
|
|||
|
||||
#print(rows)
|
||||
|
||||
export_path = Path(os.path.abspath(bpy.path.abspath(options.export_path)))
|
||||
export_path = Path(os.path.abspath(bpy.path.abspath(spreadsheet.export_path)))
|
||||
export_name = export_path.name
|
||||
|
||||
if export_path.suffix or export_name.endswith('{ext}'):
|
||||
|
@ -224,7 +226,7 @@ class VSETB_OT_export_spreadsheet(Operator):
|
|||
date = datetime.now().strftime('%Y_%m_%d')
|
||||
project_name = project.name.replace(' ', '_').lower()
|
||||
episode_name = episode.name.replace(' ', '_').lower() if episode else 'episode'
|
||||
ext = options.format.lower()
|
||||
ext = spreadsheet.format.lower()
|
||||
|
||||
export_name = export_name.format(date=date, project=project_name,
|
||||
episode=episode_name, tracker=settings.tracker_name.lower(), ext=ext)
|
||||
|
@ -234,14 +236,14 @@ class VSETB_OT_export_spreadsheet(Operator):
|
|||
#2023_04_11_kitsu_boris_ep01_shots
|
||||
export_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
if options.format == 'CSV':
|
||||
if spreadsheet.format == 'CSV':
|
||||
print('Writing .csv file to', export_path)
|
||||
with open(str(export_path), 'w', newline='\n', encoding='utf-8') as f:
|
||||
writer = csv.writer(f, delimiter=options.delimiter)
|
||||
writer = csv.writer(f, delimiter=spreadsheet.delimiter)
|
||||
for row in rows:
|
||||
writer.writerow(row)
|
||||
|
||||
elif options.format == 'XLSX':
|
||||
elif spreadsheet.format == 'XLSX':
|
||||
try:
|
||||
import openpyxl
|
||||
except ModuleNotFoundError:
|
||||
|
@ -262,7 +264,7 @@ class VSETB_OT_export_spreadsheet(Operator):
|
|||
# Save the file
|
||||
workbook.save(str(export_path))
|
||||
|
||||
if options.open_folder:
|
||||
if spreadsheet.open_folder:
|
||||
open_file(export_path, select=True)
|
||||
|
||||
return {"FINISHED"}
|
||||
|
@ -304,9 +306,9 @@ class VSETB_OT_import_spreadsheet(Operator):
|
|||
|
||||
|
||||
classes = (
|
||||
VSETB_OT_add_spreadsheet_preset,
|
||||
VSETB_MT_spreadsheet_presets,
|
||||
VSETB_OT_spreadsheet_move,
|
||||
VSETB_OT_add_export_spreadsheet_preset,
|
||||
VSETB_MT_export_spreadsheet_presets,
|
||||
VSETB_OT_spreadsheet_cell_move,
|
||||
VSETB_OT_export_spreadsheet,
|
||||
)
|
||||
|
||||
|
|
|
@ -3,9 +3,9 @@
|
|||
from vse_toolbox.ui import (panels, preferences, properties)
|
||||
|
||||
modules = (
|
||||
panels,
|
||||
properties,
|
||||
preferences,
|
||||
properties
|
||||
panels
|
||||
)
|
||||
|
||||
if 'bpy' in locals():
|
||||
|
|
|
@ -95,7 +95,7 @@ class Trackers(PropertyGroup):
|
|||
|
||||
|
||||
class VSETB_Prefs(AddonPreferences):
|
||||
bl_idname = __package__
|
||||
bl_idname = 'vse_toolbox'
|
||||
|
||||
trackers : PointerProperty(type=Trackers)
|
||||
expand_settings: BoolProperty(default=False)
|
||||
|
|
|
@ -172,7 +172,7 @@ def get_custom_name_items(self, context):
|
|||
project = settings.active_project
|
||||
return [(m.field_name, m.name, '') for m in project.metadata_types if m.entity_type=='ASSET']
|
||||
|
||||
class SpreadsheetImport(PropertyGroup):
|
||||
class SpreadsheetExport(PropertyGroup):
|
||||
format : EnumProperty(items=[(i, i, '') for i in ('CSV', 'XLSX')])
|
||||
separator : StringProperty(default='\\n')
|
||||
delimiter : StringProperty(default=';')
|
||||
|
@ -187,6 +187,18 @@ class SpreadsheetImport(PropertyGroup):
|
|||
cell_index : IntProperty(name='Spreadsheet Index', default=0)
|
||||
|
||||
|
||||
class SpreadsheetImport(PropertyGroup):
|
||||
separator : StringProperty(default='\\n')
|
||||
delimiter : StringProperty(default=';')
|
||||
use_custom_name : BoolProperty(default=False)
|
||||
custom_name : EnumProperty(items=get_custom_name_items,
|
||||
description='Use a custom name for asset using a metadata value')
|
||||
|
||||
show_settings : BoolProperty(default=False)
|
||||
cells: CollectionProperty(type=SpreadsheetCell)
|
||||
cell_index : IntProperty(name='Spreadsheet Index', default=0)
|
||||
|
||||
|
||||
class Project(PropertyGroup):
|
||||
id : StringProperty(default='')
|
||||
|
||||
|
@ -225,18 +237,20 @@ class Project(PropertyGroup):
|
|||
task_types : CollectionProperty(type=TaskType)
|
||||
task_statuses : CollectionProperty(type=TaskStatus)
|
||||
|
||||
spreadsheet_import: PointerProperty(type=Spreadsheet)
|
||||
spreadsheet_export: PointerProperty(type=Spreadsheet)
|
||||
spreadsheet_import: PointerProperty(type=SpreadsheetImport)
|
||||
spreadsheet_export: PointerProperty(type=SpreadsheetExport)
|
||||
|
||||
type : StringProperty()
|
||||
|
||||
def set_spreadsheet(self):
|
||||
spreadsheet = self.spreadsheet_export
|
||||
|
||||
cell_names = ['Sequence', 'Shot', 'Frames', 'Description']
|
||||
if self.type == 'TVSHOW':
|
||||
cell_names.insert(0, 'Episode')
|
||||
|
||||
for cell_name in cell_names:
|
||||
cell = self.spreadsheet.add()
|
||||
cell = spreadsheet.cells.add()
|
||||
cell.name = cell_name
|
||||
cell.export_name = 'Name' if cell_name == 'Shot' else cell_name
|
||||
cell.field_name = cell_name.upper()
|
||||
|
@ -245,14 +259,14 @@ class Project(PropertyGroup):
|
|||
for metadata_type in self.metadata_types:
|
||||
if not metadata_type['entity_type'] == "SHOT":
|
||||
continue
|
||||
cell = self.spreadsheet.add()
|
||||
cell = spreadsheet.cells.add()
|
||||
cell.name = metadata_type.name
|
||||
cell.export_name = metadata_type.name
|
||||
cell.field_name = metadata_type.field_name
|
||||
cell.type = "METADATA"
|
||||
|
||||
for asset_type in self.asset_types:
|
||||
cell = self.spreadsheet.add()
|
||||
cell = spreadsheet.cells.add()
|
||||
cell.name = asset_type.name
|
||||
cell.export_name = asset_type.name
|
||||
cell.field_name = asset_type.name.upper()
|
||||
|
@ -434,7 +448,8 @@ classes = (
|
|||
Metadata,
|
||||
MetadataType,
|
||||
TaskType,
|
||||
Spreadsheet,
|
||||
SpreadsheetImport,
|
||||
SpreadsheetExport,
|
||||
Project,
|
||||
VSETB_UL_spreadsheet,
|
||||
VSETB_UL_casting,
|
||||
|
|
Loading…
Reference in New Issue