From fd13cd6c13d06f7bab2241716d1dac5dbc1e054b Mon Sep 17 00:00:00 2001 From: Ryan Schultz Date: Wed, 11 Mar 2026 17:44:47 -0500 Subject: [PATCH] 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. --- .../bonsai/bim/module/light/__init__.py | 2 - .../bonsai/bim/module/light/operator.py | 43 ------------------- src/bonsai/bonsai/bim/module/light/ui.py | 23 +--------- 3 files changed, 1 insertion(+), 67 deletions(-) diff --git a/src/bonsai/bonsai/bim/module/light/__init__.py b/src/bonsai/bonsai/bim/module/light/__init__.py index 82e1187d4e..16e3042250 100644 --- a/src/bonsai/bonsai/bim/module/light/__init__.py +++ b/src/bonsai/bonsai/bim/module/light/__init__.py @@ -48,9 +48,7 @@ classes = ( operator.RADIANCE_OT_export_material_mappings, operator.RADIANCE_OT_import_material_mappings, operator.RADIANCE_OT_open_spectraldb, - operator.EnumPropertySearch, operator.PrepareRadianceScene, - operator.SetEnumProperty, operator.AddIESLight, operator.RemoveIESLight, operator.SetIESLightObject, diff --git a/src/bonsai/bonsai/bim/module/light/operator.py b/src/bonsai/bonsai/bim/module/light/operator.py index b13d603121..e83cece9f1 100644 --- a/src/bonsai/bonsai/bim/module/light/operator.py +++ b/src/bonsai/bonsai/bim/module/light/operator.py @@ -1036,49 +1036,6 @@ class RADIANCE_OT_open_spectraldb(bpy.types.Operator): 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( ies_file_path: str, diff --git a/src/bonsai/bonsai/bim/module/light/ui.py b/src/bonsai/bonsai/bim/module/light/ui.py index c8ec0f1552..8fcfe563a3 100644 --- a/src/bonsai/bonsai/bim/module/light/ui.py +++ b/src/bonsai/bonsai/bim/module/light/ui.py @@ -22,31 +22,10 @@ from typing import TYPE_CHECKING import bpy import bonsai.tool as tool +from bonsai.bim.helper import prop_with_search 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): """Creates a Panel in the render properties window"""