0
$\begingroup$

Blender version 2.83 I need create dialog window with User. Now i'm using context.wm.invoke_popup but problem that This dialog window close when cursor to far from it and not resible. Can i create GUI with Blender python API ?

Or give some info What do I need to do to prevent the dialog window from closing context.wm.invoke_props_dialog is bad because there button 'ok' i don't need this. My operator:

class EXAMPLE_OT_window(Operator):
    bl_idname = 'example.window'
    bl_label = 'Example'
    bl_options = {'REGISTER', }
    bl_description = 'example_description'

    def invoke(self, context, event):
        return context.window_manager.invoke_popup(self, width=300)

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

    def draw(self, context):
        layout = self.layout
        layout.separator()
        layout.label(text=self.bl_label)
        layout.separator()
$\endgroup$
1
$\begingroup$

Using panels in 2.8+

It's my opinion that many (including my previous self) get over enamoured with invoking modal dialog props dialogs.

Currently question code has some empty operator (execution wise) that is basically a draw method. Often I see code where the functionality of the operator used to draw a popup could be replaced entirely by a group property and update methods on the individual properties, hence may as well put in panel code.

IMO if you want a nice stable UI use a panel

Since the advent of 2.8 there is the ability to

  • absolutely size panel content

  • Popup a panel with an operator wm.popup_panel(...)

  • Popup a panel from draw method (no operator layout.popover(...)

  • Make child panels.

Here is an example which I've demonstrated in text editor. (based from good old Hello World Panel template)

In the UI N panel (context.region == 'UI') the x ui width is set to 0 making the add cube operator button the width of the panel, if invoked from the FOOTER region then the panel is 20 wide.

enter image description here

import bpy


class HelloWorldPanel(bpy.types.Panel):
    """Creates a Panel in the Object properties window"""
    bl_label = "Hello World Panel"
    bl_idname = "TEXT_PT_hello"
    bl_space_type = 'TEXT_EDITOR'
    bl_region_type = 'UI'


    def draw(self, context):
        print(context.region.type)
        layout = self.layout
        layout.ui_units_x = 0 if context.region.type == 'UI' else 20
        obj = context.object

        row = layout.row()
        
        row.label(text="Hello world!", icon='WORLD_DATA')

        row = layout.row()
        row.label(text="Active object is: " + obj.name)
        row = layout.row()
        row.prop(obj, "name")

        row = layout.row()
        row.operator("mesh.primitive_cube_add")

def draw_panel(self, context):
    op = self.layout.operator("wm.call_panel")
    op.name = "TEXT_PT_hello"
    self.layout.popover("TEXT_PT_hello")

def register():
    bpy.utils.register_class(HelloWorldPanel)


def unregister():
    bpy.utils.unregister_class(HelloWorldPanel)


if __name__ == "__main__":
    bpy.types.TEXT_HT_footer.append(draw_panel)
    register()

Note: Given the desire is to have "popup" not close when mousing away, and be resizable consider opening a new window as discussed here

New window with Python API?

$\endgroup$
1
  • $\begingroup$ Thank you. Can i change button text of "OK" button in 'invoke_props_dialog' to another word ? Can i create a custom space_area with my buttons, labeles etc like 'PROPERTIES', 'VIEW_3D', 'TEXT_EDITOR' ? $\endgroup$ – Sofia Oct 14 '20 at 13:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.