Make all features working
This commit is contained in:
@@ -28,6 +28,10 @@ class attr_set():
|
||||
for item in attrib_list:
|
||||
prop, attr = item[:2]
|
||||
self.store.append( (prop, attr, getattr(prop, attr)) )
|
||||
|
||||
for item in attrib_list:
|
||||
prop, attr = item[:2]
|
||||
|
||||
if len(item) >= 3:
|
||||
try:
|
||||
setattr(prop, attr, item[2])
|
||||
@@ -38,6 +42,9 @@ class attr_set():
|
||||
return self
|
||||
|
||||
def __exit__(self, exc_type, exc_value, exc_traceback):
|
||||
self.restore()
|
||||
|
||||
def restore(self):
|
||||
for prop, attr, old_val in self.store:
|
||||
setattr(prop, attr, old_val)
|
||||
|
||||
@@ -55,6 +62,15 @@ def get_view3d_persp():
|
||||
view_3d = next((a for a in view_3ds if a.spaces.active.region_3d.view_perspective == 'PERSP'), view_3ds[0])
|
||||
return view_3d
|
||||
|
||||
def get_viewport():
|
||||
screen = bpy.context.screen
|
||||
|
||||
areas = [a for a in screen.areas if a.type == 'VIEW_3D']
|
||||
areas.sort(key=lambda x : x.width*x.height)
|
||||
|
||||
return areas[-1]
|
||||
|
||||
|
||||
def biggest_asset_browser_area(screen: bpy.types.Screen) -> Optional[bpy.types.Area]:
|
||||
"""Return the asset browser Area that's largest on screen.
|
||||
|
||||
|
||||
+3
-3
@@ -52,14 +52,14 @@ def asset_warning_callback(self, context):
|
||||
return
|
||||
|
||||
lib = get_active_library()
|
||||
action_path = lib.adapter.get_asset_relative_path(self.name, self.catalog)
|
||||
action_path = lib.library_type.get_asset_relative_path(self.name, self.catalog)
|
||||
self.path = action_path.as_posix()
|
||||
|
||||
if lib.merge_libraries:
|
||||
prefs = get_addon_prefs()
|
||||
lib = prefs.libraries[lib.store_library]
|
||||
|
||||
if not lib.adapter.get_asset_path(self.name, self.catalog).parents[1].exists():
|
||||
if not lib.library_type.get_asset_path(self.name, self.catalog).parents[1].exists():
|
||||
self.warning = 'A new folder will be created'
|
||||
|
||||
def get_active_library():
|
||||
@@ -76,7 +76,7 @@ def get_active_catalog():
|
||||
'''Get the active catalog path'''
|
||||
|
||||
lib = get_active_library()
|
||||
cat_data = lib.adapter.read_catalog()
|
||||
cat_data = lib.library_type.read_catalog()
|
||||
cat_data = {v['id']:k for k,v in cat_data.items()}
|
||||
|
||||
cat_id = bpy.context.space_data.params.catalog_id
|
||||
|
||||
+35
-2
@@ -3,8 +3,28 @@ import os
|
||||
from pathlib import Path
|
||||
from fnmatch import fnmatch
|
||||
from glob import glob
|
||||
import string
|
||||
|
||||
|
||||
class TemplateFormatter(string.Formatter):
|
||||
def format_field(self, value, format_spec):
|
||||
if isinstance(value, str):
|
||||
spec, sep = [*format_spec.split(':'), None][:2]
|
||||
|
||||
if sep:
|
||||
value = value.replace('_', ' ')
|
||||
value = value = re.sub(r'([a-z])([A-Z])', rf'\1{sep}\2', value)
|
||||
value = value.replace(' ', sep)
|
||||
|
||||
if spec == 'u':
|
||||
value = value.upper()
|
||||
elif spec == 'l':
|
||||
value = value.lower()
|
||||
elif spec == 't':
|
||||
value = value.title()
|
||||
|
||||
return super().format(value, format_spec)
|
||||
|
||||
class Template:
|
||||
field_pattern = re.compile(r'{(\w+)\*{0,2}}')
|
||||
field_pattern_recursive = re.compile(r'{(\w+)\*{2}}')
|
||||
@@ -13,6 +33,7 @@ class Template:
|
||||
#asset_data_path = Path(lib_path) / ASSETLIB_FILENAME
|
||||
|
||||
self.raw = template
|
||||
self.formatter = TemplateFormatter()
|
||||
|
||||
@property
|
||||
def glob_pattern(self):
|
||||
@@ -52,12 +73,24 @@ class Template:
|
||||
|
||||
return {k:v for k,v in zip(fields, field_values)}
|
||||
|
||||
def norm_data(self, data):
|
||||
norm_data = {}
|
||||
for k, v in data.items():
|
||||
|
||||
if isinstance(v, Path):
|
||||
v = v.as_posix()
|
||||
|
||||
norm_data[k] = v
|
||||
|
||||
return norm_data
|
||||
|
||||
def format(self, data=None, **kargs):
|
||||
|
||||
data = {**(data or {}), **kargs}
|
||||
|
||||
try:
|
||||
path = self.raw.format(**data)
|
||||
#print('FORMAT', self.raw, data)
|
||||
path = self.formatter.format(self.raw, **self.norm_data(data))
|
||||
except KeyError as e:
|
||||
print(f'Cannot format {self.raw} with {data}, field {e} is missing')
|
||||
return
|
||||
@@ -88,7 +121,7 @@ class Template:
|
||||
if paths:
|
||||
return Path(paths[0])
|
||||
|
||||
return pattern
|
||||
#return pattern
|
||||
|
||||
def __repr__(self):
|
||||
return f'Template({self.raw})'
|
||||
Reference in New Issue
Block a user