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
|
||||
|
||||
|
||||
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
|
||||
|
||||
- added: `gp.brush_set` operator to manually assign a brush by name to a shortcut
|
||||
|
|
|
@ -1,8 +1,45 @@
|
|||
|
||||
import bpy
|
||||
import os
|
||||
import re
|
||||
from .utils import get_addon_prefs
|
||||
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):
|
||||
bl_idname = "gptb.add_namespace_entry"
|
||||
|
@ -112,40 +149,51 @@ class GPTB_OT_move_item(bpy.types.Operator):
|
|||
redraw_ui()
|
||||
return {'FINISHED'}
|
||||
|
||||
|
||||
def draw_namespace_item(self, context, layout, data, item, icon, active_data, active_propname):
|
||||
# self.use_filter_show = True # force open/close the search feature
|
||||
# prefs = get_addon_prefs()
|
||||
# split = layout.split(align=False, factor=0.3)
|
||||
row = layout.row()
|
||||
hide_ico = 'HIDE_ON' if item.hide else 'HIDE_OFF'
|
||||
source_ico = 'NETWORK_DRIVE' if item.is_project else 'USER' # BLANK1
|
||||
|
||||
row.label(text='', icon=source_ico)
|
||||
row.prop(item, 'hide', text='', icon=hide_ico, invert_checkbox=True)
|
||||
subrow = row.row(align=True)
|
||||
subrow.prop(item, 'tag', text='')
|
||||
subrow.prop(item, 'name', text='')
|
||||
subrow.enabled = not item.is_project
|
||||
|
||||
# row = layout.split(align=False)
|
||||
# row.label(text=item.prefix)
|
||||
# row.label(text=item.name)
|
||||
|
||||
# if self.show_desc:
|
||||
# row.label(text=item.description)
|
||||
# row.operator('sbam.open_online_repo', text='', icon='URL')
|
||||
|
||||
class GPTB_UL_namespace_list(bpy.types.UIList):
|
||||
|
||||
# show_desc : BoolProperty(name="Show Description", default=True,
|
||||
# description="Display Description")
|
||||
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):
|
||||
# self.use_filter_show = True # force open/close the search feature
|
||||
# prefs = get_addon_prefs()
|
||||
# split = layout.split(align=False, factor=0.3)
|
||||
row = layout.row()
|
||||
hide_ico = 'HIDE_ON' if item.hide else 'HIDE_OFF'
|
||||
source_ico = 'NETWORK_DRIVE' if item.is_project else 'USER' # BLANK1
|
||||
draw_namespace_item(self, context, layout, data, item, icon, active_data, active_propname)
|
||||
|
||||
row.label(text='', icon=source_ico)
|
||||
row.prop(item, 'hide', text='', icon=hide_ico, invert_checkbox=True)
|
||||
subrow = row.row(align=True)
|
||||
subrow.prop(item, 'tag', text='')
|
||||
subrow.prop(item, 'name', text='')
|
||||
subrow.enabled = not item.is_project
|
||||
|
||||
# row = layout.split(align=False)
|
||||
# row.label(text=item.prefix)
|
||||
# row.label(text=item.name)
|
||||
|
||||
# if self.show_desc:
|
||||
# row.label(text=item.description)
|
||||
# row.operator('sbam.open_online_repo', text='', icon='URL')
|
||||
|
||||
classes = (
|
||||
## layer name management
|
||||
GPTB_OT_reset_project_namespaces,
|
||||
GPTB_OT_add_namespace_entry,
|
||||
GPTB_OT_remove_namespace_entry,
|
||||
GPTB_OT_move_item,
|
||||
GPTB_UL_namespace_list,
|
||||
GPTB_UL_namespace_list_suffix,
|
||||
)
|
||||
|
||||
def register():
|
||||
|
|
43
__init__.py
43
__init__.py
|
@ -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():
|
||||
|
||||
|
|
|
@ -243,7 +243,6 @@ class GP_PG_namespace_props(PropertyGroup):
|
|||
|
||||
class GP_PG_namespaces(PropertyGroup):
|
||||
idx : IntProperty(default=-1)
|
||||
|
||||
namespaces : bpy.props.CollectionProperty(type=GP_PG_namespace_props)
|
||||
|
||||
classes = (
|
||||
|
|
Loading…
Reference in New Issue