Changeset View
Changeset View
Standalone View
Standalone View
release/scripts/startup/bl_operators/presets.py
| Show First 20 Lines • Show All 71 Lines • ▼ Show 20 Lines | def as_filename(name): # could reuse for other presets | ||||
| attr = "_as_filename_trans" | attr = "_as_filename_trans" | ||||
| trans = getattr(cls, attr, None) | trans = getattr(cls, attr, None) | ||||
| if trans is None: | if trans is None: | ||||
| trans = str.maketrans({char: "_" for char in " !@#$%^&*(){}:\";'[]<>,.\\/?"}) | trans = str.maketrans({char: "_" for char in " !@#$%^&*(){}:\";'[]<>,.\\/?"}) | ||||
| setattr(cls, attr, trans) | setattr(cls, attr, trans) | ||||
| return trans | return trans | ||||
| name = name.lower().strip() | name = name.strip() | ||||
| name = bpy.path.display_name_to_filepath(name) | name = bpy.path.display_name_to_filepath(name) | ||||
| trans = maketrans_init() | trans = maketrans_init() | ||||
| # Strip surrounding "_" as they are displayed as spaces. | # Strip surrounding "_" as they are displayed as spaces. | ||||
| return name.translate(trans).strip("_") | return name.translate(trans).strip("_") | ||||
| def execute(self, context): | def execute(self, context): | ||||
| import os | import os | ||||
| from bpy.utils import is_path_builtin | from bpy.utils import is_path_builtin | ||||
| ▲ Show 20 Lines • Show All 155 Lines • ▼ Show 20 Lines | class ExecutePreset(Operator): | ||||
| ) | ) | ||||
| def execute(self, context): | def execute(self, context): | ||||
| from os.path import basename, splitext | from os.path import basename, splitext | ||||
| filepath = self.filepath | filepath = self.filepath | ||||
| # change the menu title to the most recently chosen option | # change the menu title to the most recently chosen option | ||||
| preset_class = getattr(bpy.types, self.menu_idname) | preset_class = getattr(bpy.types, self.menu_idname) | ||||
| preset_class.bl_label = bpy.path.display_name(basename(filepath)) | preset_class.bl_label = bpy.path.display_name(basename(filepath), title_case=False) | ||||
| ext = splitext(filepath)[1].lower() | ext = splitext(filepath)[1].lower() | ||||
natecraddock: The extension should be converted to lowercase. The extension is loaded from disk, and if for… | |||||
| if ext not in {".py", ".xml"}: | if ext not in {".py", ".xml"}: | ||||
| self.report({'ERROR'}, "Unknown file type: %r" % ext) | self.report({'ERROR'}, "Unknown file type: %r" % ext) | ||||
| return {'CANCELLED'} | return {'CANCELLED'} | ||||
| if hasattr(preset_class, "reset_cb"): | if hasattr(preset_class, "reset_cb"): | ||||
| preset_class.reset_cb(context) | preset_class.reset_cb(context) | ||||
| ▲ Show 20 Lines • Show All 455 Lines • Show Last 20 Lines | |||||
The extension should be converted to lowercase. The extension is loaded from disk, and if for some reason the file extension was changed from .py to .PY then the preset would fail to load.