style changes for operator scripts & some pep8 edits.

This commit is contained in:
2011-07-25 06:40:16 +00:00
parent 6065390f4c
commit 4f4eeb826a
5 changed files with 254 additions and 125 deletions

View File

@@ -16,7 +16,7 @@
#
# ##### END GPL LICENSE BLOCK #####
# <pep8 compliant>
# <pep8-80 compliant>
import bpy
@@ -30,8 +30,15 @@ class AddPresetBase():
# bl_label = "Add a Python Preset"
bl_options = {'REGISTER'} # only because invoke_props_popup requires.
name = bpy.props.StringProperty(name="Name", description="Name of the preset, used to make the path name", maxlen=64, default="")
remove_active = bpy.props.BoolProperty(default=False, options={'HIDDEN'})
name = bpy.props.StringProperty(
name="Name",
description="Name of the preset, used to make the path name",
maxlen=64,
)
remove_active = bpy.props.BoolProperty(
default=False,
options={'HIDDEN'},
)
@staticmethod
def as_filename(name): # could reuse for other presets
@@ -54,7 +61,10 @@ class AddPresetBase():
filename = self.as_filename(name)
target_path = bpy.utils.user_resource('SCRIPTS', os.path.join("presets", self.preset_subdir), create=True)
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")
@@ -95,7 +105,9 @@ class AddPresetBase():
filepath = bpy.utils.preset_find(preset_active, self.preset_subdir)
if not filepath:
filepath = bpy.utils.preset_find(preset_active, self.preset_subdir, display_name=True)
filepath = bpy.utils.preset_find(preset_active,
self.preset_subdir,
display_name=True)
if not filepath:
return {'CANCELLED'}
@@ -133,8 +145,15 @@ class ExecutePreset(bpy.types.Operator):
bl_idname = "script.execute_preset"
bl_label = "Execute a Python Preset"
filepath = bpy.props.StringProperty(name="Path", description="Path of the Python file to execute", maxlen=512, default="")
menu_idname = bpy.props.StringProperty(name="Menu ID Name", description="ID name of the menu this was called from", default="")
filepath = bpy.props.StringProperty(
name="Path",
description="Path of the Python file to execute",
maxlen=512,
)
menu_idname = bpy.props.StringProperty(
name="Menu ID Name",
description="ID name of the menu this was called from",
)
def execute(self, context):
from os.path import basename
@@ -182,7 +201,10 @@ class AddPresetSSS(AddPresetBase, bpy.types.Operator):
preset_menu = "MATERIAL_MT_sss_presets"
preset_defines = [
"material = (bpy.context.material.active_node_material if bpy.context.material.active_node_material else bpy.context.material)"
("material = "
"bpy.context.material.active_node_material "
"if bpy.context.material.active_node_material "
"else bpy.context.material")
]
preset_values = [
@@ -306,7 +328,11 @@ class AddPresetOperator(AddPresetBase, bpy.types.Operator):
bl_label = "Operator Preset"
preset_menu = "WM_MT_operator_presets"
operator = bpy.props.StringProperty(name="Operator", maxlen=64, options={'HIDDEN'})
operator = bpy.props.StringProperty(
name="Operator",
maxlen=64,
options={'HIDDEN'},
)
# XXX, not ideal
preset_defines = [
@@ -322,12 +348,15 @@ class AddPresetOperator(AddPresetBase, bpy.types.Operator):
properties_blacklist = bpy.types.Operator.bl_rna.properties.keys()
prefix, suffix = self.operator.split("_OT_", 1)
operator_rna = getattr(getattr(bpy.ops, prefix.lower()), suffix).get_rna().bl_rna
op = getattr(getattr(bpy.ops, prefix.lower()), suffix)
operator_rna = op.get_rna().bl_rna
del op
ret = []
for prop_id, prop in operator_rna.properties.items():
if (not (prop.is_hidden or prop.is_skip_save)) and prop_id not in properties_blacklist:
ret.append("op.%s" % prop_id)
if not (prop.is_hidden or prop.is_skip_save):
if prop_id not in properties_blacklist:
ret.append("op.%s" % prop_id)
return ret