theme import/export - uses generic rna_xml py module.
authorCampbell Barton <ideasman42@gmail.com>
Sun, 1 Jan 2012 08:12:51 +0000 (08:12 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sun, 1 Jan 2012 08:12:51 +0000 (08:12 +0000)
release/scripts/startup/bl_operators/wm.py
release/scripts/startup/bl_ui/space_userpref.py

index 4f498e72f4b4b40ce288d8799d7e1dc8ec017697..cf6d62a330b0d2e6c0e51cf5a74d2f910cb1e61a 100644 (file)
@@ -1462,6 +1462,8 @@ class WM_OT_operator_cheat_sheet(Operator):
         self.report({'INFO'}, "See OperatorList.txt textblock")
         return {'FINISHED'}
 
+# -----------------------------------------------------------------------------
+# Addon Operators
 
 class WM_OT_addon_enable(Operator):
     "Enable an addon"
@@ -1762,3 +1764,61 @@ class WM_OT_addon_expand(Operator):
         info = addon_utils.module_bl_info(mod)
         info["show_expanded"] = not info["show_expanded"]
         return {'FINISHED'}
+
+
+# -----------------------------------------------------------------------------
+# Theme IO
+from bpy_extras.io_utils import (ImportHelper,
+                                 ExportHelper,
+                                 )
+
+
+class WM_OT_theme_import(Operator, ImportHelper):
+    bl_idname = "wm.theme_import"
+    bl_label = "Import Theme"
+    bl_options = {'REGISTER', 'UNDO'}
+
+    filename_ext = ".xml"
+    filter_glob = StringProperty(default="*.xml", options={'HIDDEN'})
+
+    def execute(self, context):
+        import rna_xml
+        import xml.dom.minidom
+
+        filepath = self.filepath
+
+        xml_nodes = xml.dom.minidom.parse(filepath)
+        theme_xml = xml_nodes.getElementsByTagName("Theme")[0]
+
+        # XXX, why always 0?, allow many?
+        theme = context.user_preferences.themes[0]
+
+        rna_xml.xml2rna(theme_xml,
+                        root_rna=theme,
+                        )
+
+        return {'FINISHED'}
+
+
+class WM_OT_theme_export(Operator, ExportHelper):
+    bl_idname = "wm.theme_export"
+    bl_label = "Export Theme"
+
+    filename_ext = ".xml"
+    filter_glob = StringProperty(default="*.xml", options={'HIDDEN'})
+
+    def execute(self, context):
+        import rna_xml
+        
+        filepath = self.filepath
+        file = open(filepath, 'w', encoding='utf-8')
+
+        # XXX, why always 0?, allow many?
+        theme = context.user_preferences.themes[0]
+
+        rna_xml.rna2xml(file.write,
+                        root_rna=theme,
+                        method='ATTR',
+                        )
+
+        return {'FINISHED'}
index df8c085d77efe87da966271ce593073c986b29ad..09286287541480241a27cfd36807c0f026191413 100644 (file)
@@ -96,6 +96,8 @@ 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_import")
+            layout.operator("wm.theme_export")
 
 
 class USERPREF_PT_tabs(Panel):