Revision: 37102 http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=37102 Author: campbellbarton Date: 2011-06-02 15:21:47 +0000 (Thu, 02 Jun 2011) Log Message: ----------- addons now show expanded list again (since Brecht's commit now makes it fast) also add utility function for getting cleaned, unique names from python: bpy_extras.io_utils.unique_name(...)
Modified Paths: -------------- trunk/blender/release/scripts/modules/bpy_extras/io_utils.py trunk/blender/release/scripts/startup/bl_ui/space_userpref.py Modified: trunk/blender/release/scripts/modules/bpy_extras/io_utils.py =================================================================== --- trunk/blender/release/scripts/modules/bpy_extras/io_utils.py 2011-06-02 14:18:51 UTC (rev 37101) +++ trunk/blender/release/scripts/modules/bpy_extras/io_utils.py 2011-06-02 15:21:47 UTC (rev 37102) @@ -29,6 +29,7 @@ "path_reference", "path_reference_copy", "path_reference_mode", + "unique_name" ) import bpy @@ -298,3 +299,43 @@ os.makedirs(dir_to) shutil.copy(file_src, file_dst) + + +def unique_name(key, name, name_dict, name_max=-1, clean_func=None): + """ + Helper function for storing unique names which may have special characters + stripped and restricted to a maximum length. + + :arg key: unique item this name belongs to, name_dict[key] will be reused + when available. + This can be the object, mesh, material, etc instance its self. + :type key: any hashable object assosiated with the *name*. + :arg name: The name used to create a unique value in *name_dict*. + :type name: string + :arg name_dict: This is used to cache namespace to ensure no collisions + occur, this should be an empty dict initially and only modified by this + function. + :type name_dict: dict + :arg clean_func: Function to call on *name* before creating a unique value. + :type clean_func: function + """ + name_new = name_dict.get(key) + if name_new is None: + count = 1 + name_dict_values = name_dict.values() + name_new = name_new_orig = name if clean_func is None else clean_func(name) + + if name_max == -1: + while name_new in name_dict_values: + name_new = "%s.%03d" % (name_new_orig, count) + count += 1 + else: + name_new = name_new[:name_max] + while name_new in name_dict_values: + count_str = "%03d" % count + name_new = "%.*s.%s" % (name_max - (len(count_str) + 1), name_new_orig, count_str) + count += 1 + + name_dict[key] = name_new + + return name_new Modified: trunk/blender/release/scripts/startup/bl_ui/space_userpref.py =================================================================== --- trunk/blender/release/scripts/startup/bl_ui/space_userpref.py 2011-06-02 14:18:51 UTC (rev 37101) +++ trunk/blender/release/scripts/startup/bl_ui/space_userpref.py 2011-06-02 15:21:47 UTC (rev 37102) @@ -890,7 +890,7 @@ col = split.column() col.prop(context.window_manager, "addon_search", text="", icon='VIEWZOOM') col.label(text="Categories") - col.prop(context.window_manager, "addon_filter", text="") # , expand=True, too slow with dynamic enum. + col.prop(context.window_manager, "addon_filter", expand=True) col.label(text="Supported Level") col.prop(context.window_manager, "addon_support", expand=True) _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org http://lists.blender.org/mailman/listinfo/bf-blender-cvs