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 krita import * | 3 | from krita import * | ||
4 | from scripter import syntax | 4 | from scripter import syntax, pythoneditor | ||
5 | import sys | 5 | import sys | ||
6 | 6 | | |||
7 | class docWrapper: | 7 | class docWrapper: | ||
8 | 8 | | |||
9 | def __init__(self, textdocument): | 9 | def __init__(self, textdocument): | ||
10 | self.textdocument = textdocument | 10 | self.textdocument = textdocument | ||
11 | 11 | | |||
12 | def write(self, text, view = None): | 12 | def write(self, text, view = None): | ||
Show All 29 Lines | 28 | def execute(self): | |||
42 | exec(bc) | 42 | exec(bc) | ||
43 | 43 | | |||
44 | sys.stdout = stdout | 44 | sys.stdout = stdout | ||
45 | sys.stderr = stderr | 45 | sys.stderr = stderr | ||
46 | 46 | | |||
47 | def showScripter(self): | 47 | def showScripter(self): | ||
48 | dialog = QDialog() | 48 | dialog = QDialog() | ||
49 | dialog.setWindowModality(Qt.NonModal) | 49 | dialog.setWindowModality(Qt.NonModal) | ||
50 | self.editor = QPlainTextEdit() | 50 | self.editor = pythoneditor.CodeEditor() | ||
51 | f = QFont("monospace", 10, QFont.Normal) | 51 | f = QFont("monospace", 10, QFont.Normal) | ||
52 | f.setFixedPitch(True) | 52 | f.setFixedPitch(True) | ||
53 | self.editor.document().setDefaultFont(f) | 53 | self.editor.document().setDefaultFont(f) | ||
54 | highlight = syntax.PythonHighlighter(self.editor.document()) | 54 | highlight = syntax.PythonHighlighter(self.editor.document()) | ||
55 | vbox = QVBoxLayout(dialog) | 55 | vbox = QVBoxLayout(dialog) | ||
56 | vbox.addWidget(self.editor) | 56 | vbox.addWidget(self.editor) | ||
57 | button = QPushButton("Execute") | 57 | button = QPushButton("Execute") | ||
58 | button.clicked.connect(self.execute) | 58 | button.clicked.connect(self.execute) | ||
59 | vbox.addWidget(button) | 59 | vbox.addWidget(button) | ||
60 | self.output = QPlainTextEdit() | 60 | self.output = QPlainTextEdit() | ||
61 | vbox.addWidget(self.output) | 61 | vbox.addWidget(self.output) | ||
62 | dialog.resize(400, 500) | 62 | dialog.resize(400, 500) | ||
63 | dialog.setWindowTitle("Scripter") | 63 | dialog.setWindowTitle("Scripter") | ||
64 | dialog.setSizeGripEnabled(True) | 64 | dialog.setSizeGripEnabled(True) | ||
65 | dialog.show() | 65 | dialog.show() | ||
66 | dialog.activateWindow() | 66 | dialog.activateWindow() | ||
67 | dialog.exec() | 67 | dialog.exec() | ||
68 | 68 | | |||
69 | 69 | | |||
70 | Krita.instance().addViewExtension(ScripterViewExtension(Krita.instance())) | 70 | Krita.instance().addViewExtension(ScripterViewExtension(Krita.instance())) | ||
71 | |