Is there an operator I can call for closing Blender preferences pane? I can open it to show my addon prefs with
bpy.ops.preferences.addon_show(module=<myaddon>)
But what about closing? Scrubbed throu the docs to find nothing.
If the Preferences window is the active one you can use bpy.ops.wm.window_close()
Otherwise you have to overwrite the context.
With Blender 3.2 there was a change.
Now we better use Context.temp_override(window, area, region, **keywords)
for this.
The following example should work with all versions:
edited: thanks to scurest
import bpy
bpy.ops.preferences.addon_show(module='io_scene_obj') # example
for window in bpy.context.window_manager.windows: # searching preference window
screen = window.screen
for area in screen.areas:
if area.type == 'PREFERENCES':
# Blender 3.2 and more
if bpy.app.version >= (3, 2, 0):
from bpy import context
with context.temp_override(window=window, area=area):
bpy.ops.wm.window_close()
# Blender < 3.2 with override context
else:
override = {'window': window, 'screen': screen, 'area': area}
bpy.ops.wm.window_close(override)
break