diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2018-11-30 17:40:46 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2018-11-30 17:40:57 +0300 |
commit | fe2855489801d8e87038b8b5884fc9d26efb1bf2 (patch) | |
tree | d84575ed71847fdbff214afd0656bab715c83ea3 /release | |
parent | 4251ab467542ca611acb6b5275dffbb61464e739 (diff) |
StudioLight Editor: Add copy settings and overwrite prompt
Copy settings let users create variations more easily.
Ovewrite prompt is there to be able to edit already existing studiolight.
Diffstat (limited to 'release')
-rw-r--r-- | release/scripts/startup/bl_operators/wm.py | 45 | ||||
-rw-r--r-- | release/scripts/startup/bl_ui/space_userpref.py | 30 |
2 files changed, 46 insertions, 29 deletions
diff --git a/release/scripts/startup/bl_operators/wm.py b/release/scripts/startup/bl_operators/wm.py index f78b7491bdd..03f83097cb0 100644 --- a/release/scripts/startup/bl_operators/wm.py +++ b/release/scripts/startup/bl_operators/wm.py @@ -2480,18 +2480,21 @@ class WM_OT_studiolight_install(Operator): class WM_OT_studiolight_new(Operator): - """Create custom studio light from the studio light editor settings""" + """Save custom studio light from the studio light editor settings""" bl_idname = 'wm.studiolight_new' - bl_label = "Create custom Studio light" + bl_label = "Save custom Studio light" filename: StringProperty( name="Name", default="StudioLight", ) + ask_overide = False + def execute(self, context): import pathlib userpref = context.user_preferences + wm = context.window_manager path_studiolights = bpy.utils.user_resource('DATAFILES') @@ -2508,8 +2511,13 @@ class WM_OT_studiolight_new(Operator): finalpath = str(path_studiolights.joinpath(self.filename)); if pathlib.Path(finalpath + ".sl").is_file(): - self.report({'ERROR'}, "File already exists") - return {'CANCELLED'} + if not self.ask_overide: + self.ask_overide = True + return wm.invoke_props_dialog(self, width=600) + else: + for studio_light in userpref.studio_lights: + if studio_light.name == self.filename + ".sl": + bpy.ops.wm.studiolight_uninstall(index=studio_light.index) userpref.studio_lights.new(path=finalpath) @@ -2524,7 +2532,10 @@ class WM_OT_studiolight_new(Operator): def draw(self, context): layout = self.layout - layout.prop(self, "filename") + if self.ask_overide: + layout.label(text="Warning, file already exists. Overwrite existing file?") + else: + layout.prop(self, "filename") def invoke(self, context, event): wm = context.window_manager @@ -2532,6 +2543,7 @@ class WM_OT_studiolight_new(Operator): class WM_OT_studiolight_uninstall(Operator): + """Delete Studio Light""" bl_idname = 'wm.studiolight_uninstall' bl_label = "Uninstall Studio Light" index: bpy.props.IntProperty() @@ -2556,6 +2568,28 @@ class WM_OT_studiolight_uninstall(Operator): return {'CANCELLED'} +class WM_OT_studiolight_copy_settings(Operator): + """Copy Studio Light settings to the Studio light editor""" + bl_idname = 'wm.studiolight_copy_settings' + bl_label = "Copy Studio Light settings" + index: bpy.props.IntProperty() + + def execute(self, context): + userpref = context.user_preferences + system = userpref.system + for studio_light in userpref.studio_lights: + if studio_light.index == self.index: + system.light_ambient = studio_light.light_ambient + for sys_light, light in zip(system.solid_lights, studio_light.solid_lights): + sys_light.use = light.use + sys_light.diffuse_color = light.diffuse_color + sys_light.specular_color = light.specular_color + sys_light.smooth = light.smooth + sys_light.direction = light.direction + return {'FINISHED'} + return {'CANCELLED'} + + class WM_OT_studiolight_userpref_show(Operator): """Show light user preferences""" bl_idname = "wm.studiolight_userpref_show" @@ -2819,6 +2853,7 @@ classes = ( WM_OT_studiolight_install, WM_OT_studiolight_new, WM_OT_studiolight_uninstall, + WM_OT_studiolight_copy_settings, WM_OT_studiolight_userpref_show, WM_OT_tool_set_by_name, WM_OT_toolbar, diff --git a/release/scripts/startup/bl_ui/space_userpref.py b/release/scripts/startup/bl_ui/space_userpref.py index 56accc902f4..ae1fe42b3d7 100644 --- a/release/scripts/startup/bl_ui/space_userpref.py +++ b/release/scripts/startup/bl_ui/space_userpref.py @@ -1516,9 +1516,14 @@ class StudioLightPanelMixin(): row = box.row() row.template_icon(layout.icon(studio_light), scale=6.0) - op = row.operator('wm.studiolight_uninstall', text="", icon='REMOVE') + col = row.column() + op = col.operator('wm.studiolight_uninstall', text="", icon='REMOVE') op.index = studio_light.index + if studio_light.type == 'STUDIO': + op = col.operator('wm.studiolight_copy_settings', text="", icon='IMPORT') + op.index = studio_light.index + box.label(text=studio_light.name) @@ -1536,29 +1541,6 @@ class USERPREF_PT_studiolight_lights(Panel, StudioLightPanelMixin): bl_label = "Studio Lights" sl_type = 'STUDIO' - @classmethod - def poll(cls, context): - userpref = context.user_preferences - return (userpref.active_section == 'LIGHTS') - - def opengl_light_buttons(self, layout, light): - - col = layout.column() - col.active = light.use - - col.prop(light, "use", text="Use Light") - col.prop(light, "diffuse_color", text="Diffuse") - col.prop(light, "specular_color", text="Specular") - col.prop(light, "smooth") - col.prop(light, "direction") - - def draw(self, context): - userpref = context.user_preferences - lights = self._get_lights(userpref) - layout = self.layout - - self.draw_light_list(layout, lights) - class USERPREF_PT_studiolight_light_editor(Panel): bl_label = "Studio Light Editor" |