def update(filepath): import rna_xml context = bpy.context print("Updating theme: %r" % filepath) preset_xml_map = ( ("user_preferences.themes[0]", "Theme"), ("user_preferences.ui_styles[0]", "Theme"), ) rna_xml.xml_file_run(context, filepath, preset_xml_map) rna_xml.xml_file_write(context, filepath, preset_xml_map)
def update(filepath): import rna_xml context = bpy.context print("Updating theme: %r" % filepath) preset_xml_map = (("user_preferences.themes[0]", "Theme"), ) rna_xml.xml_file_run(context, filepath, preset_xml_map) rna_xml.xml_file_write(context, filepath, preset_xml_map)
def execute(self, context): import os if hasattr(self, "pre_cb"): self.pre_cb(context) preset_menu_class = getattr(bpy.types, self.preset_menu) is_xml = getattr(preset_menu_class, "preset_type", None) == 'XML' if is_xml: ext = ".xml" else: ext = ".py" if not self.remove_active: name = self.name.strip() if not name: return {'FINISHED'} filename = self.as_filename(name) target_path = os.path.join("presets", self.preset_subdir) target_path = bpy.utils.user_resource('SCRIPTS', target_path, create=True) if not target_path: self.report({'WARNING'}, "Failed to create presets path") return {'CANCELLED'} filepath = os.path.join(target_path, filename) + ext if hasattr(self, "add"): self.add(context, filepath) else: print("Writing Preset: %r" % filepath) if is_xml: import rna_xml rna_xml.xml_file_write(context, filepath, preset_menu_class.preset_xml_map) else: def rna_recursive_attr_expand(value, rna_path_step, level): if isinstance(value, bpy.types.PropertyGroup): for sub_value_attr in value.bl_rna.properties.keys( ): if sub_value_attr == "rna_type": continue sub_value = getattr(value, sub_value_attr) rna_recursive_attr_expand( sub_value, "%s.%s" % (rna_path_step, sub_value_attr), level) elif type( value ).__name__ == "bpy_prop_collection_idprop": # could use nicer method file_preset.write("%s.clear()\n" % rna_path_step) for sub_value in value: file_preset.write("item_sub_%d = %s.add()\n" % (level, rna_path_step)) rna_recursive_attr_expand( sub_value, "item_sub_%d" % level, level + 1) else: # convert thin wrapped sequences # to simple lists to repr() try: value = value[:] except: pass file_preset.write("%s = %r\n" % (rna_path_step, value)) file_preset = open(filepath, 'w') file_preset.write("import bpy\n") if hasattr(self, "preset_defines"): for rna_path in self.preset_defines: exec(rna_path) file_preset.write("%s\n" % rna_path) file_preset.write("\n") for rna_path in self.preset_values: value = eval(rna_path) rna_recursive_attr_expand(value, rna_path, 1) file_preset.close() preset_menu_class.bl_label = bpy.path.display_name(filename) else: preset_active = preset_menu_class.bl_label # fairly sloppy but convenient. filepath = bpy.utils.preset_find(preset_active, self.preset_subdir, ext=ext) if not filepath: filepath = bpy.utils.preset_find(preset_active, self.preset_subdir, display_name=True, ext=ext) if not filepath: return {'CANCELLED'} if hasattr(self, "remove"): self.remove(context, filepath) else: try: os.remove(filepath) except: import traceback traceback.print_exc() # XXX, stupid! preset_menu_class.bl_label = "Presets" if hasattr(self, "post_cb"): self.post_cb(context) return {'FINISHED'}
def execute(self, context): import os if hasattr(self, "pre_cb"): self.pre_cb(context) preset_menu_class = getattr(bpy.types, self.preset_menu) is_xml = getattr(preset_menu_class, "preset_type", None) == "XML" if is_xml: ext = ".xml" else: ext = ".py" if not self.remove_active: name = self.name.strip() if not name: return {"FINISHED"} filename = self.as_filename(name) target_path = os.path.join("presets", self.preset_subdir) target_path = bpy.utils.user_resource("SCRIPTS", target_path, create=True) if not target_path: self.report({"WARNING"}, "Failed to create presets path") return {"CANCELLED"} filepath = os.path.join(target_path, filename) + ext if hasattr(self, "add"): self.add(context, filepath) else: print("Writing Preset: %r" % filepath) if is_xml: import rna_xml rna_xml.xml_file_write(context, filepath, preset_menu_class.preset_xml_map) else: def rna_recursive_attr_expand(value, rna_path_step, level): if isinstance(value, bpy.types.PropertyGroup): for sub_value_attr in value.bl_rna.properties.keys(): if sub_value_attr == "rna_type": continue sub_value = getattr(value, sub_value_attr) rna_recursive_attr_expand(sub_value, "%s.%s" % (rna_path_step, sub_value_attr), level) elif type(value).__name__ == "bpy_prop_collection_idprop": # could use nicer method file_preset.write("%s.clear()\n" % rna_path_step) for sub_value in value: file_preset.write("item_sub_%d = %s.add()\n" % (level, rna_path_step)) rna_recursive_attr_expand(sub_value, "item_sub_%d" % level, level + 1) else: # convert thin wrapped sequences # to simple lists to repr() try: value = value[:] except: pass file_preset.write("%s = %r\n" % (rna_path_step, value)) file_preset = open(filepath, "w") file_preset.write("import bpy\n") if hasattr(self, "preset_defines"): for rna_path in self.preset_defines: exec(rna_path) file_preset.write("%s\n" % rna_path) file_preset.write("\n") for rna_path in self.preset_values: value = eval(rna_path) rna_recursive_attr_expand(value, rna_path, 1) file_preset.close() preset_menu_class.bl_label = bpy.path.display_name(filename) else: preset_active = preset_menu_class.bl_label # fairly sloppy but convenient. filepath = bpy.utils.preset_find(preset_active, self.preset_subdir, ext=ext) if not filepath: filepath = bpy.utils.preset_find(preset_active, self.preset_subdir, display_name=True, ext=ext) if not filepath: return {"CANCELLED"} if hasattr(self, "remove"): self.remove(context, filepath) else: try: os.remove(filepath) except: import traceback traceback.print_exc() # XXX, stupid! preset_menu_class.bl_label = "Presets" if hasattr(self, "post_cb"): self.post_cb(context) return {"FINISHED"}
def execute(self, context): import os if hasattr(self, "pre_cb"): self.pre_cb(context) preset_menu_class = getattr(bpy.types, self.preset_menu) is_xml = getattr(preset_menu_class, "preset_type", None) == 'XML' if is_xml: ext = ".xml" else: ext = ".py" if not self.remove_active: name = self.name.strip() if not name: return {'FINISHED'} filename = self.as_filename(name) target_path = os.path.join("presets", self.preset_subdir) target_path = bpy.utils.user_resource('SCRIPTS', target_path, create=True) if not target_path: self.report({'WARNING'}, "Failed to create presets path") return {'CANCELLED'} filepath = os.path.join(target_path, filename) + ext if hasattr(self, "add"): self.add(context, filepath) else: print("Writing Preset: %r" % filepath) if is_xml: import rna_xml rna_xml.xml_file_write(context, filepath, preset_menu_class.preset_xml_map) else: file_preset = open(filepath, 'w') file_preset.write("import bpy\n") if hasattr(self, "preset_defines"): for rna_path in self.preset_defines: exec(rna_path) file_preset.write("%s\n" % rna_path) file_preset.write("\n") for rna_path in self.preset_values: value = eval(rna_path) # convert thin wrapped sequences # to simple lists to repr() try: value = value[:] except: pass file_preset.write("%s = %r\n" % (rna_path, value)) file_preset.close() preset_menu_class.bl_label = bpy.path.display_name(filename) else: preset_active = preset_menu_class.bl_label # fairly sloppy but convenient. filepath = bpy.utils.preset_find(preset_active, self.preset_subdir, ext=ext) if not filepath: filepath = bpy.utils.preset_find(preset_active, self.preset_subdir, display_name=True, ext=ext) if not filepath: return {'CANCELLED'} if hasattr(self, "remove"): self.remove(context, filepath) else: try: os.remove(filepath) except: import traceback traceback.print_exc() # XXX, stupid! preset_menu_class.bl_label = "Presets" if hasattr(self, "post_cb"): self.post_cb(context) return {'FINISHED'}