I´m using the "invoke_search_popup" method of the Window Manager to create a search box which enables me to find some items in a predefined collection of objects.
The thing is, that sometimes I switch from some type of collection to another. Let´s say that I first search in a collection of Objects, and then in a collection of Groups. If I just selected an Object the first time, on the next one it´s name will appear as a suggestion or as the "last item used" in the name field of the new Groups search box, filtering all search results.
I understand that this happens globally because the window manager instance is created once, and then on, used again and again. So I want to know if at least there is some way to recreate or reload the instance, so that the name field becomes empty again.
It happens that when working on long sessions it´s annoying to first have to delete the name field everytime to clean the search results. I would like to have it clean everytime I call it, because it makes much more sense for the workflow I´m using. If there´s a way to achieve this, I could even clean it only when switching collections type, which is smarter.
Try this code. Select an item, and then, call the script again.
import bpy
class Operator(bpy.types.Operator):
bl_idname = "operator.menu"
bl_label = "Search"
bl_description = "Whatever"
bl_options = {'REGISTER', 'INTERNAL'}
bl_property = "enum"
def scene_items(self, context):
return [(ob.name, ob.name, '') for ob in bpy.data.objects]
enum = bpy.props.EnumProperty(items=scene_items)
def execute(self, context):
self.report({'INFO'}, "The item just got selected")
return {"FINISHED"}
def invoke(self, context, event):
context.window_manager.invoke_search_popup(self)
return {"FINISHED"}
def register():
bpy.utils.register_module(__name__)
def unregister():
bpy.utils.unregister_module(__name__)
if __name__ == "__main__":
register()
bpy.ops.operator.menu("INVOKE_DEFAULT")