Skip to content

Commit

Permalink
[processing] improved script edit dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
volaya committed Sep 2, 2013
1 parent 99525c3 commit 1655f8e
Showing 1 changed file with 37 additions and 6 deletions.
43 changes: 37 additions & 6 deletions python/plugins/processing/script/EditScriptDialog.py
Expand Up @@ -50,13 +50,10 @@ def setupUi(self):
self.resize(600,400)
self.setWindowTitle("Edit script")
layout = QVBoxLayout()
self.text = QtGui.QTextEdit()
self.text.setObjectName("text")
self.text.setEnabled(True)
self.text = ScriptEditorWidget(self.alg.script if self.alg is not None else "")
#self.text.setEnabled(True)
self.buttonBox = QtGui.QDialogButtonBox()
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
if self.alg != None:
self.text.setText(self.alg.script)
self.editHelpButton = QtGui.QPushButton()
self.editHelpButton.setText("Edit script help")
self.buttonBox.addButton(self.editHelpButton, QtGui.QDialogButtonBox.ActionRole)
Expand Down Expand Up @@ -95,7 +92,7 @@ def saveAlgorithm(self):
if self.filename:
if not self.filename.endswith(".py"):
self.filename += ".py"
text = str(self.text.toPlainText())
text = self.text.text()
if self.alg is not None:
self.alg.script = text
try:
Expand All @@ -122,3 +119,37 @@ def saveAlgorithm(self):
def cancelPressed(self):
#self.update = False
self.close()

from PyQt4.Qsci import QsciScintilla, QsciLexerPython

class ScriptEditorWidget(QsciScintilla):
ARROW_MARKER_NUM = 8

def __init__(self, text, parent=None):
super(ScriptEditorWidget, self).__init__(parent)

font = QFont()
font.setFamily('Courier')
font.setFixedPitch(True)
font.setPointSize(10)
self.setFont(font)
self.setMarginsFont(font)

fontmetrics = QFontMetrics(font)
self.setMarginsFont(font)
self.setMarginWidth(0, fontmetrics.width("00000") + 6)
self.setMarginLineNumbers(0, True)
self.setMarginsBackgroundColor(QColor("#cccccc"))

self.setBraceMatching(QsciScintilla.SloppyBraceMatch)

self.setCaretLineVisible(True)
self.setCaretLineBackgroundColor(QColor("#ffe4e4"))

lexer = QsciLexerPython()
lexer.setDefaultFont(font)
self.setLexer(lexer)
self.SendScintilla(QsciScintilla.SCI_STYLESETFONT, 1, 'Courier')

self.setText(text)

0 comments on commit 1655f8e

Please sign in to comment.