Krita Source Code Documentation
Loading...
Searching...
No Matches
saveaction.py
Go to the documentation of this file.
1"""
2SPDX-FileCopyrightText: 2017 Eliakin Costa <eliakim170@gmail.com>
3
4SPDX-License-Identifier: GPL-2.0-or-later
5"""
6try:
7 from PyQt6.QtGui import QKeySequence, QAction
8 from PyQt6.QtCore import Qt
9except:
10 from PyQt5.QtWidgets import QAction
11 from PyQt5.QtGui import QKeySequence
12 from PyQt5.QtCore import Qt
13from krita import FileDialog
14from builtins import i18n
15
16
17class SaveAction(QAction):
18
19 def __init__(self, scripter, parent=None):
20 super(SaveAction, self).__init__(parent)
21 self.scripter = scripter
22 self.editor = self.scripter.uicontroller.editor
23
24 self.triggered.connect(self.savesave)
25
26 self.setText(i18n("Save"))
27 self.setObjectName('save')
28 self.setShortcut(QKeySequence(Qt.Modifier.CTRL | Qt.Key.Key_S))
29
30 @property
31 def parent(self):
32 return 'File',
33
34 def save(self):
35 text = self.editor.toPlainText()
36 fileName = ''
37
38 if not self.scripter.documentcontroller.activeDocument:
39 fileName = FileDialog.getSaveFileName(self.scripter.uicontroller.mainWidget,
40 i18n("Save Python File"), '',
41 (i18n("Python Files") + " (*.py)"))
42 if not fileName:
43 return
44
45 # don't validate file name - trust user to specify the extension they want
46 # getSaveFileName will add ".py" if there is no extension.
47 # It will strip a trailing period and, in each case, test for file collisions
48
49 document = self.scripter.documentcontroller.saveDocument(text, fileName)
50 if document:
51 self.scripter.uicontroller.setStatusBar(document.filePath)
52 else:
53 self.scripter.uicontroller.setStatusBar('untitled')
54 self.editor._documentModified = False
55 self.scripter.uicontroller.setStatusModified()
56 return document
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
static QString getSaveFileName(QWidget *parent=nullptr, const QString &caption=QString(), const QString &directory=QString(), const QString &filter=QString(), const QString &selectedFilter=QString(), const QString &dialogName=QString())
Create and show a file dialog and return the name of a file to save to selected by the user.