[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [43052] trunk/blender/release/scripts: rna_xml module - write colors as hexadecimal values, also swap import/ export order of key config buttons, since they didnt match other uses where import is first.

Campbell Barton ideasman42 at gmail.com
Sun Jan 1 11:05:09 CET 2012


Revision: 43052
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=43052
Author:   campbellbarton
Date:     2012-01-01 10:05:04 +0000 (Sun, 01 Jan 2012)
Log Message:
-----------
rna_xml module - write colors as hexadecimal values, also swap import/export order of key config buttons, since they didnt match other uses where import is first. 

Modified Paths:
--------------
    trunk/blender/release/scripts/modules/rna_xml.py
    trunk/blender/release/scripts/startup/bl_ui/space_userpref.py

Modified: trunk/blender/release/scripts/modules/rna_xml.py
===================================================================
--- trunk/blender/release/scripts/modules/rna_xml.py	2012-01-01 09:39:43 UTC (rev 43051)
+++ trunk/blender/release/scripts/modules/rna_xml.py	2012-01-01 10:05:04 UTC (rev 43052)
@@ -47,7 +47,7 @@
             root_node="",
             root_rna=None,  # must be set
             root_rna_skip=set(),
-            ident_val="  ",
+            ident_val="    ",
             skip_classes=(bpy.types.Operator,
                           bpy.types.Panel,
                           bpy.types.KeyingSet,
@@ -115,15 +115,29 @@
                     # check if the list contains native types
                     subvalue_rna = value.path_resolve(prop, False)
                     if type(subvalue_rna).__name__ == "bpy_prop_array":
-                        # TODO, multi-dim!
-                        def str_recursive(s):
-                            subsubvalue_type = type(s)
-                            if subsubvalue_type in (int, float, bool):
-                                return number_to_str(s, subsubvalue_type)
-                            else:
-                                return " ".join([str_recursive(si) for si in s])
+                        # check if this is a 0-1 color (rgb, rgba)
+                        # in that case write as a hexidecimal
+                        prop_rna = value.bl_rna.properties[prop]
+                        if (prop_rna.subtype == 'COLOR_GAMMA' and
+                                prop_rna.hard_min == 0.0 and
+                                prop_rna.hard_max == 1.0 and
+                                prop_rna.array_length in {3, 4}):
+                            # -----
+                            # color
+                            array_value = "#" + "".join(("%.2x" % int(v * 255) for v in subvalue_rna))
 
-                        node_attrs.append("%s=\"%s\"" % (prop, " ".join(str_recursive(v) for v in subvalue_rna)))
+                        else:
+                            # default
+                            def str_recursive(s):
+                                subsubvalue_type = type(s)
+                                if subsubvalue_type in (int, float, bool):
+                                    return number_to_str(s, subsubvalue_type)
+                                else:
+                                    return " ".join([str_recursive(si) for si in s])
+                            
+                            array_value = " ".join(str_recursive(v) for v in subvalue_rna)
+
+                        node_attrs.append("%s=\"%s\"" % (prop, array_value))
                     else:
                         nodes_lists.append((prop, subvalue_ls, subvalue_type))
 
@@ -224,11 +238,18 @@
                     value_xml_coerce = value_xml
                     tp_name = 'STR'
                 elif hasattr(subvalue, "__len__"):
-                    value_xml_split = value_xml.split()
-                    try:
-                        value_xml_coerce = [int(v) for v in value_xml_split]
-                    except ValueError:
-                        value_xml_coerce = [float(v) for v in value_xml_split]
+                    if value_xml.startswith("#"):
+                        # read hexidecimal value as float array
+                        value_xml_split = value_xml[1:]
+                        value_xml_coerce = [int(value_xml_split[i:i + 2], 16) / 255  for i in range(0, len(value_xml_split), 2)]
+                        del value_xml_split
+                    else:
+                        value_xml_split = value_xml.split()
+                        try:
+                            value_xml_coerce = [int(v) for v in value_xml_split]
+                        except ValueError:
+                            value_xml_coerce = [float(v) for v in value_xml_split]
+                        del value_xml_split
                     tp_name = 'ARRAY'
 
 #                print("  %s.%s (%s) --- %s" % (type(value).__name__, attr, tp_name, subvalue_type))

Modified: trunk/blender/release/scripts/startup/bl_ui/space_userpref.py
===================================================================
--- trunk/blender/release/scripts/startup/bl_ui/space_userpref.py	2012-01-01 09:39:43 UTC (rev 43051)
+++ trunk/blender/release/scripts/startup/bl_ui/space_userpref.py	2012-01-01 10:05:04 UTC (rev 43052)
@@ -89,8 +89,8 @@
         layout.operator_context = 'INVOKE_DEFAULT'
 
         if userpref.active_section == 'INPUT':
+            layout.operator("wm.keyconfig_import")
             layout.operator("wm.keyconfig_export")
-            layout.operator("wm.keyconfig_import")
         elif userpref.active_section == 'ADDONS':
             layout.operator("wm.addon_install")
             layout.menu("USERPREF_MT_addons_dev_guides")



More information about the Bf-blender-cvs mailing list