As per question, I would like to build a function that is only executed upon opening the blender preferences. But I checked in the Blender API under bpy.app.handlers, and found nothing. Anyone have any idea how to do it, if it is possible?

The basic idea is to run this function when my addon is shown "Open" in the addon preferences. Such a thing if it existed: -->bpy.app.handrers.on_my_addon_preferences_open"""<--

I would like to be sure that I consume few resources, as I have to be careful not to overload the work at all. I think I could use various handrers and do the trick. But I'm sure there is someone here who can perhaps suggest me the best way to make a sensible system

  • $\begingroup$ maybe you should tell us what you want to do as your goal. Maybe we can help you better.... $\endgroup$
    – Chris
    Jul 5, 2021 at 7:22
  • 1
    $\begingroup$ The actual window or the add-on preferences? $\endgroup$
    – brockmann
    Jul 5, 2021 at 7:43
  • $\begingroup$ @brockmann The ideal would be in that of the preferences-->add-on $\endgroup$
    – Noob Cat
    Jul 5, 2021 at 9:21

1 Answer 1


Via a draw callback hack.

Using the code in I can't get a SpaceView3D draw callback to work as a template, this does little more than write "Do Something with PREFS" via blf on the user preferences space. Here are some examples of using what I call the draw callback hack.

Is automatic "Reload from disk" confirmation in Text Editor possible?

handle vertex property changes with msgbus.subscribe_rna

Bug in addon to Change header color dynamically

Add your own method in the draw callback, in the knowledge that the context is when the preferences space is being drawn on the screen. (eg it will be displaying addon prefs if context.preferences.active_section == 'ADDONS')

import bpy
import blf
#from gi.repository import Gdk
class DrawingClass:
    def __init__(self, context, prop):
        self.prop = prop
        self.handle = bpy.types.SpacePreferences.draw_handler_add(
                   'WINDOW', 'POST_PIXEL')

    def draw_text_callback(self, context):
        font_id = 0  # XXX, need to find out how best to get this.
        # draw some text
        blf.position(font_id, 15, 50, 20)
        blf.size(font_id, 20, 72)
        blf.draw(font_id, "%s %s" % (context.scene.name, self.prop))

    def remove_handle(self):
         bpy.types.SpacePreferences.draw_handler_remove(self.handle, 'WINDOW')

if __name__ == "__main__":
    # test call            
    dc = DrawingClass(bpy.context, "Do Something with PREFS")
  • $\begingroup$ I have to analyze this answer well, it seems to open the doors to new horizons, and I have to understand well how this works, it seems an excellent solution, and I want to study it thoroughly. $\endgroup$
    – Noob Cat
    Jul 8, 2021 at 11:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .