GizmoGroup + GIZMO_GT_button_2d - not working on autoload

I’m trying to build a small addon with a single 2d gizmo button. The code works as expected when it is enabled (or disabled and re-enabled) in preferences, clicking the button executes indicated operator. However, when the preferences are saved to have the addon automatically started with blender, when Blender starts, the button doesn’t react at all on any user actions. The only solution - to disable and re-enable addon in preferences. Then the button works again… And when the Blender is restarted… Again it is needed to disable and re-enable addon…

Sample code:

# Licensing information

bl_info = {
    "name": "Gizmo button 2d test",
    "version": (0, 1),
    "blender": (2, 80, 0),
    "description": "test gizmo button 2d functionality, report problem...",
    "location": "View3D",
    "warning": "",
    "category": "3D View"

import bpy

from bpy.props import (IntProperty, EnumProperty, BoolProperty)
from bpy.types import (AddonPreferences, GizmoGroup, Operator)

class GizmoButton2D(GizmoGroup):
    """ test gizmo button 2d """
    bl_idname = "view3d.gizmo_button_2d"
    bl_label = "Test button 2d"
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'WINDOW'
    bl_options = {'PERSISTENT', 'SCALE'}
    def poll(cls, context):
        if context.object != None:
            return True
        return False
    def draw_prepare(self, context):
            self.foo_gizmo.matrix_basis[0][3] = 100
            self.foo_gizmo.matrix_basis[1][3] = 100

    def setup(self, context):
        mpr ="GIZMO_GT_button_2d")
        mpr.icon = 'OUTLINER_OB_CAMERA'
        mpr.draw_options = {'BACKDROP', 'OUTLINE'}
        mpr.alpha = 0.0
        mpr.color_highlight = 0.8, 0.8, 0.8
        mpr.alpha_highlight = 0.2
        mpr.scale_basis = (80 * 0.35) / 2 # same as buttons defined in C
        self.foo_gizmo = mpr

def register():

def unregister():

Any ideas? I’m really stuck, everything I’ve tried doesn’t change anything. Do I miss something? Is there a difference when addon is started by enabling it in Preferences or being automatically loaded by Blender?..

The last Blender build reports warnings on empty keymap for the newly created GizmoButton2D. I’ve tried to provide

def setup_keymap(cls, keyconfig):
    keymap = ...
    return keymap

however I don’t know how to correctly populate the keymap. And after this modification the button doesn’t work even after disabling and re-enabling addon…

1 Like

Not sure if it is related but I had similar problem with new Tool UI system (had to reload it to make it work):
It was marked as tuplicate of:
I think devs know about this modal keymap not being initalized properly problem. I havent used GizmoGroup, but I think it may be similar problem to WorkSpaceTool

1 Like

Thank you very much for this information! Indeed this look like the same or at least related problem. And my addon also works properly after bpy.ops.script.reload()… Hope this issue will be fixed soon… )))
Have you found any workaround for your problem?

Nope. I wait for finitalized WorkSpaceTool python api. It is medium priority, but hopefully devs will look into that on 2.8 release.
I guess maybe manually reloading addon from handler could work maybe?

Hi! Looks like in the last builds the issues with gizmo button were fixed. What about your problem with Tool UI?

I dosen’t work for Tools hotkeys from addon. But the bug is reported, so hopefuly it will be fixed in future.

I have found another bug which I associate with Gizmo API. I don’t know how these are related but when the presented example (addon) is activated in Preferences in the Operator (as an example used Move op - I’ve moved islands in the UV editor) properties window content is downscaled as in this screenshot:

When the addon is deactivated everything is OK:

I don’t know where to send this information to have this registered as a bug…

P.S. Have opened another thread for this…