Add "Install Theme" button in user preferences, patch #31505 by Julien Duroure.
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Fri, 18 May 2012 12:49:27 +0000 (12:49 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Fri, 18 May 2012 12:49:27 +0000 (12:49 +0000)
release/scripts/startup/bl_operators/wm.py
release/scripts/startup/bl_ui/space_userpref.py

index c3638da5814e235a3555d223ec019cdadc35f610..883bac84e7898df29d54ce3986ff17121d9e43e8 100644 (file)
@@ -1545,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"
index 01a8f1c6dcbfa2c6b348ae39cd4db99f15601400..dec3960f37685d4cc21cfca146b08342fc368991 100644 (file)
@@ -96,6 +96,7 @@ class USERPREF_HT_header(Header):
             layout.menu("USERPREF_MT_addons_dev_guides")
         elif userpref.active_section == 'THEMES':
             layout.operator("ui.reset_default_theme")
+            layout.operator("wm.theme_install")
 
 
 class USERPREF_PT_tabs(Panel):