Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2017-03-14 22:04:52 +0300
committerCampbell Barton <ideasman42@gmail.com>2017-03-14 22:04:52 +0300
commit1d5ba269c1f6b232f1ec83e77e6e8fe07d5c5d1f (patch)
tree327dc2edb006468113e185b4946ab4c3b434d68b /release
parent0f13f5a683ec9b8d024feaec5ba2ede193a618f0 (diff)
parentf13c729b26befae8709a8e565a27d6fd31101d44 (diff)
Merge branch 'master' into blender2.8
Diffstat (limited to 'release')
-rw-r--r--release/scripts/modules/bpy_types.py37
-rw-r--r--release/scripts/startup/bl_operators/presets.py2
-rw-r--r--release/scripts/startup/bl_ui/space_text.py18
3 files changed, 41 insertions, 16 deletions
diff --git a/release/scripts/modules/bpy_types.py b/release/scripts/modules/bpy_types.py
index d64acd2ce3b..b6a9b2f2f62 100644
--- a/release/scripts/modules/bpy_types.py
+++ b/release/scripts/modules/bpy_types.py
@@ -725,11 +725,30 @@ class Header(StructRNA, _GenericUI, metaclass=RNAMeta):
class Menu(StructRNA, _GenericUI, metaclass=RNAMeta):
__slots__ = ()
- def path_menu(self, searchpaths, operator,
- props_default=None, filter_ext=None):
+ def path_menu(self, searchpaths, operator, *,
+ props_default=None, prop_filepath="filepath",
+ filter_ext=None, display_name=None):
+ """
+ Populate a menu from a list of paths.
+
+ :arg searchpaths: Paths to scan.
+ :type searchpaths: sequence of strings.
+ :arg operator: The operator id to use with each file.
+ :type operator: string
+ :arg prop_filepath: Optional operator filepath property (defaults to "filepath").
+ :type prop_filepath: string
+ :arg props_default: Properties to assign to each operator.
+ :type props_default: dict
+ :arg filter_ext: Optional callback that takes the file extensions.
+
+ Returning false excludes the file from the list.
+
+ :type filter_ext: Callable that takes a string and returns a bool.
+ :arg display_name: Optional callback that takes the full path, returns the name to display.
+ :type display_name: Callable that takes a string and returns a string.
+ """
layout = self.layout
- # hard coded to set the operators 'filepath' to the filename.
import os
import bpy.utils
@@ -752,15 +771,19 @@ class Menu(StructRNA, _GenericUI, metaclass=RNAMeta):
files.sort()
for f, filepath in files:
- props = layout.operator(operator,
- text=bpy.path.display_name(f),
- translate=False)
+ # Intentionally pass the full path to 'display_name' callback,
+ # since the callback may want to use part a directory in the name.
+ props = layout.operator(
+ operator,
+ text=display_name(filepath) if display_name else bpy.path.display_name(f),
+ translate=False,
+ )
if props_default is not None:
for attr, value in props_default.items():
setattr(props, attr, value)
- props.filepath = filepath
+ setattr(props, prop_filepath, filepath)
if operator == "script.execute_preset":
props.menu_idname = self.bl_idname
diff --git a/release/scripts/startup/bl_operators/presets.py b/release/scripts/startup/bl_operators/presets.py
index e01e509b292..cb332c18127 100644
--- a/release/scripts/startup/bl_operators/presets.py
+++ b/release/scripts/startup/bl_operators/presets.py
@@ -135,7 +135,7 @@ class AddPresetBase:
file_preset.write("%s = %r\n" % (rna_path_step, value))
- file_preset = open(filepath, 'w')
+ file_preset = open(filepath, 'w', encoding="utf-8")
file_preset.write("import bpy\n")
if hasattr(self, "preset_defines"):
diff --git a/release/scripts/startup/bl_ui/space_text.py b/release/scripts/startup/bl_ui/space_text.py
index 1fd10575e07..8c5418161ca 100644
--- a/release/scripts/startup/bl_ui/space_text.py
+++ b/release/scripts/startup/bl_ui/space_text.py
@@ -215,20 +215,22 @@ class TEXT_MT_templates_py(Menu):
bl_label = "Python"
def draw(self, context):
- self.path_menu(bpy.utils.script_paths("templates_py"),
- "text.open",
- {"internal": True},
- )
+ self.path_menu(
+ bpy.utils.script_paths("templates_py"),
+ "text.open",
+ props_default={"internal": True},
+ )
class TEXT_MT_templates_osl(Menu):
bl_label = "Open Shading Language"
def draw(self, context):
- self.path_menu(bpy.utils.script_paths("templates_osl"),
- "text.open",
- {"internal": True},
- )
+ self.path_menu(
+ bpy.utils.script_paths("templates_osl"),
+ "text.open",
+ props_default={"internal": True},
+ )
class TEXT_MT_templates(Menu):