[Bf-blender-cvs] [fab834d] gooseberry: Merge branch 'master' into gooseberry
Sergey Sharybin
noreply at git.blender.org
Sat Jun 13 16:30:47 CEST 2015
Commit: fab834d35154e8f09767d9a19b2ee4c8ea2ca1d3
Author: Sergey Sharybin
Date: Sat Jun 13 16:30:34 2015 +0200
Branches: gooseberry
https://developer.blender.org/rBfab834d35154e8f09767d9a19b2ee4c8ea2ca1d3
Merge branch 'master' into gooseberry
===================================================================
===================================================================
diff --cc release/scripts/startup/bl_operators/presets.py
index ffaf1b7,63c1945..2d13a8b
--- a/release/scripts/startup/bl_operators/presets.py
+++ b/release/scripts/startup/bl_operators/presets.py
@@@ -53,43 -53,21 +53,54 @@@ class AddPresetBase
@staticmethod
def as_filename(name): # could reuse for other presets
- for char in " !@#$%^&*(){}:\";'[]<>,.\\/?":
- name = name.replace(char, '_')
- return name.lower().strip()
+
+ # lazy init maketrans
+ def maketrans_init():
+ cls = AddPresetBase
+ attr = "_as_filename_trans"
+
+ trans = getattr(cls, attr, None)
+ if trans is None:
+ trans = str.maketrans({char: "_" for char in " !@#$%^&*(){}:\";'[]<>,.\\/?"})
+ setattr(cls, attr, trans)
+ return trans
+
+ trans = maketrans_init()
+ return name.lower().strip().translate(trans)
+ def write_preset_py(self, file_preset):
+ def rna_recursive_attr_expand(value, rna_path_step, level):
+ if isinstance(value, bpy.types.PropertyGroup):
+ for sub_value_attr in value.bl_rna.properties.keys():
+ if sub_value_attr == "rna_type":
+ continue
+ sub_value = getattr(value, sub_value_attr)
+ rna_recursive_attr_expand(sub_value, "%s.%s" % (rna_path_step, sub_value_attr), level)
+ elif type(value).__name__ == "bpy_prop_collection_idprop": # could use nicer method
+ file_preset.write("%s.clear()\n" % rna_path_step)
+ for sub_value in value:
+ file_preset.write("item_sub_%d = %s.add()\n" % (level, rna_path_step))
+ rna_recursive_attr_expand(sub_value, "item_sub_%d" % level, level + 1)
+ else:
+ # convert thin wrapped sequences
+ # to simple lists to repr()
+ try:
+ value = value[:]
+ except:
+ pass
+
+ file_preset.write("%s = %r\n" % (rna_path_step, value))
+
+ if hasattr(self, "preset_defines"):
+ for rna_path in self.preset_defines:
+ exec(rna_path)
+ file_preset.write("%s\n" % rna_path)
+ file_preset.write("\n")
+
+ for rna_path in self.preset_values:
+ value = eval(rna_path)
+ rna_recursive_attr_expand(value, rna_path, 1)
+
def execute(self, context):
import os
More information about the Bf-blender-cvs
mailing list