[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [45453] trunk/blender/release/scripts/ modules/bpy_types.py: dont display any file as a preset in the menu ( limit to *.py, *.xml)
Campbell Barton
ideasman42 at gmail.com
Sat Apr 7 04:19:13 CEST 2012
Revision: 45453
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=45453
Author: campbellbarton
Date: 2012-04-07 02:19:11 +0000 (Sat, 07 Apr 2012)
Log Message:
-----------
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.
Modified Paths:
--------------
trunk/blender/release/scripts/modules/bpy_types.py
Modified: trunk/blender/release/scripts/modules/bpy_types.py
===================================================================
--- trunk/blender/release/scripts/modules/bpy_types.py 2012-04-07 00:37:01 UTC (rev 45452)
+++ trunk/blender/release/scripts/modules/bpy_types.py 2012-04-07 02:19:11 UTC (rev 45453)
@@ -671,7 +671,7 @@
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,18 +687,17 @@
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:
+ props = layout.operator(operator, text=bpy.path.display_name(f))
- if f.startswith("."):
- continue
-
- preset_name = bpy.path.display_name(f)
- props = layout.operator(operator, text=preset_name)
-
for attr, value in props_default.items():
setattr(props, attr, value)
@@ -714,4 +713,5 @@
"""
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"})
More information about the Bf-blender-cvs
mailing list