Differential D4731 Diff 11652 plugins/extensions/pykrita/plugin/plugins/scripter/ui_scripter/actions/runaction/runaction.py
Changeset View
Changeset View
Standalone View
Standalone View
plugins/extensions/pykrita/plugin/plugins/scripter/ui_scripter/actions/runaction/runaction.py
1 | from PyQt5.QtWidgets import QAction, QMessageBox | 1 | from PyQt5.QtWidgets import QAction, QMessageBox | ||
---|---|---|---|---|---|
2 | from PyQt5.QtGui import QIcon, QKeySequence | 2 | from PyQt5.QtGui import QIcon, QKeySequence | ||
3 | from PyQt5.QtCore import Qt | 3 | from PyQt5.QtCore import Qt | ||
4 | import sys | 4 | import sys | ||
5 | from . import docwrapper | 5 | from . import docwrapper | ||
6 | import os | 6 | import os | ||
7 | from scripter import resources_rc | 7 | from scripter import resources_rc | ||
8 | 8 | | |||
9 | 9 | | |||
10 | class RunAction(QAction): | 10 | class RunAction(QAction): | ||
11 | 11 | | |||
12 | def __init__(self, scripter, parent=None): | 12 | def __init__(self, scripter, parent=None): | ||
13 | super(RunAction, self).__init__(parent) | 13 | super(RunAction, self).__init__(parent) | ||
14 | self.scripter = scripter | 14 | self.scripter = scripter | ||
15 | 15 | | |||
16 | self.editor = self.scripter.uicontroller.editor | 16 | self.editor = self.scripter.uicontroller.editor | ||
17 | self.output = self.scripter.uicontroller.findStackWidget('OutPut') | 17 | self.output = self.scripter.uicontroller.findTabWidget('OutPut') | ||
18 | 18 | | |||
19 | self.triggered.connect(self.run) | 19 | self.triggered.connect(self.run) | ||
20 | 20 | | |||
21 | self.setText('Run') | 21 | self.setText('Run') | ||
22 | self.setToolTip('Run Ctrl+R') | 22 | self.setToolTip('Run Ctrl+R') | ||
23 | self.setIcon(QIcon(':/icons/run.svg')) | 23 | self.setIcon(QIcon(':/icons/run.svg')) | ||
24 | self.setShortcut(QKeySequence(Qt.CTRL + Qt.Key_R)) | 24 | self.setShortcut(QKeySequence(Qt.CTRL + Qt.Key_R)) | ||
25 | 25 | | |||
26 | @property | 26 | @property | ||
27 | def parent(self): | 27 | def parent(self): | ||
28 | return 'toolBar' | 28 | return 'toolBar' | ||
29 | 29 | | |||
30 | def run(self): | 30 | def run(self): | ||
31 | self.scripter.uicontroller.setActiveWidget('OutPut') | ||||
31 | stdout = sys.stdout | 32 | stdout = sys.stdout | ||
32 | stderr = sys.stderr | 33 | stderr = sys.stderr | ||
33 | output = docwrapper.DocWrapper(self.output.document()) | 34 | output = docwrapper.DocWrapper(self.output.document()) | ||
34 | output.write("======================================\n") | 35 | output.write("======================================\n") | ||
35 | sys.stdout = output | 36 | sys.stdout = output | ||
36 | sys.stderr = output | 37 | sys.stderr = output | ||
37 | script = self.editor.document().toPlainText() | 38 | script = self.editor.document().toPlainText() | ||
38 | try: | 39 | try: | ||
39 | exec(script) | 40 | exec(script) | ||
40 | except Exception as e: | 41 | except Exception as e: | ||
41 | self.scripter.uicontroller.showException(str(e)) | 42 | self.scripter.uicontroller.showException(str(e)) | ||
42 | sys.stdout = stdout | 43 | sys.stdout = stdout | ||
43 | sys.stderr = stderr | 44 | sys.stderr = stderr |