diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-04-07 06:19:11 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-04-07 06:19:11 +0400 |
commit | b9f9aa947a4ffc7ecc8cc661655b02a21efe6d0a (patch) | |
tree | 83389028037ba007545c39bbbd4db5d9f5e15763 /release/scripts/modules/bpy_types.py | |
parent | 628b183d98f55a71ad22dd9c742c2318ed7c72e6 (diff) |
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.
Diffstat (limited to 'release/scripts/modules/bpy_types.py')
-rw-r--r-- | release/scripts/modules/bpy_types.py | 18 |
1 files 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"}) |