@@ -50,13 +50,10 @@ def setupUi(self):
50
50
self .resize (600 ,400 )
51
51
self .setWindowTitle ("Edit script" )
52
52
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)
56
55
self .buttonBox = QtGui .QDialogButtonBox ()
57
56
self .buttonBox .setOrientation (QtCore .Qt .Horizontal )
58
- if self .alg != None :
59
- self .text .setText (self .alg .script )
60
57
self .editHelpButton = QtGui .QPushButton ()
61
58
self .editHelpButton .setText ("Edit script help" )
62
59
self .buttonBox .addButton (self .editHelpButton , QtGui .QDialogButtonBox .ActionRole )
@@ -95,7 +92,7 @@ def saveAlgorithm(self):
95
92
if self .filename :
96
93
if not self .filename .endswith (".py" ):
97
94
self .filename += ".py"
98
- text = str ( self .text .toPlainText () )
95
+ text = self .text .text ( )
99
96
if self .alg is not None :
100
97
self .alg .script = text
101
98
try :
@@ -122,3 +119,37 @@ def saveAlgorithm(self):
122
119
def cancelPressed (self ):
123
120
#self.update = False
124
121
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