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>2019-01-02 18:01:28 +0300
committerCampbell Barton <ideasman42@gmail.com>2019-01-02 18:13:00 +0300
commitae50a7df037e63863815b54ca53b4dbf3cda2799 (patch)
tree1236d43cce43d3c529c916744d2405751e149225 /release
parent72e2a0cfb6f8e4d21b33982bbd572f10c20e947c (diff)
Fixes and edits to studio light operators
- Remove pathlib use (was converting to/from string with no real advantage). - Use user_resource(..., create=True) to ensure the path exists. - Pass full path to BKE_studiolight_create, don't add extension after. - Fix 'sl' filtering glob and move from ui code to operator. - Fix string copy length.
Diffstat (limited to 'release')
-rw-r--r--release/scripts/startup/bl_operators/wm.py67
-rw-r--r--release/scripts/startup/bl_ui/space_userpref.py8
2 files changed, 29 insertions, 46 deletions
diff --git a/release/scripts/startup/bl_operators/wm.py b/release/scripts/startup/bl_operators/wm.py
index 12b0e4df912..b8db041710c 100644
--- a/release/scripts/startup/bl_operators/wm.py
+++ b/release/scripts/startup/bl_operators/wm.py
@@ -2451,33 +2451,24 @@ class WM_OT_studiolight_install(Operator):
)
def execute(self, context):
- import traceback
+ import os
import shutil
- import pathlib
prefs = context.preferences
- filepaths = [pathlib.Path(self.directory, e.name) for e in self.files]
- path_studiolights = bpy.utils.user_resource('DATAFILES')
-
+ filepaths = [os.path.join(self.directory, e.name) for e in self.files]
+ path_studiolights = bpy.utils.user_resource('DATAFILES', "studiolights", create=True)
if not path_studiolights:
- self.report({'ERROR'}, "Failed to get Studio Light path")
+ self.report({'ERROR'}, "Failed to create Studio Light path")
return {'CANCELLED'}
- path_studiolights = pathlib.Path(path_studiolights, "studiolights", self.type.lower())
- if not path_studiolights.exists():
- try:
- path_studiolights.mkdir(parents=True, exist_ok=True)
- except:
- traceback.print_exc()
-
for filepath in filepaths:
- shutil.copy(str(filepath), str(path_studiolights))
- prefs.studio_lights.load(str(path_studiolights.joinpath(filepath.name)), self.type)
+ shutil.copy(filepath, path_studiolights)
+ prefs.studio_lights.load(os.path.join(path_studiolights, filepath), self.type)
# print message
msg = (
tip_("StudioLight Installed %r into %r") %
- (", ".join(str(x.name) for x in self.files), str(path_studiolights))
+ (", ".join(e.name for e in self.files), path_studiolights)
)
print(msg)
self.report({'INFO'}, msg)
@@ -2485,6 +2476,10 @@ class WM_OT_studiolight_install(Operator):
def invoke(self, context, event):
wm = context.window_manager
+
+ if self.type == 'STUDIO':
+ self.filter_glob = "*.sl"
+
wm.fileselect_add(self)
return {'RUNNING_MODAL'}
@@ -2502,34 +2497,27 @@ class WM_OT_studiolight_new(Operator):
ask_overide = False
def execute(self, context):
- import pathlib
+ import os
prefs = context.preferences
wm = context.window_manager
+ filename = bpy.path.ensure_ext(self.filename, ".sl")
- path_studiolights = bpy.utils.user_resource('DATAFILES')
-
+ path_studiolights = bpy.utils.user_resource('DATAFILES', os.path.join("studiolights", "studio"), create=True)
if not path_studiolights:
self.report({'ERROR'}, "Failed to get Studio Light path")
return {'CANCELLED'}
- path_studiolights = pathlib.Path(path_studiolights, "studiolights", "studio")
- if not path_studiolights.exists():
- try:
- path_studiolights.mkdir(parents=True, exist_ok=True)
- except:
- traceback.print_exc()
-
- finalpath = str(path_studiolights.joinpath(self.filename))
- if pathlib.Path(finalpath + ".sl").is_file():
+ filepath_final = os.path.join(path_studiolights, filename)
+ if os.path.isfile(filepath_final):
if not self.ask_overide:
self.ask_overide = True
return wm.invoke_props_dialog(self, width=600)
else:
for studio_light in prefs.studio_lights:
- if studio_light.name == self.filename + ".sl":
+ if studio_light.name == filename:
bpy.ops.wm.studiolight_uninstall(index=studio_light.index)
- prefs.studio_lights.new(path=finalpath)
+ prefs.studio_lights.new(path=filepath_final)
# print message
msg = (
@@ -2558,21 +2546,18 @@ class WM_OT_studiolight_uninstall(Operator):
bl_label = "Uninstall Studio Light"
index: bpy.props.IntProperty()
- def _remove_path(self, path):
- if path.exists():
- path.unlink()
-
def execute(self, context):
- import pathlib
+ import os
prefs = context.preferences
for studio_light in prefs.studio_lights:
if studio_light.index == self.index:
- if studio_light.path:
- self._remove_path(pathlib.Path(studio_light.path))
- if studio_light.path_irr_cache:
- self._remove_path(pathlib.Path(studio_light.path_irr_cache))
- if studio_light.path_sh_cache:
- self._remove_path(pathlib.Path(studio_light.path_sh_cache))
+ for filepath in (
+ studio_light.path,
+ studio_light.path_irr_cache,
+ studio_light.path_sh_cache,
+ ):
+ if filepath and os.path.exists(filepath):
+ os.unlink(filepath)
prefs.studio_lights.remove(studio_light)
return {'FINISHED'}
return {'CANCELLED'}
diff --git a/release/scripts/startup/bl_ui/space_userpref.py b/release/scripts/startup/bl_ui/space_userpref.py
index 73d34fdb380..7dacb8d9db6 100644
--- a/release/scripts/startup/bl_ui/space_userpref.py
+++ b/release/scripts/startup/bl_ui/space_userpref.py
@@ -45,11 +45,9 @@ class USERPREF_HT_header(Header):
layout.operator("wm.addon_refresh", icon='FILE_REFRESH')
layout.menu("USERPREF_MT_addons_online_resources")
elif prefs.active_section == 'LIGHTS':
- layout.operator("wm.studiolight_install", text="Add MatCap").type = 'MATCAP'
- layout.operator("wm.studiolight_install", text="Add LookDev HDRI").type = 'WORLD'
- op = layout.operator("wm.studiolight_install", text="Add Studio Light")
- op.type = 'STUDIO'
- op.filter_glob = ".sl"
+ layout.operator("wm.studiolight_install", text="Install MatCap").type = 'MATCAP'
+ layout.operator("wm.studiolight_install", text="Install LookDev HDRI").type = 'WORLD'
+ layout.operator("wm.studiolight_install", text="Install Studio Light").type = 'STUDIO'
elif prefs.active_section == 'THEMES':
layout.operator("wm.theme_install", icon='FILEBROWSER')
layout.operator("ui.reset_default_theme", icon='LOOP_BACK')