[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [43048] trunk/blender/release/scripts/ startup: theme import/export - uses generic rna_xml py module.

Campbell Barton ideasman42 at gmail.com
Sun Jan 1 09:12:52 CET 2012


Revision: 43048
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=43048
Author:   campbellbarton
Date:     2012-01-01 08:12:51 +0000 (Sun, 01 Jan 2012)
Log Message:
-----------
theme import/export - uses generic rna_xml py module.

Modified Paths:
--------------
    trunk/blender/release/scripts/startup/bl_operators/wm.py
    trunk/blender/release/scripts/startup/bl_ui/space_userpref.py

Modified: trunk/blender/release/scripts/startup/bl_operators/wm.py
===================================================================
--- trunk/blender/release/scripts/startup/bl_operators/wm.py	2012-01-01 08:09:30 UTC (rev 43047)
+++ trunk/blender/release/scripts/startup/bl_operators/wm.py	2012-01-01 08:12:51 UTC (rev 43048)
@@ -1462,6 +1462,8 @@
         self.report({'INFO'}, "See OperatorList.txt textblock")
         return {'FINISHED'}
 
+# -----------------------------------------------------------------------------
+# Addon Operators
 
 class WM_OT_addon_enable(Operator):
     "Enable an addon"
@@ -1762,3 +1764,61 @@
         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'}

Modified: trunk/blender/release/scripts/startup/bl_ui/space_userpref.py
===================================================================
--- trunk/blender/release/scripts/startup/bl_ui/space_userpref.py	2012-01-01 08:09:30 UTC (rev 43047)
+++ trunk/blender/release/scripts/startup/bl_ui/space_userpref.py	2012-01-01 08:12:51 UTC (rev 43048)
@@ -96,6 +96,8 @@
             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):




More information about the Bf-blender-cvs mailing list