UI: Extend preset menu

- allow for preset menu to change operator defaults.
- allow preset menu to select own kinds of file extensions.
This commit is contained in:
Campbell Barton 2015-04-09 19:09:03 +10:00
parent bdad2c0595
commit cc6e0b7394

@ -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):