mmmrqs/bl_ui_widgets

[BUG] the button mouse up binding will not pass the context to the function

atticus-lv opened this issue · 3 comments

The origin repo do not have this problem
Try binding this with the mouse up function (Even using the context overide will not fix this problem)

def btn_click(self,widget,event,x,y):
    bpy.ops.view3d.view_axis(type = 'TOP')

@mmmrqs hey mmmrqs do you have time to check this issue?

mmmrqs commented
mmmrqs commented

The origin repo do not have this problem Try binding this with the mouse up function (Even using the context overide will not fix this problem)

def btn_click(self,widget,event,x,y):
    bpy.ops.view3d.view_axis(type = 'TOP')

Hi @atticus-lv, this is kind of annoying issue and such a complicated one. I was able to find a workaround though, using context override with some tweaks. I confess that I do not have much expertise with these Blender/Python idiosyncrasies but this solution works fine for this particular case. You may want to try the following example:

def btn_click(self, widget, event, x, y):
    for window in bpy.context.window_manager.windows:
        for area in window.screen.areas:
            if area.type == 'VIEW_3D':
                with bpy.context.temp_override(window=window, area=area, region=area.regions[-1]):
                    bpy.ops.view3d.view_axis(type = 'TOP')
                return True

I am going to update the code in my repo with all these changes and the sample piece will be there for people to refer. Once again, thank you very much for bringing this to my attention. I apologize for not having time to provide a quicker support, but it is what it is.