centralize docstring extraction in UI module

This commit is contained in:
Gorgious
2021-08-05 16:31:21 +02:00
parent efa1e245c5
commit e7a63d2a0b
2 changed files with 26 additions and 23 deletions
@@ -2,7 +2,6 @@ import os
import bpy
import json
import ifcpatch
from .helper import extract_docs
class SelectIfcPatchInput(bpy.types.Operator):
@@ -69,23 +68,21 @@ class ExecuteIfcPatch(bpy.types.Operator):
class PopulatePatchArguments(bpy.types.Operator):
bl_idname = "bim.populate_patch_arguments"
bl_label = "Update IFC Patch arguments"
recipe: bpy.props.StringProperty()
inputs: bpy.props.StringProperty()
def execute(self, context):
patch_args = context.scene.BIMPatchProperties.ifc_patch_args_attr
patch_args.clear()
docs = extract_docs(ifcpatch, self.recipe, "Patcher", "__init__", ("src", "file", "logger", "args"))
if "inputs" in docs:
for arg_name in docs["inputs"]:
arg_info = docs["inputs"][arg_name]
new_attr = patch_args.add()
new_attr.data_type = {
"str": "string",
"float": "float",
"int": "integer",
"bool": "boolean",
}[arg_info["type"]]
new_attr.name = arg_name
new_attr.set_value(arg_info.get("default", new_attr.get_value_default()))
new_attr.description = arg_info.get("description", "")
for name, _type, default, description in json.loads(self.inputs):
new_attr = patch_args.add()
new_attr.data_type = {
"str": "string",
"float": "float",
"int": "integer",
"bool": "boolean",
}[_type]
new_attr.name = name
if default is not None:
new_attr.set_value(default)
new_attr.description = description
return {"FINISHED"}
@@ -1,10 +1,9 @@
import bpy
import importlib
import importlib.util
import ifcpatch
from blenderbim.bim.helper import draw_attributes
from .helper import extract_docs
from .operator import PopulatePatchArguments
import json
class BIM_PT_patch(bpy.types.Panel):
@@ -23,7 +22,7 @@ class BIM_PT_patch(bpy.types.Panel):
scene = context.scene
props = scene.BIMPatchProperties
row = layout.row()
row.prop(props, "ifc_patch_recipes")
row.prop(props, "ifc_patch_recipes")
recipe = props.ifc_patch_recipes
@@ -41,9 +40,16 @@ class BIM_PT_patch(bpy.types.Panel):
row.prop(props, "ifc_patch_output")
row.operator("bim.select_ifc_patch_output", icon="FILE_FOLDER", text="")
op = layout.operator(PopulatePatchArguments.bl_idname)
op.recipe = recipe
if props.ifc_patch_args_attr and bool(docs["inputs"]):
update_args_op = layout.operator(PopulatePatchArguments.bl_idname)
update_args_op.inputs = json.dumps([
(
v["name"],
v["type"],
v.get("default", None),
v.get("description", "")
)
for v in docs.get("inputs", {}).values()])
if props.ifc_patch_args_attr and update_args_op.inputs:
draw_attributes(props.ifc_patch_args_attr, layout, show_description=True)
else:
row = layout.row()
@@ -51,4 +57,4 @@ class BIM_PT_patch(bpy.types.Panel):
row = layout.row()
op = row.operator("bim.execute_ifc_patch")
op.use_json_for_args = not bool(docs["inputs"])
op.use_json_for_args = not update_args_op.inputs