Changeset View
Changeset View
Standalone View
Standalone View
plugins/extensions/pykrita/plugin/plugins/scripter/scripter.py
1 | from PyQt5.QtGui import * | 1 | from PyQt5.QtGui import * | ||
---|---|---|---|---|---|
2 | from PyQt5.QtWidgets import * | 2 | from PyQt5.QtWidgets import * | ||
3 | from PyQt5.QtCore import * | ||||
3 | from krita import * | 4 | from krita import * | ||
4 | from scripter import syntax, pythoneditor | 5 | from scripter import syntax, pythoneditor, settingsdialog, syntaxstyles | ||
5 | import sys | 6 | import sys | ||
6 | 7 | | |||
7 | class docWrapper: | 8 | class docWrapper: | ||
8 | 9 | | |||
9 | def __init__(self, textdocument): | 10 | def __init__(self, textdocument): | ||
10 | self.textdocument = textdocument | 11 | self.textdocument = textdocument | ||
11 | 12 | | |||
12 | def write(self, text, view = None): | 13 | def write(self, text, view = None): | ||
Show All 26 Lines | 39 | except Exception as e: | |||
39 | QMessageBox.critical(self.editor, "Error compiling script", str(e)) | 40 | QMessageBox.critical(self.editor, "Error compiling script", str(e)) | ||
40 | return | 41 | return | ||
41 | 42 | | |||
42 | exec(bc) | 43 | exec(bc) | ||
43 | 44 | | |||
44 | sys.stdout = stdout | 45 | sys.stdout = stdout | ||
45 | sys.stderr = stderr | 46 | sys.stderr = stderr | ||
46 | 47 | | |||
48 | def openSettings(self): | ||||
49 | self.settingsDialog = settingsdialog.SettingsDialog(self) | ||||
50 | self.settingsDialog.setWindowModality(Qt.WindowModal) | ||||
51 | self.settingsDialog.setFixedSize(400, 250) | ||||
52 | self.settingsDialog.show() | ||||
53 | self.settingsDialog.exec() | ||||
54 | | ||||
47 | def showScripter(self): | 55 | def showScripter(self): | ||
48 | dialog = QDialog() | 56 | dialog = QDialog() | ||
49 | dialog.setWindowModality(Qt.NonModal) | 57 | dialog.setWindowModality(Qt.NonModal) | ||
50 | self.editor = pythoneditor.CodeEditor() | 58 | self.editor = pythoneditor.CodeEditor() | ||
51 | f = QFont("monospace", 10, QFont.Normal) | 59 | f = QFont("monospace", 10, QFont.Normal) | ||
52 | f.setFixedPitch(True) | 60 | f.setFixedPitch(True) | ||
53 | self.editor.document().setDefaultFont(f) | 61 | self.editor.document().setDefaultFont(f) | ||
54 | highlight = syntax.PythonHighlighter(self.editor.document()) | 62 | self.highlight = syntax.PythonHighlighter(self.editor.document(), syntaxstyles.DefaultSyntaxStyle()) | ||
55 | vbox = QVBoxLayout(dialog) | 63 | vbox = QVBoxLayout(dialog) | ||
56 | vbox.addWidget(self.editor) | 64 | vbox.addWidget(self.editor) | ||
57 | button = QPushButton("Execute") | 65 | buttonLayout = QHBoxLayout() | ||
66 | button = QPushButton("Run") | ||||
67 | settingsButton = QPushButton("Settings") | ||||
58 | button.clicked.connect(self.execute) | 68 | button.clicked.connect(self.execute) | ||
59 | vbox.addWidget(button) | 69 | settingsButton.clicked.connect(self.openSettings) | ||
70 | buttonLayout.addWidget(button) | ||||
71 | buttonLayout.addWidget(settingsButton) | ||||
72 | vbox.addLayout(buttonLayout) | ||||
60 | self.output = QPlainTextEdit() | 73 | self.output = QPlainTextEdit() | ||
61 | vbox.addWidget(self.output) | 74 | vbox.addWidget(self.output) | ||
62 | dialog.resize(400, 500) | 75 | dialog.resize(400, 500) | ||
63 | dialog.setWindowTitle("Scripter") | 76 | dialog.setWindowTitle("Scripter") | ||
64 | dialog.setSizeGripEnabled(True) | 77 | dialog.setSizeGripEnabled(True) | ||
65 | dialog.show() | 78 | dialog.show() | ||
66 | dialog.activateWindow() | 79 | dialog.activateWindow() | ||
67 | dialog.exec() | 80 | dialog.exec() | ||
68 | 81 | | |||
69 | 82 | | |||
70 | Krita.instance().addViewExtension(ScripterViewExtension(Krita.instance())) | 83 | Krita.instance().addViewExtension(ScripterViewExtension(Krita.instance())) |