Krita Source Code Documentation
Loading...
Searching...
No Matches
reloadaction.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.QtWidgets import QMessageBox
8 from PyQt6.QtGui import QKeySequence, QAction
9 from PyQt6.QtCore import Qt
10except:
11 from PyQt5.QtWidgets import QAction, QMessageBox
12 from PyQt5.QtGui import QKeySequence
13 from PyQt5.QtCore import Qt
14from .... import utils
15from builtins import i18n
16
17
18class ReloadAction(QAction):
19
20 def __init__(self, scripter, parent=None):
21 super(ReloadAction, self).__init__(parent)
22 self.scripter = scripter
23 self.editor = self.scripter.uicontroller.editor
24
25 self.triggered.connect(self.reloadFilereloadFile)
26
27 self.setText(i18n("Reload File"))
28 self.setObjectName('reloadfile')
29 self.setShortcut(QKeySequence(Qt.Modifier.ALT | Qt.Key.Key_R))
30
31 self.setToolTip(i18n('Reload File Alt+R'))
32 self.setIcon(utils.getThemedIcon(':/icons/reload_script.svg'))
33
34 @property
35 def parent(self):
36 return 'File', 'toolBar'
37
38 def reloadFile(self):
39 # get the currently open document's path
40 curr_doc_fpath = ''
41 document = self.scripter.documentcontroller._activeDocument
42 if document is None:
43 QMessageBox.critical(self.scripter.uicontroller.mainWidget,
44 i18n("No existing document"),
45 i18n("Please specify a document by opening it before reloading"))
46 return
47 else:
48 curr_doc_fpath = document.filePath
49
50 # clear the editor
51 self.scripter.documentcontroller.clearActiveDocument()
52 self.scripter.uicontroller.setStatusBar()
53 self.scripter.uicontroller.clearEditor()
54
55 # reload the document
56 document = self.scripter.documentcontroller.openDocument(curr_doc_fpath)
57 self.scripter.uicontroller.setDocumentEditor(document)
58 self.scripter.uicontroller.setStatusBar(document.filePath)
59
60 return document
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))