Differential D4731 Diff 11652 plugins/extensions/pykrita/plugin/plugins/scripter/ui_scripter/actions/closeaction/closeaction.py
Changeset View
Changeset View
Standalone View
Standalone View
plugins/extensions/pykrita/plugin/plugins/scripter/ui_scripter/actions/closeaction/closeaction.py
- This file was added.
1 | from PyQt5.QtWidgets import QAction, QMessageBox | ||||
---|---|---|---|---|---|
2 | from PyQt5.QtGui import QKeySequence | ||||
3 | from PyQt5.QtCore import Qt | ||||
4 | | ||||
5 | | ||||
6 | class CloseAction(QAction): | ||||
7 | | ||||
8 | def __init__(self, scripter, parent=None): | ||||
9 | super(CloseAction, self).__init__(parent) | ||||
10 | self.scripter = scripter | ||||
11 | | ||||
12 | self.triggered.connect(self.close) | ||||
13 | | ||||
14 | self.setText('Close') | ||||
15 | self.setObjectName('close') | ||||
16 | self.setShortcut(QKeySequence(Qt.CTRL + Qt.Key_Q)) | ||||
17 | | ||||
18 | @property | ||||
19 | def parent(self): | ||||
20 | return 'File' | ||||
21 | | ||||
22 | def close(self): | ||||
23 | msgBox = QMessageBox(self.scripter.uicontroller.mainWidget) | ||||
24 | | ||||
25 | msgBox.setInformativeText("Do you want to save the current document?"); | ||||
26 | msgBox.setStandardButtons(QMessageBox.Save | QMessageBox.Discard | QMessageBox.Cancel); | ||||
27 | msgBox.setDefaultButton(QMessageBox.Save); | ||||
28 | | ||||
29 | ret = msgBox.exec(); | ||||
30 | | ||||
31 | if ret == QMessageBox.Cancel: | ||||
32 | return | ||||
33 | if ret == QMessageBox.Save: | ||||
34 | if not self.scripter.uicontroller.invokeAction('save'): | ||||
35 | return | ||||
36 | | ||||
37 | self.scripter.uicontroller.closeScripter() |