use path_resolve instead of eval

This commit is contained in:
Gorgious
2022-01-23 23:01:19 +01:00
parent 4ad5f5cbf4
commit cc790c0a09
2 changed files with 15 additions and 14 deletions
+5 -5
View File
@@ -30,13 +30,10 @@ def draw_attributes(props, layout, copy_operator=None):
prefs = bpy.context.preferences.addons["blenderbim"].preferences prefs = bpy.context.preferences.addons["blenderbim"].preferences
for i, attribute in enumerate(props): for i, attribute in enumerate(props):
row = layout.row(align=True) row = layout.row(align=True)
draw_attribute(attribute, row, copy_operator) draw_attribute(attribute, row, copy_operator, prefs.info_mode)
if prefs.info_mode:
info = row.operator("bim.show_attribute_documentation", icon="INFO", text="")
info.path = f"context.scene.{props.path_from_id()}[{i}].doc"
def draw_attribute(attribute, layout, copy_operator=None): def draw_attribute(attribute, layout, copy_operator=None, info_mode=False):
value_name = attribute.get_value_name() value_name = attribute.get_value_name()
if not value_name: if not value_name:
layout.label(text=attribute.name) layout.label(text=attribute.name)
@@ -51,6 +48,9 @@ def draw_attribute(attribute, layout, copy_operator=None):
if copy_operator: if copy_operator:
op = layout.operator(f"{copy_operator}", text="", icon="COPYDOWN") op = layout.operator(f"{copy_operator}", text="", icon="COPYDOWN")
op.name = attribute.name op.name = attribute.name
if info_mode:
info_op = layout.operator("bim.show_attribute_documentation", icon="INFO", text="")
info_op.path = f"{attribute.path_from_id()}"
def import_attributes(ifc_class, props, data, callback=None): def import_attributes(ifc_class, props, data, callback=None):
+4 -3
View File
@@ -371,8 +371,9 @@ class BIM_OT_open_webbrowser(bpy.types.Operator):
def execute(self, context): def execute(self, context):
import webbrowser import webbrowser
webbrowser.open(self.url) webbrowser.open(self.url)
return {'FINISHED'} return {"FINISHED"}
class BIM_OT_show_attribute_documentation(bpy.types.Operator): class BIM_OT_show_attribute_documentation(bpy.types.Operator):
@@ -382,13 +383,13 @@ class BIM_OT_show_attribute_documentation(bpy.types.Operator):
path: bpy.props.StringProperty() path: bpy.props.StringProperty()
def execute(self, context): def execute(self, context):
return {'FINISHED'} return {"FINISHED"}
def invoke(self, context, event): def invoke(self, context, event):
return context.window_manager.invoke_props_dialog(self) return context.window_manager.invoke_props_dialog(self)
def draw(self, context): def draw(self, context):
doc = eval(self.path) doc = context.scene.path_resolve(self.path)
doc.draw(self.layout) doc.draw(self.layout)