diff options
author | Campbell Barton <ideasman42@gmail.com> | 2015-04-09 12:09:03 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2015-04-09 12:10:00 +0300 |
commit | cc6e0b7394e2abb6fd32722851d30299ca75fa67 (patch) | |
tree | fe1e10e0394b4e965496d000935a0e561a5583c4 /release/scripts/modules/bpy_types.py | |
parent | bdad2c0595948add04cbb30a3118ddb1f2056ca7 (diff) |
UI: Extend preset menu
- allow for preset menu to change operator defaults.
- allow preset menu to select own kinds of file extensions.
Diffstat (limited to 'release/scripts/modules/bpy_types.py')
-rw-r--r-- | release/scripts/modules/bpy_types.py | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/release/scripts/modules/bpy_types.py b/release/scripts/modules/bpy_types.py index c7ec7e1e54a..94d371447d6 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): |