Page MenuHome

Fix: C.area, C.region and C.space_data in refreshed pop-ups
ClosedPublic

Authored by Aleksandr Zinovev (raa) on Jul 30 2017, 10:29 AM.

Details

Summary

Before and After:

Run this script in Blender's text editor and press Line Numbers button to refresh the pop-up:

import bpy

def draw_prop(layout, data_path, prop):
    context = bpy.context
    data = eval(data_path)
    if data:
        layout.prop(data, prop)
    else:
        layout.label("%s is None" % data_path, icon='ERROR')

class TestDialog(bpy.types.Operator):
    bl_idname = "test.dialog"
    bl_label = "Test"
    
    def check(self, context):
        return True

    def draw(self, context):
        draw_prop(self.layout, "context.area", "width")
        draw_prop(self.layout, "context.region", "width")
        draw_prop(self.layout, "context.space_data", "show_line_numbers")

    def execute(self, context):
        return {'FINISHED'}

    def invoke(self, context, event):
        return context.window_manager.invoke_props_dialog(self)

bpy.utils.register_class(TestDialog)
bpy.ops.test.dialog('INVOKE_DEFAULT')

Diff Detail

Repository
rB Blender

Event Timeline

Brecht Van Lommel (brecht) requested changes to this revision.Jul 30 2017, 12:56 PM

This needs to restore the previous area after running ui_popup_block_refresh, see other places that call CTX_wm_area_set.

This revision now requires changes to proceed.Jul 30 2017, 12:56 PM
Aleksandr Zinovev (raa) edited edge metadata.

Restore previous area and region

Julian Eisel (Severin) accepted this revision.EditedJul 30 2017, 1:46 PM

Looking fine, just one super picky suggestion.

I'm a bit unsure if we should commit this to 2.79. It should only affect popups but context changes are always a can of worms with ugly corner-cases.... Anyway, I'm not too concerned with pushing to 2.79 either. Is there any urgency in fixing the issue or is it fine to wait (until 2.8 I guess)?

source/blender/editors/interface/interface_regions.c
1679–1682

Could move this into the if (ar->do_draw & RGN_DRAW_REFRESH_UI) block, CTX_wm_area & CTX_wm_region may do some extra Python calls which can be avoided.
Not really an issue, would just consider this good practice :)

Is there any urgency in fixing the issue?

Nope, the issue can be fixed by a python script. Let's commit the patch after 2.79 release.

Is there any urgency in fixing the issue?

Nope, the issue can be fixed by a python script. Let's commit the patch after 2.79 release.

Alright. You can just push to blender2.8 branch then, it's unlikely that there will be another feature release in-between :)

Is there any urgency in fixing the issue?

Nope, the issue can be fixed by a python script. Let's commit the patch after 2.79 release.

Alright. You can just push to blender2.8 branch then, it's unlikely that there will be another feature release in-between :)

Please, no! We do not know what will happen in future, so until we merge back blender2.8 into master, please always commit any non-2.8-specific stuff to master. The less difference we have between those two, the easier it is to manage merges etc.

Also, plan is to ahoy RC1 in next day or so, which means we'll branch out 2.79 from master, so you can commit this to master within two or three days anyway.

Looks good to me now.

This revision is now accepted and ready to land.Aug 1 2017, 1:58 AM