[Bf-blender-cvs] [cc6e0b7] master: UI: Extend preset menu

Campbell Barton noreply at git.blender.org
Thu Apr 9 11:10:52 CEST 2015


Commit: cc6e0b7394e2abb6fd32722851d30299ca75fa67
Author: Campbell Barton
Date:   Thu Apr 9 19:09:03 2015 +1000
Branches: master
https://developer.blender.org/rBcc6e0b7394e2abb6fd32722851d30299ca75fa67

UI: Extend preset menu

- allow for preset menu to change operator defaults.
- allow preset menu to select own kinds of file extensions.

===================================================================

M	release/scripts/modules/bpy_types.py

===================================================================

diff --git a/release/scripts/modules/bpy_types.py b/release/scripts/modules/bpy_types.py
index c7ec7e1..94d3714 100644
--- a/release/scripts/modules/bpy_types.py
+++ b/release/scripts/modules/bpy_types.py
@@ -715,7 +715,7 @@ class Menu(StructRNA, _GenericUI, metaclass=RNAMeta):
     __slots__ = ()
 
     def path_menu(self, searchpaths, operator,
-                  props_default={}, filter_ext=None):
+                  props_default=None, filter_ext=None):
 
         layout = self.layout
         # hard coded to set the operators 'filepath' to the filename.
@@ -745,8 +745,9 @@ class Menu(StructRNA, _GenericUI, metaclass=RNAMeta):
                                     text=bpy.path.display_name(f),
                                     translate=False)
 
-            for attr, value in props_default.items():
-                setattr(props, attr, value)
+            if props_default is not None:
+                for attr, value in props_default.items():
+                    setattr(props, attr, value)
 
             props.filepath = filepath
             if operator == "script.execute_preset":
@@ -754,14 +755,20 @@ class Menu(StructRNA, _GenericUI, metaclass=RNAMeta):
 
     def draw_preset(self, context):
         """
-        Define these on the subclass
-        - preset_operator
-        - preset_subdir
+        Define these on the subclass:
+        - preset_operator (string)
+        - preset_subdir (string)
+
+        Optionally:
+        - preset_extensions (set of strings)
+        - preset_operator_defaults (dict of keyword args)
         """
         import bpy
+        ext = getattr(self, "preset_extensions", {".py", ".xml"})
+        ext = getattr(self, "preset_operator_defaults", None)
         self.path_menu(bpy.utils.preset_paths(self.preset_subdir),
                        self.preset_operator,
-                       filter_ext=lambda ext: ext.lower() in {".py", ".xml"})
+                       filter_ext=lambda ext: ext.lower() in ext)
 
     @classmethod
     def draw_collapsible(cls, context, layout):




More information about the Bf-blender-cvs mailing list