2023-03-14 13:38:04 +01:00
|
|
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
|
|
|
import bpy
|
|
|
|
import inspect
|
|
|
|
import os
|
|
|
|
|
|
|
|
from bpy.props import (
|
|
|
|
BoolProperty,
|
|
|
|
EnumProperty,
|
|
|
|
FloatProperty,
|
|
|
|
IntProperty,
|
|
|
|
PointerProperty,
|
|
|
|
StringProperty,
|
|
|
|
)
|
|
|
|
|
|
|
|
from bpy.types import (
|
|
|
|
AddonPreferences,
|
|
|
|
PropertyGroup,
|
|
|
|
)
|
2023-03-21 18:33:29 +01:00
|
|
|
from vse_toolbox.bl_utils import get_addon_prefs, get_scene_settings
|
2023-03-14 13:38:04 +01:00
|
|
|
from vse_toolbox.constants import (
|
|
|
|
TRACKERS,
|
|
|
|
TRACKERS_DIR,
|
|
|
|
)
|
|
|
|
from vse_toolbox.file_utils import (
|
|
|
|
import_module_from_path,
|
|
|
|
norm_str,
|
|
|
|
read_file,
|
|
|
|
)
|
|
|
|
from vse_toolbox.resources.trackers.kitsu import Kitsu
|
|
|
|
|
|
|
|
def load_trackers():
|
|
|
|
from vse_toolbox.resources.trackers.tracker import Tracker
|
|
|
|
|
|
|
|
TRACKERS.clear()
|
|
|
|
tracker_files = list(TRACKERS_DIR.glob('*.py'))
|
|
|
|
|
|
|
|
for tracker_file in tracker_files:
|
|
|
|
if tracker_file.stem.startswith('_'):
|
|
|
|
continue
|
|
|
|
|
|
|
|
mod = import_module_from_path(tracker_file)
|
|
|
|
for name, obj in inspect.getmembers(mod):
|
|
|
|
|
|
|
|
if not inspect.isclass(obj):
|
|
|
|
continue
|
|
|
|
|
|
|
|
if not Tracker in obj.__mro__:
|
|
|
|
continue
|
|
|
|
|
|
|
|
if obj is Tracker or obj.name in (a.name for a in TRACKERS):
|
|
|
|
continue
|
|
|
|
|
|
|
|
try:
|
|
|
|
print(f'Register Plugin {name}')
|
|
|
|
bpy.utils.register_class(obj)
|
|
|
|
setattr(Trackers, norm_str(obj.name), PointerProperty(type=obj))
|
|
|
|
TRACKERS.append(obj)
|
|
|
|
except Exception as e:
|
|
|
|
print(f'Could not register library_type {name}')
|
|
|
|
print(e)
|
|
|
|
|
2023-03-21 18:33:29 +01:00
|
|
|
def load_tracker_prefs():
|
|
|
|
prefs = get_addon_prefs()
|
|
|
|
tracker_prefs_file = os.getenv('TRACKER_PREFS')
|
|
|
|
|
|
|
|
if not tracker_prefs_file:
|
|
|
|
return
|
|
|
|
|
|
|
|
tracker_datas = read_file(os.path.expandvars(tracker_prefs_file))
|
|
|
|
|
|
|
|
for tracker_data in tracker_datas:
|
|
|
|
tracker_name = norm_str(tracker_data['name'])
|
|
|
|
if not hasattr(prefs.trackers, tracker_name):
|
|
|
|
continue
|
|
|
|
|
|
|
|
tracker_pref = getattr(prefs.trackers, tracker_name)
|
|
|
|
|
|
|
|
if not tracker_pref:
|
|
|
|
continue
|
|
|
|
|
|
|
|
for k, v in tracker_data.items():
|
|
|
|
if k in ('name',):
|
|
|
|
continue
|
|
|
|
setattr(tracker_pref, k, os.path.expandvars(v))
|
|
|
|
|
2023-03-14 13:38:04 +01:00
|
|
|
|
|
|
|
class Trackers(PropertyGroup):
|
|
|
|
def __iter__(self):
|
|
|
|
return (getattr(self, p) for p in self.bl_rna.properties.keys() if p not in ('rna_type', 'name'))
|
|
|
|
|
|
|
|
|
|
|
|
class VSETB_Prefs(AddonPreferences):
|
|
|
|
bl_idname = __package__
|
|
|
|
|
|
|
|
trackers : PointerProperty(type=Trackers)
|
|
|
|
expand_settings: BoolProperty(default=False)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def tracker(self):
|
2023-03-21 18:33:29 +01:00
|
|
|
return getattr(self.trackers, norm_str(get_scene_settings().tracker_name))
|
2023-03-14 13:38:04 +01:00
|
|
|
|
|
|
|
def draw(self, context):
|
|
|
|
prefs = get_addon_prefs()
|
2023-03-21 18:33:29 +01:00
|
|
|
settings = get_scene_settings()
|
2023-03-14 13:38:04 +01:00
|
|
|
|
|
|
|
layout = self.layout
|
|
|
|
|
|
|
|
col = layout.column(align=True)
|
|
|
|
box = col.box()
|
|
|
|
row = box.row(align=True)
|
|
|
|
icon = "DISCLOSURE_TRI_DOWN" if self.expand_settings else "DISCLOSURE_TRI_RIGHT"
|
|
|
|
row.prop(self, 'expand_settings', icon=icon, emboss=False, text='')
|
|
|
|
row.label(icon='PREFERENCES')
|
|
|
|
row.label(text='Settings')
|
|
|
|
subrow = row.row()
|
|
|
|
subrow.alignment = 'RIGHT'
|
|
|
|
subrow.operator("vse_toolbox.reload_addon", text='Reload Addon')
|
|
|
|
|
|
|
|
if self.expand_settings:
|
|
|
|
box.prop(settings, 'tracker_name', text='Tracker')
|
|
|
|
self.tracker.draw_prefs(box)
|
|
|
|
|
|
|
|
|
|
|
|
classes=[
|
|
|
|
Trackers,
|
|
|
|
VSETB_Prefs,
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
def register():
|
|
|
|
for cls in classes:
|
|
|
|
bpy.utils.register_class(cls)
|
|
|
|
|
|
|
|
load_trackers()
|
|
|
|
prefs = get_addon_prefs()
|
|
|
|
|
|
|
|
tracker_name = os.getenv('TRACKER_NAME')
|
2023-03-21 18:33:29 +01:00
|
|
|
if tracker_name is not None:
|
2023-03-14 13:38:04 +01:00
|
|
|
prefs['tracker_name'] = os.path.expandvars(norm_str(tracker_name, format=str.upper))
|
2023-03-21 18:33:29 +01:00
|
|
|
|
|
|
|
load_tracker_prefs()
|
2023-03-14 13:38:04 +01:00
|
|
|
|
|
|
|
def unregister():
|
|
|
|
for cls in reversed(classes + TRACKERS):
|
|
|
|
bpy.utils.unregister_class(cls)
|
|
|
|
|
|
|
|
TRACKERS.clear()
|