From b9f9aa947a4ffc7ecc8cc661655b02a21efe6d0a Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 7 Apr 2012 02:19:11 +0000 Subject: [PATCH] dont display any file as a preset in the menu (limit to *.py, *.xml) backup files like .py~ for eg had their own menu entries which got annoying. added optional filter_ext function callback argument to Menu.path_menu() to avoid displaying invalid types. --- release/scripts/modules/bpy_types.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/release/scripts/modules/bpy_types.py b/release/scripts/modules/bpy_types.py index 933e77ce2e3..6f921868ccc 100644 --- a/release/scripts/modules/bpy_types.py +++ b/release/scripts/modules/bpy_types.py @@ -671,7 +671,7 @@ class Header(StructRNA, _GenericUI, metaclass=RNAMeta): class Menu(StructRNA, _GenericUI, metaclass=RNAMeta): __slots__ = () - def path_menu(self, searchpaths, operator, props_default={}): + def path_menu(self, searchpaths, operator, props_default={}, filter_ext=None): layout = self.layout # hard coded to set the operators 'filepath' to the filename. @@ -687,17 +687,16 @@ class Menu(StructRNA, _GenericUI, metaclass=RNAMeta): files = [] for directory in searchpaths: files.extend([(f, os.path.join(directory, f)) - for f in os.listdir(directory)]) + for f in os.listdir(directory) + if (not f.startswith(".")) + if ((filter_ext is None) or + (filter_ext(os.path.splitext(f)[1]))) + ]) files.sort() for f, filepath in files: - - if f.startswith("."): - continue - - preset_name = bpy.path.display_name(f) - props = layout.operator(operator, text=preset_name) + props = layout.operator(operator, text=bpy.path.display_name(f)) for attr, value in props_default.items(): setattr(props, attr, value) @@ -714,4 +713,5 @@ class Menu(StructRNA, _GenericUI, metaclass=RNAMeta): """ import bpy self.path_menu(bpy.utils.preset_paths(self.preset_subdir), - self.preset_operator) + self.preset_operator, + filter_ext=lambda ext: ext.lower() in {".py", ".xml"})