Differential D10839 Diff 28263 plugins/python/scripter/ui_scripter/actions/reloadaction/reloadaction.py
Changeset View
Changeset View
Standalone View
Standalone View
plugins/python/scripter/ui_scripter/actions/reloadaction/reloadaction.py
- This file was added.
1 | from PyQt5.QtWidgets import QAction, QFileDialog, QMessageBox | ||||
---|---|---|---|---|---|
2 | from PyQt5.QtGui import QKeySequence | ||||
3 | from PyQt5.QtCore import Qt | ||||
4 | | ||||
5 | | ||||
6 | class ReloadAction(QAction): | ||||
7 | | ||||
8 | def __init__(self, scripter, parent=None): | ||||
9 | super(ReloadAction, self).__init__(parent) | ||||
10 | self.scripter = scripter | ||||
11 | self.editor = self.scripter.uicontroller.editor | ||||
12 | | ||||
13 | self.triggered.connect(self.reloadFile) | ||||
14 | | ||||
15 | self.setText('Reload File') | ||||
16 | self.setObjectName('reloadfile') | ||||
17 | self.setShortcut(QKeySequence(Qt.ALT + Qt.Key_R)) | ||||
18 | | ||||
19 | @property | ||||
20 | def parent(self): | ||||
21 | return 'File' | ||||
22 | | ||||
23 | def reloadFile(self): | ||||
24 | # get the currently open document's path | ||||
25 | curr_doc_fpath = '' | ||||
26 | document = self.scripter.documentcontroller._activeDocument | ||||
27 | if document is None: | ||||
28 | QMessageBox.critical(self.scripter.uicontroller.mainWidget, | ||||
29 | 'No existing document', | ||||
30 | 'Please specify a document by opening it before reloading') | ||||
31 | return | ||||
32 | else: | ||||
33 | curr_doc_fpath = document.filePath | ||||
34 | | ||||
35 | # clear the editor | ||||
36 | self.scripter.documentcontroller.clearActiveDocument() | ||||
37 | self.scripter.uicontroller.setStatusBar() | ||||
38 | self.scripter.uicontroller.clearEditor() | ||||
39 | | ||||
40 | # reload the document | ||||
41 | document = self.scripter.documentcontroller.openDocument(curr_doc_fpath) | ||||
42 | self.scripter.uicontroller.setDocumentEditor(document) | ||||
43 | self.scripter.uicontroller.setStatusBar(document.filePath) | ||||
44 | print("reload is run") | ||||
45 | | ||||
46 | return document |