Clean whitespaces
parent
652c4632a9
commit
d1748c592d
|
@ -31,9 +31,9 @@ def layer_name_build(layer, prefix='', desc='', suffix=''):
|
|||
prefs = get_addon_prefs()
|
||||
sep = prefs.separator
|
||||
name = old = layer.info
|
||||
|
||||
|
||||
pattern = PATTERN.replace('_', sep) # set separator
|
||||
|
||||
|
||||
res = re.search(pattern, name.strip())
|
||||
|
||||
# prefix -> tag
|
||||
|
@ -59,7 +59,7 @@ def layer_name_build(layer, prefix='', desc='', suffix=''):
|
|||
# tag2 = prefix2.upper().strip() + sep
|
||||
if desc:
|
||||
name = desc
|
||||
|
||||
|
||||
if suffix:
|
||||
if suffix == 'suffixkillcode':
|
||||
sfix = ''
|
||||
|
@ -70,13 +70,13 @@ def layer_name_build(layer, prefix='', desc='', suffix=''):
|
|||
new = f'{grp}{tag}{name}{sfix}'
|
||||
|
||||
layer.info = new
|
||||
|
||||
|
||||
## update name in modifier targets
|
||||
if old != new:
|
||||
# find objects using this GP datablock
|
||||
for ob_user in [o for o in bpy.data.objects if o.data == layer.id_data]: # bpy.context.scene.objects
|
||||
# maybe a more elegant way exists to find all objects users ?
|
||||
|
||||
|
||||
# update Gpencil modifier targets
|
||||
for mod in ob_user.grease_pencil_modifiers:
|
||||
if not hasattr(mod, 'layer'):
|
||||
|
@ -84,7 +84,7 @@ def layer_name_build(layer, prefix='', desc='', suffix=''):
|
|||
if mod.layer == old:
|
||||
mod.layer = new
|
||||
|
||||
"""
|
||||
"""
|
||||
def layer_name_build(layer, prefix='', prefix2='', desc='', suffix=''):
|
||||
'''GET a layer and infos to build name
|
||||
Can take one or two prefix and description/name of the layer)
|
||||
|
@ -94,9 +94,9 @@ def layer_name_build(layer, prefix='', prefix2='', desc='', suffix=''):
|
|||
prefs = get_addon_prefs()
|
||||
sep = prefs.separator
|
||||
name = layer.info
|
||||
|
||||
|
||||
pattern = pattern.replace('_', sep) # set separator
|
||||
|
||||
|
||||
res = re.search(pattern, name.strip())
|
||||
p1 = '' if res.group(1) is None else res.group(1)
|
||||
p2 = '' if res.group(2) is None else res.group(2)
|
||||
|
@ -111,10 +111,10 @@ def layer_name_build(layer, prefix='', prefix2='', desc='', suffix=''):
|
|||
|
||||
if prefix2:
|
||||
p2 = prefix2.upper().strip() + sep
|
||||
|
||||
|
||||
if desc:
|
||||
p3 = desc
|
||||
|
||||
|
||||
if suffix:
|
||||
if suffix == 'suffixkillcode':
|
||||
p4 = ''
|
||||
|
@ -176,11 +176,11 @@ def grp_toggle(l, mode='TOGGLE'):
|
|||
if not res and mode in ('TOGGLE', 'GROUP'):
|
||||
# No gpr : add group prefix after stripping all space and dash
|
||||
l.info = grp_item_id + l.info.lstrip(' -')
|
||||
|
||||
|
||||
elif res and mode in ('TOGGLE', 'UNGROUP'):
|
||||
# found : delete group prefix
|
||||
l.info = res.group(2)
|
||||
|
||||
|
||||
|
||||
class GPTB_OT_layer_group_toggle(Operator):
|
||||
bl_idname = "gp.layer_group_toggle"
|
||||
|
@ -191,7 +191,7 @@ class GPTB_OT_layer_group_toggle(Operator):
|
|||
@classmethod
|
||||
def poll(cls, context):
|
||||
return True
|
||||
|
||||
|
||||
# group : StringProperty(default='', options={'SKIP_SAVE'})
|
||||
|
||||
def execute(self, context):
|
||||
|
@ -224,12 +224,12 @@ class GPTB_OT_layer_new_group(Operator):
|
|||
if not res:
|
||||
self.report({'ERROR'}, 'Could not create a group name, create a layer manually')
|
||||
return {"CANCELLED"}
|
||||
|
||||
|
||||
name = res.group('name').strip(' -')
|
||||
if not name:
|
||||
self.report({'ERROR'}, f'No name found in {act.info}')
|
||||
return {"CANCELLED"}
|
||||
|
||||
|
||||
if name in [l.info.strip(' -') for l in gpl]:
|
||||
self.report({'WARNING'}, f'Name already exists: {act.info}')
|
||||
return {"FINISHED"}
|
||||
|
@ -258,7 +258,7 @@ def build_layers_targets_from_dopesheet(context):
|
|||
gpl = context.object.data.layers
|
||||
act = gpl.active
|
||||
dopeset = context.space_data.dopesheet
|
||||
|
||||
|
||||
|
||||
if dopeset.show_only_selected:
|
||||
pool = [o for o in context.selected_objects if o.type == 'GPENCIL']
|
||||
|
@ -269,7 +269,7 @@ def build_layers_targets_from_dopesheet(context):
|
|||
|
||||
layer_pool = [l for o in pool for l in o.data.layers]
|
||||
layer_pool = list(set(layer_pool)) # remove dupli-layers from same data source with
|
||||
|
||||
|
||||
# apply search filter
|
||||
if dopeset.filter_text:
|
||||
layer_pool = [l for l in layer_pool if (dopeset.filter_text.lower() in l.info.lower()) ^ dopeset.use_filter_invert]
|
||||
|
@ -293,7 +293,7 @@ class GPTB_OT_select_set_same_prefix(Operator):
|
|||
@classmethod
|
||||
def poll(cls, context):
|
||||
return context.object and context.object.type == 'GPENCIL'
|
||||
|
||||
|
||||
mode : EnumProperty(default='SELECT', options={'SKIP_SAVE'},
|
||||
items=(
|
||||
('SELECT', "Select", "Select layer with same prefix as active"),
|
||||
|
@ -346,23 +346,23 @@ class GPTB_OT_select_set_same_prefix(Operator):
|
|||
## with split
|
||||
# namespace = act.info.split(sep,1)[0]
|
||||
# namespace_bool_list = [l.info.split(sep,1)[0] == namespace for l in gpl]
|
||||
|
||||
|
||||
## with reg # only active
|
||||
# namespace_bool_list = [l.info.split(sep,1)[0] + sep == namespace for l in gpl]
|
||||
# gpl.foreach_set('select', namespace_bool_list)
|
||||
|
||||
|
||||
## don't work Need Foreach set per gp
|
||||
# for l in pool:
|
||||
# l.select = l.info.split(sep,1)[0] + sep == namespace
|
||||
|
||||
|
||||
for gp, layers in gp_dic.items():
|
||||
# check namespace + restrict selection to visible layers according to filters
|
||||
# TODO : Should use the regex pattern to detect and compare r.group('tag')
|
||||
namespace_bool_list = [(l in layers) and (l.info.split(sep,1)[0] + sep == namespace) for l in gp.layers]
|
||||
gp.layers.foreach_set('select', namespace_bool_list)
|
||||
|
||||
|
||||
elif self.mode == 'SET':
|
||||
for l in pool:
|
||||
for l in pool:
|
||||
if not l.select or l == act:
|
||||
continue
|
||||
layer_name_build(l, prefix=namespace.strip(sep))
|
||||
|
@ -381,7 +381,7 @@ class GPTB_OT_select_set_same_color(Operator):
|
|||
@classmethod
|
||||
def poll(cls, context):
|
||||
return context.object and context.object.type == 'GPENCIL'
|
||||
|
||||
|
||||
mode : EnumProperty(default='SELECT', options={'SKIP_SAVE'},
|
||||
items=(
|
||||
('SELECT', "Select", "Select layer with same prefix as active"),
|
||||
|
@ -419,7 +419,7 @@ class GPTB_OT_select_set_same_color(Operator):
|
|||
color = act.channel_color
|
||||
if self.mode == 'SELECT':
|
||||
## NEED FOREACH TO APPLY SELECT
|
||||
|
||||
|
||||
## Only on active object
|
||||
# same_color_bool = [l.channel_color == act.channel_color for l in gpl]
|
||||
# gpl.foreach_set('select', same_color_bool) # only
|
||||
|
@ -428,8 +428,8 @@ class GPTB_OT_select_set_same_color(Operator):
|
|||
# for l in pool:
|
||||
# print(l.id_data.name, l.info, l.channel_color == act.channel_color)
|
||||
# l.select = l.channel_color == act.channel_color
|
||||
|
||||
"""
|
||||
|
||||
"""
|
||||
gps = []
|
||||
for l in pool:
|
||||
if l.id_data not in gps:
|
||||
|
@ -463,7 +463,7 @@ def replace_layer_name(target, replacement, selected_only=True, prefix_only=True
|
|||
gpl = bpy.context.object.data.layers
|
||||
|
||||
if selected_only:
|
||||
lays = [l for l in gpl if l.select] # exclude : l.info != 'background'
|
||||
lays = [l for l in gpl if l.select] # exclude : l.info != 'background'
|
||||
else:
|
||||
lays = [l for l in gpl] # exclude : if l.info != 'background'
|
||||
|
||||
|
@ -533,11 +533,11 @@ class GPTB_OT_rename_gp_layer(Operator):
|
|||
row = layout.row()
|
||||
row_a= row.row()
|
||||
row_a.prop(self, "selected")
|
||||
|
||||
|
||||
row_b= row.row()
|
||||
row_b.prop(self, "prefix")
|
||||
row_c= row.row()
|
||||
|
||||
|
||||
row_c.prop(self, "use_regex")
|
||||
row_b.active = not self.use_regex
|
||||
|
||||
|
@ -549,7 +549,7 @@ class GPTB_OT_rename_gp_layer(Operator):
|
|||
|
||||
def layer_name_builder_ui(self, context):
|
||||
'''appended to DATA_PT_gpencil_layers'''
|
||||
|
||||
|
||||
prefs = get_addon_prefs()
|
||||
if not prefs.show_prefix_buttons:
|
||||
return
|
||||
|
@ -563,7 +563,7 @@ def layer_name_builder_ui(self, context):
|
|||
|
||||
|
||||
line_limit = 8
|
||||
|
||||
|
||||
if len(prefs.prefixes.namespaces):
|
||||
ct = 0
|
||||
# can't use enumerate cause there can be hided prefix
|
||||
|
@ -576,7 +576,7 @@ def layer_name_builder_ui(self, context):
|
|||
op = row.operator("gp.layer_name_build", text=namespace.tag)
|
||||
op.prefix = namespace.tag
|
||||
op.tooltip = namespace.name
|
||||
|
||||
|
||||
if ct > 0:
|
||||
row.operator("gp.layer_name_build", text='', icon='X').prefix = 'prefixkillcode'
|
||||
|
||||
|
@ -604,12 +604,12 @@ def layer_name_builder_ui(self, context):
|
|||
## name (description of layer content)
|
||||
row = col.row(align=True)
|
||||
row.prop(context.scene.gptoolprops, 'layer_name', text='')
|
||||
|
||||
|
||||
## mimic groups using dash (disabled for now)
|
||||
# row.operator("gp.layer_new_group", text='', icon='COLLECTION_NEW')
|
||||
# row.operator("gp.layer_group_toggle", text='', icon='OUTLINER_OB_GROUP_INSTANCE')
|
||||
## no need for desc ops, already trigerred from update
|
||||
# row.operator("gp.layer_name_build", text='', icon='EVENT_RETURN').desc = context.scene.gptoolprops.layer_name
|
||||
# row.operator("gp.layer_name_build", text='', icon='EVENT_RETURN').desc = context.scene.gptoolprops.layer_name
|
||||
|
||||
if len(prefs.suffixes.namespaces):
|
||||
ct = 0
|
||||
|
@ -623,7 +623,7 @@ def layer_name_builder_ui(self, context):
|
|||
op = row.operator("gp.layer_name_build", text=namespace.tag)
|
||||
op.suffix = namespace.tag
|
||||
op.tooltip = namespace.name
|
||||
|
||||
|
||||
if ct > 0:
|
||||
row.operator("gp.layer_name_build", text='', icon='X').suffix = 'suffixkillcode'
|
||||
|
||||
|
@ -708,7 +708,7 @@ class GPTB_PT_layer_name_ui(bpy.types.Panel):
|
|||
wm = context.window_manager
|
||||
wm.invoke_props_dialog(self) # , width=600
|
||||
return {'FINISHED'}
|
||||
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
|
||||
|
@ -719,7 +719,7 @@ class GPTB_PT_layer_name_ui(bpy.types.Panel):
|
|||
# row.label(icon=icon)
|
||||
# return row
|
||||
# row = row_with_icon(layout, 'OUTLINER_DATA_GP_LAYER')
|
||||
|
||||
|
||||
row = layout.row()
|
||||
row.activate_init = True
|
||||
row.label(icon='OUTLINER_DATA_GP_LAYER')
|
||||
|
@ -774,7 +774,7 @@ def register_keymaps():
|
|||
kmi = km.keymap_items.new('gp.add_layer_rename', type='INSERT', value='PRESS', shift=True)
|
||||
addon_keymaps.append((km, kmi))
|
||||
|
||||
##---# F2 rename calls
|
||||
##---# F2 rename calls
|
||||
## Direct rename active layer in Paint mode
|
||||
km = addon.keymaps.new(name = "Grease Pencil Stroke Paint Mode", space_type = "EMPTY")
|
||||
kmi = km.keymap_items.new('wm.call_panel', type='F2', value='PRESS')
|
||||
|
@ -816,7 +816,7 @@ classes=(
|
|||
def register():
|
||||
for cls in classes:
|
||||
bpy.utils.register_class(cls)
|
||||
|
||||
|
||||
bpy.types.DATA_PT_gpencil_layers.prepend(layer_name_builder_ui)
|
||||
bpy.types.DOPESHEET_HT_header.append(gpencil_dopesheet_header)
|
||||
bpy.types.GPENCIL_MT_layer_context_menu.append(gpencil_layer_dropdown_menu)
|
||||
|
@ -832,9 +832,9 @@ def unregister():
|
|||
bpy.types.GPENCIL_MT_layer_context_menu.remove(gpencil_layer_dropdown_menu)
|
||||
bpy.types.DOPESHEET_HT_header.remove(gpencil_dopesheet_header)
|
||||
bpy.types.DATA_PT_gpencil_layers.remove(layer_name_builder_ui)
|
||||
|
||||
|
||||
for cls in reversed(classes):
|
||||
bpy.utils.unregister_class(cls)
|
||||
|
||||
|
||||
# delete layer index trigger
|
||||
bpy.msgbus.clear_by_owner(bpy.types.GreasePencil)
|
Loading…
Reference in New Issue