diff options
Diffstat (limited to 'release/scripts/startup/bl_operators/wm.py')
-rw-r--r-- | release/scripts/startup/bl_operators/wm.py | 68 |
1 files changed, 67 insertions, 1 deletions
diff --git a/release/scripts/startup/bl_operators/wm.py b/release/scripts/startup/bl_operators/wm.py index 926ad9b94f7..883bac84e78 100644 --- a/release/scripts/startup/bl_operators/wm.py +++ b/release/scripts/startup/bl_operators/wm.py @@ -764,6 +764,7 @@ class WM_OT_path_open(Operator): filepath = StringProperty( subtype='FILE_PATH', + options={'SKIP_SAVE'}, ) def execute(self, context): @@ -771,7 +772,13 @@ class WM_OT_path_open(Operator): import os import subprocess - filepath = bpy.path.abspath(self.filepath) + filepath = self.filepath + + if not filepath: + self.report({'ERROR'}, "File path was not set") + return {'CANCELLED'} + + filepath = bpy.path.abspath(filepath) filepath = os.path.normpath(filepath) if not os.path.exists(filepath): @@ -1538,6 +1545,65 @@ class WM_OT_addon_disable(Operator): addon_utils.disable(self.module) return {'FINISHED'} +class WM_OT_theme_install(Operator): + "Install a theme" + bl_idname = "wm.theme_install" + bl_label = "Install Theme..." + + overwrite = BoolProperty( + name="Overwrite", + description="Remove existing theme file if exists", + default=True, + ) + filepath = StringProperty( + subtype='FILE_PATH', + ) + filter_folder = BoolProperty( + name="Filter folders", + default=True, + options={'HIDDEN'}, + ) + filter_glob = StringProperty( + default="*.xml", + options={'HIDDEN'}, + ) + + def execute(self, context): + import os + import shutil + import traceback + + xmlfile = self.filepath + + path_themes = bpy.utils.user_resource('SCRIPTS','presets/interface_theme',create=True) + + if not path_themes: + self.report({'ERROR'}, "Failed to get themes path") + return {'CANCELLED'} + + path_dest = os.path.join(path_themes, os.path.basename(xmlfile)) + + if not self.overwrite: + if os.path.exists(path_dest): + self.report({'WARNING'}, "File already installed to %r\n" % path_dest) + return {'CANCELLED'} + + try: + shutil.copyfile(xmlfile, path_dest) + bpy.ops.script.execute_preset(filepath=path_dest,menu_idname="USERPREF_MT_interface_theme_presets") + + except: + traceback.print_exc() + return {'CANCELLED'} + + return {'FINISHED'} + + + def invoke(self, context, event): + wm = context.window_manager + wm.fileselect_add(self) + return {'RUNNING_MODAL'} + class WM_OT_addon_install(Operator): "Install an addon" |