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)gpv2
parent
b2a6e6a899
commit
b370dd7344
|
@ -1,5 +1,12 @@
|
||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
2.1.2
|
2.1.2
|
||||||
|
|
||||||
- added: `gp.brush_set` operator to manually assign a brush by name to a shortcut
|
- added: `gp.brush_set` operator to manually assign a brush by name to a shortcut
|
||||||
|
|
|
@ -1,8 +1,45 @@
|
||||||
|
|
||||||
import bpy
|
import bpy
|
||||||
|
import os
|
||||||
import re
|
import re
|
||||||
from .utils import get_addon_prefs
|
from .utils import get_addon_prefs
|
||||||
from .functions import redraw_ui
|
from .functions import redraw_ui
|
||||||
|
from .__init__ import set_namespace_env
|
||||||
|
|
||||||
|
|
||||||
|
class GPTB_OT_reset_project_namespaces(bpy.types.Operator):
|
||||||
|
bl_idname = "gptb.reset_project_namespaces"
|
||||||
|
bl_label = "Reload Project Names"
|
||||||
|
bl_description = "Reset projects namespaced from environnement variable"
|
||||||
|
bl_options = {'REGISTER', 'INTERNAL'}
|
||||||
|
|
||||||
|
def execute(self, context):
|
||||||
|
prefs = get_addon_prefs()
|
||||||
|
prefix_list = os.getenv('PREFIXES')
|
||||||
|
suffix_list = os.getenv('SUFFIXES')
|
||||||
|
if not prefix_list and not suffix_list:
|
||||||
|
self.report({'WARNING'}, "No name list in env (variables: 'PREFIXES','SUFFIXES')")
|
||||||
|
return {'CANCELLED'}
|
||||||
|
|
||||||
|
for propname in ('prefixes', 'suffixes'):
|
||||||
|
pg = getattr(prefs, propname)
|
||||||
|
uilist = pg.namespaces
|
||||||
|
uilist.clear()
|
||||||
|
|
||||||
|
missing = []
|
||||||
|
if prefix_list:
|
||||||
|
set_namespace_env('PREFIXES', prefs.prefixes)
|
||||||
|
else:
|
||||||
|
missing.append('prefixes')
|
||||||
|
|
||||||
|
if suffix_list:
|
||||||
|
set_namespace_env('SUFFIXES', prefs.suffixes)
|
||||||
|
else:
|
||||||
|
missing.append('suffixes')
|
||||||
|
|
||||||
|
if missing:
|
||||||
|
self.report({'WARNING'}, f'No {" and ".join(missing)} presets to load from project env')
|
||||||
|
return {'FINISHED'}
|
||||||
|
|
||||||
class GPTB_OT_add_namespace_entry(bpy.types.Operator):
|
class GPTB_OT_add_namespace_entry(bpy.types.Operator):
|
||||||
bl_idname = "gptb.add_namespace_entry"
|
bl_idname = "gptb.add_namespace_entry"
|
||||||
|
@ -112,12 +149,8 @@ class GPTB_OT_move_item(bpy.types.Operator):
|
||||||
redraw_ui()
|
redraw_ui()
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
class GPTB_UL_namespace_list(bpy.types.UIList):
|
|
||||||
|
|
||||||
# show_desc : BoolProperty(name="Show Description", default=True,
|
def draw_namespace_item(self, context, layout, data, item, icon, active_data, active_propname):
|
||||||
# description="Display Description")
|
|
||||||
|
|
||||||
def draw_item(self, context, layout, data, item, icon, active_data, active_propname):
|
|
||||||
# self.use_filter_show = True # force open/close the search feature
|
# self.use_filter_show = True # force open/close the search feature
|
||||||
# prefs = get_addon_prefs()
|
# prefs = get_addon_prefs()
|
||||||
# split = layout.split(align=False, factor=0.3)
|
# split = layout.split(align=False, factor=0.3)
|
||||||
|
@ -140,12 +173,27 @@ class GPTB_UL_namespace_list(bpy.types.UIList):
|
||||||
# row.label(text=item.description)
|
# row.label(text=item.description)
|
||||||
# row.operator('sbam.open_online_repo', text='', icon='URL')
|
# row.operator('sbam.open_online_repo', text='', icon='URL')
|
||||||
|
|
||||||
|
class GPTB_UL_namespace_list(bpy.types.UIList):
|
||||||
|
|
||||||
|
def draw_item(self, context, layout, data, item, icon, active_data, active_propname):
|
||||||
|
draw_namespace_item(self, context, layout, data, item, icon, active_data, active_propname)
|
||||||
|
|
||||||
|
## Need to duplicate UL as a separate class for suffixes\
|
||||||
|
## otherwise displayed row in UI are synchronised
|
||||||
|
class GPTB_UL_namespace_list_suffix(bpy.types.UIList):
|
||||||
|
|
||||||
|
def draw_item(self, context, layout, data, item, icon, active_data, active_propname):
|
||||||
|
draw_namespace_item(self, context, layout, data, item, icon, active_data, active_propname)
|
||||||
|
|
||||||
|
|
||||||
classes = (
|
classes = (
|
||||||
## layer name management
|
## layer name management
|
||||||
|
GPTB_OT_reset_project_namespaces,
|
||||||
GPTB_OT_add_namespace_entry,
|
GPTB_OT_add_namespace_entry,
|
||||||
GPTB_OT_remove_namespace_entry,
|
GPTB_OT_remove_namespace_entry,
|
||||||
GPTB_OT_move_item,
|
GPTB_OT_move_item,
|
||||||
GPTB_UL_namespace_list,
|
GPTB_UL_namespace_list,
|
||||||
|
GPTB_UL_namespace_list_suffix,
|
||||||
)
|
)
|
||||||
|
|
||||||
def register():
|
def register():
|
||||||
|
|
43
__init__.py
43
__init__.py
|
@ -4,7 +4,7 @@ bl_info = {
|
||||||
"name": "GP toolbox",
|
"name": "GP toolbox",
|
||||||
"description": "Tool set for Grease Pencil in animation production",
|
"description": "Tool set for Grease Pencil in animation production",
|
||||||
"author": "Samuel Bernou, Christophe Seux",
|
"author": "Samuel Bernou, Christophe Seux",
|
||||||
"version": (2, 1, 2),
|
"version": (2, 1, 3),
|
||||||
"blender": (3, 0, 0),
|
"blender": (3, 0, 0),
|
||||||
"location": "Sidebar (N menu) > Gpencil > Toolbox / Gpencil properties",
|
"location": "Sidebar (N menu) > Gpencil > Toolbox / Gpencil properties",
|
||||||
"warning": "",
|
"warning": "",
|
||||||
|
@ -363,12 +363,12 @@ class GPTB_prefs(bpy.types.AddonPreferences):
|
||||||
# description = "Auto assign shortcut for temp_cutter",
|
# description = "Auto assign shortcut for temp_cutter",
|
||||||
# default = True)
|
# 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'''
|
'''Get layout, property group to draw and default row number'''
|
||||||
|
|
||||||
pg = getattr(self, pg_name)
|
pg = getattr(self, pg_name)
|
||||||
row = layout.row(align=True)
|
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 = row.column(align=True) # Lateral right
|
||||||
subcol.operator("gptb.add_namespace_entry", icon="ADD", text="").propname=pg_name
|
subcol.operator("gptb.add_namespace_entry", icon="ADD", text="").propname=pg_name
|
||||||
subcol.operator("gptb.remove_namespace_entry", icon="REMOVE", 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 = box.box()
|
||||||
subbox.label(text='Namespace:')
|
subbox.label(text='Namespace:')
|
||||||
subbox.prop(self, 'separator')
|
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:
|
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 = subbox.row()
|
||||||
row.prop(self, 'prefixes')
|
row.prop(self, 'prefixes')
|
||||||
|
@ -440,10 +444,11 @@ class GPTB_prefs(bpy.types.AddonPreferences):
|
||||||
row.prop(self, 'suffixes')
|
row.prop(self, 'suffixes')
|
||||||
row.operator('prefs.reset_gp_toolbox_env', text='', icon='LOOP_BACK').mode = 'SUFFIXES'
|
row.operator('prefs.reset_gp_toolbox_env', text='', icon='LOOP_BACK').mode = 'SUFFIXES'
|
||||||
"""
|
"""
|
||||||
|
|
||||||
## Collection UI list version
|
## 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()
|
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
|
### TODO add render settings
|
||||||
|
@ -656,27 +661,34 @@ class GPTB_prefs(bpy.types.AddonPreferences):
|
||||||
def set_namespace_env(name_env, prop_group):
|
def set_namespace_env(name_env, prop_group):
|
||||||
tag_list = os.getenv(name_env)
|
tag_list = os.getenv(name_env)
|
||||||
current_pfix = []
|
current_pfix = []
|
||||||
if tag_list:
|
project_pfix = []
|
||||||
tag_list = tag_list.strip(',').split(',')
|
|
||||||
|
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]
|
current_pfix = [n.tag for n in prop_group.namespaces if n.tag]
|
||||||
# for n in prop_group.namespaces:
|
# for n in prop_group.namespaces:
|
||||||
# print(n.tag, n.name)
|
# print(n.tag, n.name)
|
||||||
|
|
||||||
for p in tag_list:
|
for p in tag_list:
|
||||||
tag = p.split(':')[0].strip()
|
tag = p.split(':')[0].strip()
|
||||||
|
project_pfix.append(tag)
|
||||||
name = '' if not ':' in p else p.split(':')[1].strip()
|
name = '' if not ':' in p else p.split(':')[1].strip()
|
||||||
item = None
|
item = None
|
||||||
if tag not in current_pfix:
|
if tag not in current_pfix:
|
||||||
item = prop_group.namespaces.add()
|
item = prop_group.namespaces.add()
|
||||||
item.tag = tag
|
item.tag = tag
|
||||||
item.name = name
|
item.name = name
|
||||||
item.is_project = True
|
# print('Loaded project tag:', tag, name)
|
||||||
print('Loaded project tag:', tag, name)
|
|
||||||
elif name:
|
elif name:
|
||||||
# get the tag and apply name
|
# get the tag and apply name
|
||||||
item = [n for n in prop_group.namespaces if n.tag == tag][0]
|
item = next((n for n in prop_group.namespaces if n.tag == tag), None)
|
||||||
if not item.name.strip():
|
if item: # and not item.name.strip()
|
||||||
item.name = name
|
item.name = name
|
||||||
print('Loaded name:', name)
|
# print('Loaded name:', name)
|
||||||
|
|
||||||
if item:
|
if item:
|
||||||
item.is_project = True
|
item.is_project = True
|
||||||
|
@ -686,8 +698,7 @@ def set_namespace_env(name_env, prop_group):
|
||||||
|
|
||||||
# "release" suffix that are not in project anymore
|
# "release" suffix that are not in project anymore
|
||||||
for n in prop_group.namespaces:
|
for n in prop_group.namespaces:
|
||||||
if n.tag not in current_pfix:
|
n.is_project = n.tag in project_pfix
|
||||||
n.is_project = False
|
|
||||||
|
|
||||||
def set_env_properties():
|
def set_env_properties():
|
||||||
|
|
||||||
|
|
|
@ -243,7 +243,6 @@ class GP_PG_namespace_props(PropertyGroup):
|
||||||
|
|
||||||
class GP_PG_namespaces(PropertyGroup):
|
class GP_PG_namespaces(PropertyGroup):
|
||||||
idx : IntProperty(default=-1)
|
idx : IntProperty(default=-1)
|
||||||
|
|
||||||
namespaces : bpy.props.CollectionProperty(type=GP_PG_namespace_props)
|
namespaces : bpy.props.CollectionProperty(type=GP_PG_namespace_props)
|
||||||
|
|
||||||
classes = (
|
classes = (
|
||||||
|
|
Loading…
Reference in New Issue