Skip to content

armgit / krita

Public Imported from GitHub
0

Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.

C++
1.6 KB
Raw Blame
"""
SPDX-FileCopyrightText: 2017 Eliakin Costa <[email protected]>

SPDX-License-Identifier: GPL-2.0-or-later
"""
try:
    from PyQt6.QtWidgets import QMessageBox
    from PyQt6.QtGui import QKeySequence, QAction, QIcon
    from PyQt6.QtCore import Qt
except:
    from PyQt5.QtWidgets import QAction, QMessageBox
    from PyQt5.QtGui import QKeySequence, QIcon
    from PyQt5.QtCore import Qt
from krita import Krita
from builtins import i18n

class CloseAction(QAction):

    def __init__(self, scripter, parent=None):
        super(CloseAction, self).__init__(parent)
        self.scripter = scripter

        self.triggered.connect(self.close)

        self.setText(i18n("Close"))
        self.setObjectName('close')
        self.setIcon(Krita.instance().icon("application-exit"))
        self.setShortcut(QKeySequence(Qt.Modifier.CTRL | Qt.Key.Key_Q))

    @property
    def parent(self):
        return 'File',

    def close(self):
        msgBox = QMessageBox(self.scripter.uicontroller.mainWidget)

        msgBox.setInformativeText(i18n("Do you want to save the current document?"))
        msgBox.setStandardButtons(QMessageBox.StandardButton.Save | QMessageBox.StandardButton.Discard | QMessageBox.StandardButton.Cancel)
        msgBox.setDefaultButton(QMessageBox.StandardButton.Save)

        ret = msgBox.exec()

        if ret == QMessageBox.StandardButton.Cancel:
            return
        if ret == QMessageBox.StandardButton.Save:
            if not self.scripter.uicontroller.invokeAction('save'):
                return

        self.scripter.uicontroller.closeScripter()