fix namespace pref lists and add a reset button

2.1.3

- fixed: decoralate Prefix and Suffix UI_lists scroll
- fixed: Problem when settings project namespaces
- added: Button to reset project namespace (to have the right order)
This commit is contained in:
pullusb
2022-11-30 17:58:12 +01:00
parent b2a6e6a899
commit b370dd7344
4 changed files with 104 additions and 39 deletions
+27 -16
View File
@@ -4,7 +4,7 @@ bl_info = {
"name": "GP toolbox",
"description": "Tool set for Grease Pencil in animation production",
"author": "Samuel Bernou, Christophe Seux",
"version": (2, 1, 2),
"version": (2, 1, 3),
"blender": (3, 0, 0),
"location": "Sidebar (N menu) > Gpencil > Toolbox / Gpencil properties",
"warning": "",
@@ -363,12 +363,12 @@ class GPTB_prefs(bpy.types.AddonPreferences):
# description = "Auto assign shortcut for temp_cutter",
# default = True)
def draw_namespaces_list(self, layout, pg_name, rows=4):
def draw_namespaces_list(self, layout, template_list, pg_name, rows=4):
'''Get layout, property group to draw and default row number'''
pg = getattr(self, pg_name)
row = layout.row(align=True)
row.template_list("GPTB_UL_namespace_list", "", pg, "namespaces", pg, "idx", rows=rows)
row.template_list(template_list, "", pg, "namespaces", pg, "idx", rows=rows)
subcol = row.column(align=True) # Lateral right
subcol.operator("gptb.add_namespace_entry", icon="ADD", text="").propname=pg_name
subcol.operator("gptb.remove_namespace_entry", icon="REMOVE", text="").propname=pg_name
@@ -428,10 +428,14 @@ class GPTB_prefs(bpy.types.AddonPreferences):
subbox = box.box()
subbox.label(text='Namespace:')
subbox.prop(self, 'separator')
subbox.prop(self, 'show_prefix_buttons', text='Use Prefixes Toggles')
subrow = subbox.row()
subrow.prop(self, 'show_prefix_buttons', text='Use Prefixes Toggles')
if self.show_prefix_buttons:
# subbox.prop(self, 'use_env_namespace')
rowrow = subrow.row()
# Reset Names From Projects
rowrow.alignment = 'RIGHT'
rowrow.operator('gptb.reset_project_namespaces', text='', icon='BRUSH_DATA')
"""
row = subbox.row()
row.prop(self, 'prefixes')
@@ -440,10 +444,11 @@ class GPTB_prefs(bpy.types.AddonPreferences):
row.prop(self, 'suffixes')
row.operator('prefs.reset_gp_toolbox_env', text='', icon='LOOP_BACK').mode = 'SUFFIXES'
"""
## Collection UI list version
self.draw_namespaces_list(subbox, 'prefixes', rows=4)
self.draw_namespaces_list(subbox, 'GPTB_UL_namespace_list', 'prefixes', rows=4)
subbox.separator()
self.draw_namespaces_list(subbox, 'suffixes', rows=4)
self.draw_namespaces_list(subbox, 'GPTB_UL_namespace_list_suffix', 'suffixes', rows=2)
### TODO add render settings
@@ -656,27 +661,34 @@ class GPTB_prefs(bpy.types.AddonPreferences):
def set_namespace_env(name_env, prop_group):
tag_list = os.getenv(name_env)
current_pfix = []
if tag_list:
tag_list = tag_list.strip(',').split(',')
project_pfix = []
if tag_list and tag_list.strip():
## Force clear (clear also hide): prop_group.namespaces.clear()
## Get current tag list
tag_list = tag_list.strip(', ').split(',')
current_pfix = [n.tag for n in prop_group.namespaces if n.tag]
# for n in prop_group.namespaces:
# print(n.tag, n.name)
for p in tag_list:
tag = p.split(':')[0].strip()
project_pfix.append(tag)
name = '' if not ':' in p else p.split(':')[1].strip()
item = None
if tag not in current_pfix:
item = prop_group.namespaces.add()
item.tag = tag
item.name = name
item.is_project = True
print('Loaded project tag:', tag, name)
# print('Loaded project tag:', tag, name)
elif name:
# get the tag and apply name
item = [n for n in prop_group.namespaces if n.tag == tag][0]
if not item.name.strip():
item = next((n for n in prop_group.namespaces if n.tag == tag), None)
if item: # and not item.name.strip()
item.name = name
print('Loaded name:', name)
# print('Loaded name:', name)
if item:
item.is_project = True
@@ -686,8 +698,7 @@ def set_namespace_env(name_env, prop_group):
# "release" suffix that are not in project anymore
for n in prop_group.namespaces:
if n.tag not in current_pfix:
n.is_project = False
n.is_project = n.tag in project_pfix
def set_env_properties():