In UILayout there is really convenient option to set field as active in popup window. It allows you to support hotkey workflow - it activates some field and user will be able to type into it right away without clicking it first, then user can just hit enter and execute the operator.
It does work flawlessly if you add row.activate_init = True
before adding drawing prop with row.prop(self, "dummy_name", text='')
(where dummy_name
is StringProperty
).
But it doesn’t work at all if you use row.prop_search
. Is it possible to somehow make it work?
Example code (you can run it from script editor in default blender scene and then search for operators with “test popup” in F3 menu and call them to see the difference).
import bpy
class PopupOperatorText(bpy.types.Operator):
bl_idname = "test.popup_operator_text"
bl_label = "Popup Operator Test"
dummy_name: bpy.props.StringProperty(name="Property", default="test")
def invoke(self, context, event):
return context.window_manager.invoke_props_dialog(self)
def draw(self, context):
row = self.layout.row()
row.activate_init = True
row.prop(self, "dummy_name", text='')
def execute(self, context):
return {"FINISHED"}
class PopupOperatorPropSearch(bpy.types.Operator):
bl_idname = "test.popup_operator_prop_search"
bl_label = "Popup Operator Test Prop Search"
dummy_name: bpy.props.StringProperty(name="Property")
def invoke(self, context, event):
return context.window_manager.invoke_props_dialog(self)
def draw(self, context):
row = self.layout.row()
row.activate_init = True
row.prop_search(self, "dummy_name", bpy.data, "materials")
def execute(self, context):
return {"FINISHED"}
bpy.utils.register_class(PopupOperatorText)
bpy.utils.register_class(PopupOperatorPropSearch)