Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bqt/blender_applications/blender_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import logging
from abc import abstractmethod, abstractstaticmethod, ABCMeta
import os
from bqt.ui.quit_dialogue import BlenderClosingDialog, shutdown_blender
from bqt.ui.quit_dialogue import BlenderClosingDialog, shutdown_blender_with_save_dialogue
from bqt.qt_core import QEvent, QObject, QRect, QSettings, QTimer, QCloseEvent, QIcon, QWindow, QApplication, QWidget, QMainWindow
import bpy
import bqt.manager
Expand Down Expand Up @@ -192,7 +192,7 @@ def notify(self, receiver: QObject, event: QEvent) -> bool:

if os.getenv("BQT_DISABLE_CLOSE_DIALOGUE") == "1":
# this triggers the default blender close event, showing the save dialog if needed
shutdown_blender({"window": bpy.context.window_manager.windows[0]}, "INVOKE_DEFAULT")
shutdown_blender_with_save_dialogue()
else:
closing_dialog = BlenderClosingDialog(self.blender_widget)
closing_dialog.execute()
Expand Down
33 changes: 19 additions & 14 deletions bqt/ui/quit_dialogue.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,7 @@
import bqt.ui



def shutdown_blender(*args, **kwargs):
"""Custom shutdown function for Blender, imitating the default Blender shutdown"""

# By default, changes to preferences are saved on exit, this can be toggled off in the preferences
if bpy.context.preferences.use_preferences_save:
bpy.ops.wm.save_userpref()

def quit_blender_from_main_thread(*args, **kwargs):
# https://github.com/techartorg/bqt/issues/131
# running bpy.ops.wm.quit_blender, runs it from the Qt thread.
# this can cause an EXCEPTION_ACCESS_VIOLATION on closing blender
Expand All @@ -23,6 +16,24 @@ def __quit_blender():
bpy.app.timers.register(__quit_blender)


def shutdown_blender(*args, **kwargs):
"""
Quit blender, without triggering the save dialogue

:param args: catches any arguments passed by bpy handlers, and option to pass args to bpy.ops.wm.quit_blender
"""
# By default changes to preferences are saved on exit, this can be toggled off in the preferences
if bpy.context.preferences.use_preferences_save:
bpy.ops.wm.save_userpref()

quit_blender_from_main_thread(*args, **kwargs)


def shutdown_blender_with_save_dialogue():
with bpy.context.temp_override(window=bpy.context.window_manager.windows[0]):
quit_blender_from_main_thread("INVOKE_DEFAULT")


class WINDOW_OT_SaveFileFromQt(bpy.types.Operator):
bl_idname = "wm.save_from_qt"
bl_label = "Save_from_Qt"
Expand All @@ -44,9 +55,6 @@ def execute(self, context):


class BlenderClosingDialog(QMessageBox):
"""
The default Blender closing dialog recreated with Qt, to ensure correct window parenting
"""
def __init__(self, parent):
super().__init__(parent) #, Qt.WindowCloseButtonHint | Qt.WindowSystemMenuHint | Qt.WindowTitleHint | Qt.WindowStaysOnTopHint)

Expand All @@ -66,9 +74,6 @@ def __init__(self, parent):
self.setIconPixmap(question_icon)

def execute(self):
"""
Show the dialog and handle the user's choice: Save, Discard, or Cancel.
"""
if not bpy.data.is_dirty:
shutdown_blender()
return
Expand Down