22
22
from PyQt4 .QtCore import *
23
23
from PyQt4 .QtGui import *
24
24
from PyQt4 .Qsci import (QsciScintilla ,
25
- QsciScintillaBase ,
25
+ QsciScintillaBase ,
26
26
QsciLexerPython )
27
27
import sys
28
-
28
+
29
29
class writeOut :
30
30
def __init__ (self , edit , out = None , style = None ):
31
31
"""
@@ -46,19 +46,19 @@ def write(self, m):
46
46
47
47
if self .out :
48
48
self .out .write (m )
49
-
49
+
50
50
def move_cursor_to_end (self ):
51
51
"""Move cursor to end of text"""
52
52
line , index = self .get_end_pos ()
53
53
self .outputArea .setCursorPosition (line , index )
54
54
self .outputArea .ensureCursorVisible ()
55
55
self .outputArea .ensureLineVisible (line )
56
-
56
+
57
57
def get_end_pos (self ):
58
58
"""Return (line, index) position of the last character"""
59
59
line = self .outputArea .lines () - 1
60
60
return (line , self .outputArea .text (line ).length ())
61
-
61
+
62
62
def flush (self ):
63
63
pass
64
64
@@ -68,17 +68,17 @@ def __init__(self, parent=None):
68
68
super (EditorOutput ,self ).__init__ (parent )
69
69
self .parent = parent
70
70
self .edit = self .parent .edit
71
-
72
- # Enable non-ascii chars for editor
71
+
72
+ # Enable non-ascii chars for editor
73
73
self .setUtf8 (True )
74
-
74
+
75
75
sys .stdout = writeOut (self , sys .stdout )
76
76
sys .stderr = writeOut (self , sys .stderr , "traceback" )
77
-
77
+
78
78
self .insertInitText ()
79
79
self .setLexers ()
80
80
self .setReadOnly (True )
81
-
81
+
82
82
# Set the default font
83
83
font = QFont ()
84
84
font .setFamily ('Courier' )
@@ -102,42 +102,42 @@ def __init__(self, parent=None):
102
102
#self.setFolding(QsciScintilla.BoxedTreeFoldStyle)
103
103
#self.setFoldMarginColors(QColor("#99CC66"),QColor("#333300"))
104
104
#self.setWrapMode(QsciScintilla.WrapCharacter)
105
-
105
+
106
106
## Edge Mode
107
107
#self.setEdgeMode(QsciScintilla.EdgeLine)
108
108
#self.setEdgeColumn(80)
109
- #self.setEdgeColor(QColor("#FF0000"))
110
-
109
+ #self.setEdgeColor(QColor("#FF0000"))
110
+
111
111
self .setWrapMode (QsciScintilla .WrapCharacter )
112
112
self .SendScintilla (QsciScintilla .SCI_SETHSCROLLBAR , 0 )
113
-
113
+
114
114
self .runShortcut = QShortcut (QKeySequence (Qt .CTRL + Qt .Key_E ), self )
115
115
self .runShortcut .activated .connect (self .enteredSelected )
116
116
# Reimplemeted copy action to prevent paste prompt (>>>,...) in command view
117
117
self .copyShortcut = QShortcut (QKeySequence .Copy , self )
118
118
self .copyShortcut .activated .connect (self .copy )
119
119
self .selectAllShortcut = QShortcut (QKeySequence .SelectAll , self )
120
120
self .selectAllShortcut .activated .connect (self .selectAll )
121
-
121
+
122
122
def insertInitText (self ):
123
123
txtInit = QCoreApplication .translate ("PythonConsole" ,
124
124
"## To access Quantum GIS environment from this console\n "
125
125
"## use qgis.utils.iface object (instance of QgisInterface class). Read help for more info.\n \n " )
126
126
initText = self .setText (txtInit )
127
-
127
+
128
128
def refreshLexerProperties (self ):
129
129
self .setLexers ()
130
-
130
+
131
131
def setLexers (self ):
132
132
self .lexer = QsciLexerPython ()
133
-
133
+
134
134
settings = QSettings ()
135
135
loadFont = settings .value ("pythonConsole/fontfamilytext" , "Monospace" ).toString ()
136
136
fontSize = settings .value ("pythonConsole/fontsize" , 10 ).toInt ()[0 ]
137
137
font = QFont (loadFont )
138
138
font .setFixedPitch (True )
139
139
font .setPointSize (fontSize )
140
-
140
+
141
141
self .lexer .setDefaultFont (font )
142
142
self .lexer .setColor (Qt .red , 1 )
143
143
self .lexer .setColor (Qt .darkGreen , 5 )
@@ -153,40 +153,40 @@ def getTextFromEditor(self):
153
153
text = self .text ()
154
154
textList = text .split ("\n " )
155
155
return textList
156
-
156
+
157
157
def clearConsole (self ):
158
158
#self.SendScintilla(QsciScintilla.SCI_CLEARALL)
159
159
self .setText ('' )
160
160
self .insertInitText ()
161
161
self .edit .setFocus ()
162
-
163
- def contextMenuEvent (self , e ):
162
+
163
+ def contextMenuEvent (self , e ):
164
164
menu = QMenu (self )
165
165
iconRun = QIcon (":/images/console/iconRunConsole.png" )
166
166
iconPastebin = QIcon (":/images/console/iconCodepadConsole.png" )
167
167
iconClear = QIcon (":/images/console/iconClearConsole.png" )
168
168
iconHideTool = QIcon (":/images/console/iconHideToolConsole.png" )
169
- hideToolBar = menu .addAction (iconHideTool ,
170
- "Hide/Show Toolbar" ,
169
+ hideToolBar = menu .addAction (iconHideTool ,
170
+ "Hide/Show Toolbar" ,
171
171
self .hideToolBar )
172
172
menu .addSeparator ()
173
- runAction = menu .addAction (iconRun ,
174
- "Enter Selected" ,
175
- self .enteredSelected ,
173
+ runAction = menu .addAction (iconRun ,
174
+ "Enter Selected" ,
175
+ self .enteredSelected ,
176
176
QKeySequence (Qt .CTRL + Qt .Key_E ))
177
- clearAction = menu .addAction (iconClear ,
178
- "Clear console" ,
177
+ clearAction = menu .addAction (iconClear ,
178
+ "Clear console" ,
179
179
self .clearConsole )
180
180
menu .addSeparator ()
181
- copyAction = menu .addAction ("Copy" ,
182
- self .copy ,
181
+ copyAction = menu .addAction ("Copy" ,
182
+ self .copy ,
183
183
QKeySequence .Copy )
184
- pastebinAction = menu .addAction (iconPastebin ,
185
- "Share on codepad" ,
184
+ pastebinAction = menu .addAction (iconPastebin ,
185
+ "Share on codepad" ,
186
186
self .pastebin )
187
187
menu .addSeparator ()
188
- selectAllAction = menu .addAction ("Select All" ,
189
- self .selectAll ,
188
+ selectAllAction = menu .addAction ("Select All" ,
189
+ self .selectAll ,
190
190
QKeySequence .SelectAll )
191
191
runAction .setEnabled (False )
192
192
clearAction .setEnabled (False )
@@ -201,12 +201,12 @@ def contextMenuEvent(self, e):
201
201
selectAllAction .setEnabled (True )
202
202
clearAction .setEnabled (True )
203
203
action = menu .exec_ (self .mapToGlobal (e .pos ()))
204
-
204
+
205
205
def hideToolBar (self ):
206
206
tB = self .parent .toolBar
207
207
tB .hide () if tB .isVisible () else tB .show ()
208
208
self .edit .setFocus ()
209
-
209
+
210
210
def copy (self ):
211
211
"""Copy text to clipboard... or keyboard interrupt"""
212
212
if self .hasSelectedText ():
@@ -220,7 +220,7 @@ def enteredSelected(self):
220
220
cmd = self .selectedText ()
221
221
self .edit .insertFromDropPaste (cmd )
222
222
self .edit .entered ()
223
-
223
+
224
224
def keyPressEvent (self , e ):
225
225
# empty text indicates possible shortcut key sequence so stay in output
226
226
txt = e .text ()
0 commit comments