5

My addon code calls bpy.ops.wm.quit_blender()

And after that there is simply an exit from Blender. But I want to see the standard Blender quit dialog. Is it possible?

Gorgious
  • 30,723
  • 2
  • 44
  • 101
Multifora
  • 63
  • 4

2 Answers2

5

You would have to pass 'INVOKE_DEFAULT' to call the invoke method of the operator:

bpy.ops.wm.quit_blender('INVOKE_DEFAULT')

enter image description here

Read: https://docs.blender.org/api/current/bpy.ops.html#execution-context

brockmann
  • 12,613
  • 4
  • 50
  • 93
2

To close Blender and pop-up the UI window "Save changes before closing", you need to run the code stated below.

import bpy
bpy.ops.wm.window_close()

NOTE: The option Save Prompt must be turned on, which can be found in the Save & Load category of the "User Preferences" editor in able for the code to work properly.

RPaladin
  • 1,235
  • 1
  • 5
  • 17
  • 3
    From what I understood, this operator only the active window : If you only have one open, it's technically the same as quit_blender, but it won't terminate blender if you have multiple windows open in one file. Good to know though :) – Gorgious May 27 '21 at 20:41
  • I think you are confused, quit_blender quits without bring-up the pop-up, save file window. Even with the save prompt I mentioned turned on. window_close on the other hand, does call the pop-up window, if the save prompt option is turned on. – RPaladin May 27 '21 at 21:23
  • 1
    But only if there is one open window was my point. People working with 2 screens often have several blender windows open with that file, and then your solution doesn't work, whereas the one suggested by brockmann does (ie call the invoke method rather than directly the execute one) – Gorgious May 27 '21 at 21:42
  • Are you referring to instances of the blend-file or multiple internal UI layout windows split to external windows. Confused. – RPaladin May 27 '21 at 22:14
  • 3
    I'm referring to windows that you open with Window > New Main Window – Gorgious May 28 '21 at 06:31
  • 3
    ... or for example the preferences window. – batFINGER May 28 '21 at 08:50