mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-26 10:11:46 +00:00
Fix AttributeError by removing duplicate bim.enum_property_search operator
The light module (PR #5452) defined its own EnumPropertySearch class with bl_idname = "bim.enum_property_search", conflicting with the main BIM_OT_enum_property_search in operator.py. The light module's version lacked should_click_ok and other properties, so whichever class registered last caused an AttributeError when helper.py tried to set op.should_click_ok. Remove the duplicate EnumPropertySearch and SetEnumProperty operators from light/operator.py and __init__.py entirely, and replace the local prop_with_search/get_enum_items helpers in light/ui.py with an import of the canonical prop_with_search from bonsai.bim.helper. Generated with the assistance of an AI coding tool.
This commit is contained in:
@@ -48,9 +48,7 @@ classes = (
|
|||||||
operator.RADIANCE_OT_export_material_mappings,
|
operator.RADIANCE_OT_export_material_mappings,
|
||||||
operator.RADIANCE_OT_import_material_mappings,
|
operator.RADIANCE_OT_import_material_mappings,
|
||||||
operator.RADIANCE_OT_open_spectraldb,
|
operator.RADIANCE_OT_open_spectraldb,
|
||||||
operator.EnumPropertySearch,
|
|
||||||
operator.PrepareRadianceScene,
|
operator.PrepareRadianceScene,
|
||||||
operator.SetEnumProperty,
|
|
||||||
operator.AddIESLight,
|
operator.AddIESLight,
|
||||||
operator.RemoveIESLight,
|
operator.RemoveIESLight,
|
||||||
operator.SetIESLightObject,
|
operator.SetIESLightObject,
|
||||||
|
|||||||
@@ -1036,49 +1036,6 @@ class RADIANCE_OT_open_spectraldb(bpy.types.Operator):
|
|||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
class EnumPropertySearch(bpy.types.Operator):
|
|
||||||
bl_idname = "radiance.enum_property_search"
|
|
||||||
bl_label = "Search Enum Property"
|
|
||||||
bl_options = {"REGISTER", "UNDO"}
|
|
||||||
|
|
||||||
prop_name: bpy.props.StringProperty()
|
|
||||||
search_term: bpy.props.StringProperty()
|
|
||||||
|
|
||||||
def execute(self, context):
|
|
||||||
data = context.space_data.context_pointer_get("data")
|
|
||||||
enum_items = get_enum_items(data, self.prop_name)
|
|
||||||
filtered_items = [item for item in enum_items if self.search_term.lower() in item[1].lower()]
|
|
||||||
|
|
||||||
def draw_menu(self, context):
|
|
||||||
layout = self.layout
|
|
||||||
for item in filtered_items:
|
|
||||||
props = layout.operator("bim.set_enum_property", text=item[1])
|
|
||||||
props.prop_name = self.prop_name
|
|
||||||
props.enum_value = item[0]
|
|
||||||
|
|
||||||
bpy.context.window_manager.popup_menu(draw_menu, title="Search Results", icon="VIEWZOOM")
|
|
||||||
return {"FINISHED"}
|
|
||||||
|
|
||||||
def invoke(self, context, event):
|
|
||||||
return context.window_manager.invoke_props_dialog(self)
|
|
||||||
|
|
||||||
def draw(self, context):
|
|
||||||
self.layout.prop(self, "search_term", text="Search")
|
|
||||||
|
|
||||||
|
|
||||||
class SetEnumProperty(bpy.types.Operator):
|
|
||||||
bl_idname = "bim.set_enum_property"
|
|
||||||
bl_label = "Set Enum Property"
|
|
||||||
bl_options = {"REGISTER", "UNDO"}
|
|
||||||
|
|
||||||
prop_name: bpy.props.StringProperty()
|
|
||||||
enum_value: bpy.props.StringProperty()
|
|
||||||
|
|
||||||
def execute(self, context):
|
|
||||||
data = context.space_data.context_pointer_get("data")
|
|
||||||
setattr(data, self.prop_name, self.enum_value)
|
|
||||||
return {"FINISHED"}
|
|
||||||
|
|
||||||
|
|
||||||
def convert_ies_to_radiance(
|
def convert_ies_to_radiance(
|
||||||
ies_file_path: str,
|
ies_file_path: str,
|
||||||
|
|||||||
@@ -22,31 +22,10 @@ from typing import TYPE_CHECKING
|
|||||||
import bpy
|
import bpy
|
||||||
|
|
||||||
import bonsai.tool as tool
|
import bonsai.tool as tool
|
||||||
|
from bonsai.bim.helper import prop_with_search
|
||||||
from bonsai.bim.module.light.data import SolarData
|
from bonsai.bim.module.light.data import SolarData
|
||||||
|
|
||||||
|
|
||||||
def get_enum_items(data, prop_name, context=None):
|
|
||||||
prop = data.__annotations__[prop_name]
|
|
||||||
items = prop.keywords.get("items")
|
|
||||||
if items is None:
|
|
||||||
return
|
|
||||||
if not isinstance(items, (list, tuple)):
|
|
||||||
items = items(data, context or bpy.context)
|
|
||||||
return items
|
|
||||||
|
|
||||||
|
|
||||||
def prop_with_search(layout, data, prop_name, **kwargs):
|
|
||||||
row = layout.row(align=True)
|
|
||||||
row.prop(data, prop_name, **kwargs)
|
|
||||||
try:
|
|
||||||
if len(get_enum_items(data, prop_name)) > 10:
|
|
||||||
row.context_pointer_set(name="data", data=data)
|
|
||||||
op = row.operator("radiance.enum_property_search", text="", icon="VIEWZOOM")
|
|
||||||
op.prop_name = prop_name
|
|
||||||
except TypeError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class BIM_PT_radiance_exporter(bpy.types.Panel):
|
class BIM_PT_radiance_exporter(bpy.types.Panel):
|
||||||
"""Creates a Panel in the render properties window"""
|
"""Creates a Panel in the render properties window"""
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user