Page MenuHome

Popup Dialog (wm.popup_dialog)
Needs ReviewPublic

Authored by Dalai Felinto (dfelinto) on Mar 30 2016, 11:07 PM.

Details

Summary

This add an option for a popup dialog that gives more freedom to the user than the current alternative.

Things that do not work yet:

  • row() and split() mess with layout
  • redraw not working
  • exit_on_execute not working (the idea is to exit when an operator is called, but not when a property is chagned)
  • I get a asan crash if I use the delete object operator from within the popup dialog

Test script:

import bpy

def draw(self, context):
    layout = self.layout
    col = layout.column()
    row = col.row()
    row.label("Hello")
    row.label("World")

    row = col.row()
    row.label("Blender")
    row.label("Hi There", icon='INFO')

    col.operator("object.add")

    ob = context.object
    if ob:
        col.prop(ob, "name")
        col.prop(ob, "location")
        col.row().prop(ob, "dupli_type", expand=True)

        if ob.dupli_type == 'VERTS':
            col.label(text="VERT")
        else:
            col.label(text="Something else")

        col.operator("object.delete")

bpy.context.window_manager.popup_dialog(draw, title="Greeting", icon='INFO', keep_open=True, exit_on_execute=True)

Diff Detail

Repository
rB Blender
Branch
popup_dialog

Event Timeline

Dalai Felinto (dfelinto) retitled this revision from to Popup Dialog (wm.popup_dialog).
Dalai Felinto (dfelinto) updated this object.
  • Leftover from debugging
  • UI_EMBOSS instead of UI_EMBOSS_PULLDOWN

Having the ability for a Python popup without associated operators is nice when an interface isn't associated with a single tool (we had this in 2.4x in fact, see: https://www.blender.org/api/249PythonDoc/Draw-module.html#UIBlock )

However there are some issues:

  • The interface won't block (which is good in general, though it can complicate writing scripts if you just want some input immediately) that means the popup will be created and Python will continue executing.
  • Script authors will very likely want the script to be able to redraw once the settings have changed (wasn't supported for a long time with operators until we added the check callback), this means the patch needs to be quite a lot more involved - since the C code will need to store the callback and call it multiple times.

Also think we will need extra callbacks, eg:
popup_dialog(draw=... , check=... , cancel=...) where check will optionally re-run draw after a value is changed and cancel will run if the user presses escape or clicks away.