Skip to content

Commit 1655f8e

Browse files
committed
[processing] improved script edit dialog
1 parent 99525c3 commit 1655f8e

File tree

1 file changed

+37
-6
lines changed

1 file changed

+37
-6
lines changed

python/plugins/processing/script/EditScriptDialog.py

+37-6
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,10 @@ def setupUi(self):
5050
self.resize(600,400)
5151
self.setWindowTitle("Edit script")
5252
layout = QVBoxLayout()
53-
self.text = QtGui.QTextEdit()
54-
self.text.setObjectName("text")
55-
self.text.setEnabled(True)
53+
self.text = ScriptEditorWidget(self.alg.script if self.alg is not None else "")
54+
#self.text.setEnabled(True)
5655
self.buttonBox = QtGui.QDialogButtonBox()
5756
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
58-
if self.alg != None:
59-
self.text.setText(self.alg.script)
6057
self.editHelpButton = QtGui.QPushButton()
6158
self.editHelpButton.setText("Edit script help")
6259
self.buttonBox.addButton(self.editHelpButton, QtGui.QDialogButtonBox.ActionRole)
@@ -95,7 +92,7 @@ def saveAlgorithm(self):
9592
if self.filename:
9693
if not self.filename.endswith(".py"):
9794
self.filename += ".py"
98-
text = str(self.text.toPlainText())
95+
text = self.text.text()
9996
if self.alg is not None:
10097
self.alg.script = text
10198
try:
@@ -122,3 +119,37 @@ def saveAlgorithm(self):
122119
def cancelPressed(self):
123120
#self.update = False
124121
self.close()
122+
123+
from PyQt4.Qsci import QsciScintilla, QsciLexerPython
124+
125+
class ScriptEditorWidget(QsciScintilla):
126+
ARROW_MARKER_NUM = 8
127+
128+
def __init__(self, text, parent=None):
129+
super(ScriptEditorWidget, self).__init__(parent)
130+
131+
font = QFont()
132+
font.setFamily('Courier')
133+
font.setFixedPitch(True)
134+
font.setPointSize(10)
135+
self.setFont(font)
136+
self.setMarginsFont(font)
137+
138+
fontmetrics = QFontMetrics(font)
139+
self.setMarginsFont(font)
140+
self.setMarginWidth(0, fontmetrics.width("00000") + 6)
141+
self.setMarginLineNumbers(0, True)
142+
self.setMarginsBackgroundColor(QColor("#cccccc"))
143+
144+
self.setBraceMatching(QsciScintilla.SloppyBraceMatch)
145+
146+
self.setCaretLineVisible(True)
147+
self.setCaretLineBackgroundColor(QColor("#ffe4e4"))
148+
149+
lexer = QsciLexerPython()
150+
lexer.setDefaultFont(font)
151+
self.setLexer(lexer)
152+
self.SendScintilla(QsciScintilla.SCI_STYLESETFONT, 1, 'Courier')
153+
154+
self.setText(text)
155+

0 commit comments

Comments
 (0)