fix [#27148] *Invalid Path* in all "operator presets" dropdowns

This commit is contained in:
Campbell Barton 2011-05-02 17:29:30 +00:00
parent a9b066a9c6
commit d8eafe14c6
6 changed files with 30 additions and 16 deletions

@ -226,21 +226,35 @@ def user_script_path():
return None
def script_paths(subdir=None, user=True):
def script_paths(subdir=None, user_pref=True, all=False):
"""
Returns a list of valid script paths from the home directory and user preferences.
Returns a list of valid script paths.
Accepts any number of string arguments which are joined to make a path.
:arg subdir: Optional subdir.
:type subdir: string
:arg user_pref: Include the user preference script path.
:type user_pref: bool
:arg all: Include local, user and system paths rather just the paths blender uses.
:type all: bool
:return: script paths.
:rtype: list
"""
scripts = list(_scripts)
# add user scripts dir
if user:
if user_pref:
user_script_path = _bpy.context.user_preferences.filepaths.script_directory
else:
user_script_path = None
for path in _bpy_script_paths() + (user_script_path, ):
if all:
# all possible paths
base_paths = tuple(_os.path.join(resource_path(res), "scripts") for res in ('LOCAL', 'USER', 'SYSTEM'))
else:
# only paths blender uses
base_paths = _bpy_script_paths()
for path in base_paths + (user_script_path, ):
if path:
path = _os.path.normpath(path)
if path not in scripts and _os.path.isdir(path):
@ -266,7 +280,7 @@ def preset_paths(subdir):
Returns a list of paths for a specific preset.
"""
dirs = []
for path in script_paths("presets"):
for path in script_paths("presets", all=True):
directory = _os.path.join(path, subdir)
if _os.path.isdir(directory):
dirs.append(directory)

@ -48,11 +48,11 @@ class AddPresetBase():
preset_menu_class = getattr(bpy.types, self.preset_menu)
if not self.remove_active:
if not self.name:
name = self.name.strip()
if not name:
return {'FINISHED'}
filename = self.as_filename(self.name)
filename = self.as_filename(name)
target_path = bpy.utils.user_resource('SCRIPTS', os.path.join("presets", self.preset_subdir), create=True)
@ -118,7 +118,7 @@ class AddPresetBase():
return {'FINISHED'}
def check(self, context):
self.name = self.as_filename(self.name)
self.name = self.as_filename(self.name.strip())
def invoke(self, context, event):
if not self.remove_active:

@ -837,6 +837,7 @@ class WM_OT_properties_add(bpy.types.Operator):
item[property] = 1.0
return {'FINISHED'}
class WM_OT_properties_context_change(bpy.types.Operator):
"Change the context tab in a Properties Window"
bl_idname = "wm.properties_context_change"
@ -846,7 +847,6 @@ class WM_OT_properties_context_change(bpy.types.Operator):
def execute(self, context):
context.space_data.context = (self.context)
return {'FINISHED'}