diff options
Diffstat (limited to 'release')
-rw-r--r-- | release/scripts/modules/bpy/utils.py | 6 | ||||
-rw-r--r-- | release/scripts/modules/rna_xml.py | 45 | ||||
-rw-r--r-- | release/scripts/startup/bl_operators/presets.py | 70 | ||||
-rw-r--r-- | release/scripts/startup/bl_operators/wm.py | 58 | ||||
-rw-r--r-- | release/scripts/startup/bl_ui/space_userpref.py | 6 |
5 files changed, 87 insertions, 98 deletions
diff --git a/release/scripts/modules/bpy/utils.py b/release/scripts/modules/bpy/utils.py index 6fd15c146f2..442d257b237 100644 --- a/release/scripts/modules/bpy/utils.py +++ b/release/scripts/modules/bpy/utils.py @@ -408,7 +408,7 @@ def smpte_from_frame(frame, fps=None, fps_base=None): return smpte_from_seconds((frame * fps_base) / fps, fps) -def preset_find(name, preset_path, display_name=False): +def preset_find(name, preset_path, display_name=False, ext=".py"): if not name: return None @@ -417,11 +417,11 @@ def preset_find(name, preset_path, display_name=False): if display_name: filename = "" for fn in _os.listdir(directory): - if fn.endswith(".py") and name == _bpy.path.display_name(fn): + if fn.endswith(ext) and name == _bpy.path.display_name(fn): filename = fn break else: - filename = name + ".py" + filename = name + ext if filename: filepath = _os.path.join(directory, filename) diff --git a/release/scripts/modules/rna_xml.py b/release/scripts/modules/rna_xml.py index 2b53ddcd941..9019728c014 100644 --- a/release/scripts/modules/rna_xml.py +++ b/release/scripts/modules/rna_xml.py @@ -307,9 +307,21 @@ def xml2rna(root_xml, # # This roughly matches the operator 'bpy.ops.script.python_file_run' +def _get_context_val(context, path): + path_full = "context." + path + try: + value = eval(path_full) + except: + import traceback + traceback.print_exc() + print("Error: %r could not be found" % path_full) + + value = Ellipsis + + return value + def xml_file_run(context, filepath, rna_map): - import rna_xml import xml.dom.minidom xml_nodes = xml.dom.minidom.parse(filepath) @@ -321,17 +333,24 @@ def xml_file_run(context, filepath, rna_map): # TODO, error check xml_node = bpy_xml.getElementsByTagName(xml_tag)[0] - # now get - rna_path_full = "context." + rna_path - try: - value = eval(rna_path_full) - except: - import traceback - traceback.print_exc() - print("Error: %r could not be found" % rna_path_full) - - value = Ellipsis + value = _get_context_val(context, rna_path) if value is not Ellipsis and value is not None: - print("Loading XML: %r" % rna_path_full) - rna_xml.xml2rna(xml_node, root_rna=value) + print(" loading XML: %r" % rna_path) + xml2rna(xml_node, root_rna=value) + + +def xml_file_write(context, filepath, rna_map): + + file = open(filepath, 'w', encoding='utf-8') + fw = file.write + + fw("<bpy>\n") + + for rna_path, xml_tag in rna_map: + # xml_tag is ignored, we get this from the rna + value = _get_context_val(context, rna_path) + rna2xml(fw, root_rna=value, method='ATTR') + + fw("</bpy>\n") + file.close() diff --git a/release/scripts/startup/bl_operators/presets.py b/release/scripts/startup/bl_operators/presets.py index f4524c328c1..0ba19ad8109 100644 --- a/release/scripts/startup/bl_operators/presets.py +++ b/release/scripts/startup/bl_operators/presets.py @@ -55,6 +55,13 @@ class AddPresetBase(): 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: @@ -71,32 +78,40 @@ class AddPresetBase(): self.report({'WARNING'}, "Failed to create presets path") return {'CANCELLED'} - filepath = os.path.join(target_path, filename) + ".py" + filepath = os.path.join(target_path, filename) + ext if hasattr(self, "add"): self.add(context, filepath) else: print("Writing Preset: %r" % filepath) - 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() + 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) @@ -104,12 +119,15 @@ class AddPresetBase(): preset_active = preset_menu_class.bl_label # fairly sloppy but convenient. - filepath = bpy.utils.preset_find(preset_active, self.preset_subdir) + 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) + display_name=True, + ext=ext) if not filepath: return {'CANCELLED'} @@ -397,6 +415,14 @@ class AddPresetTrackingSettings(AddPresetBase, Operator): preset_subdir = "tracking_settings" +class AddPresetInterfaceTheme(AddPresetBase, Operator): + '''Add a theme preset''' + bl_idname = "wm.interface_theme_preset_add" + bl_label = "Add Tracking Settings Preset" + preset_menu = "USERPREF_MT_interface_theme_presets" + preset_subdir = "interface_theme" + + class AddPresetKeyconfig(AddPresetBase, Operator): '''Add a Keyconfig Preset''' bl_idname = "wm.keyconfig_preset_add" diff --git a/release/scripts/startup/bl_operators/wm.py b/release/scripts/startup/bl_operators/wm.py index 8dbcbc4447e..d7f970218a5 100644 --- a/release/scripts/startup/bl_operators/wm.py +++ b/release/scripts/startup/bl_operators/wm.py @@ -1769,61 +1769,3 @@ class WM_OT_addon_expand(Operator): 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', - root_node="bpy" - ) - - return {'FINISHED'} diff --git a/release/scripts/startup/bl_ui/space_userpref.py b/release/scripts/startup/bl_ui/space_userpref.py index 5e95e02f1f4..804fb73e4c7 100644 --- a/release/scripts/startup/bl_ui/space_userpref.py +++ b/release/scripts/startup/bl_ui/space_userpref.py @@ -96,10 +96,12 @@ 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") + layout.label(text="Presets:") layout.menu("USERPREF_MT_interface_theme_presets", text=bpy.types.USERPREF_MT_interface_theme_presets.bl_label) + row = layout.row(align=True) + row.operator("wm.interface_theme_preset_add", text="", icon='ZOOMIN') + row.operator("wm.interface_theme_preset_add", text="", icon='ZOOMOUT').remove_active = True class USERPREF_PT_tabs(Panel): |