My question is not about the File Browser modal window, but about the Editor.
I found this other question that shows how to get the selected files from the File Browser Editor
via Python, but I would like to know when the user clicks on a file to update my add-on dynamically. I can't find a handler that triggers a callback on file click, so I'm thinking this isn't possible. I could kludge it and poll for the currently selected file, but that is less than ideal. I could also go hard-core and build an entire Python UI for selecting files, but it just seems silly to go that route since the UI already exists in C.
Am I right in concluding that the only use for the File Browser Editor
is for the user to see files and drag/drop them into other editors?
(Alternatively, I could use the Outliner Editor
, filter for images, and use that for selection. But again, I can't find a handler that calls me back when the user clicks on an image.)
Edit
A solution was discovered after being inspired by the answers given:
import bpy
import os
def fbDraw(panel, context):
layout: bpy.types.UILayout = panel.layout
area = next((a for a in context.screen.areas if a.type == "FILE_BROWSER"), None)
if area:
params = area.spaces.active.params
# Pretend code follows:
info = params.filename if '_PT_' in panel.bl_idname else params.directory.decode()
info = info.replace(os.path.sep, '/')
layout.label(text=f'{panel.bl_idname}: {info}')
def register():
# Either of these would work
bpy.types.FILEBROWSER_HT_header.append(fbDraw)
bpy.types.FILEBROWSER_PT_directory_path.prepend(fbDraw)
def unregister():
bpy.types.FILEBROWSER_HT_header.remove(fbDraw)
bpy.types.FILEBROWSER_PT_directory_path.remove(fbDraw)
(More info in my answer below)
asset_data
), i.e., clicking an asset doesn't trigger any handler. Note: I put a callback in every single handler available, for testing. $\endgroup$