24
24
from PyQt4 .Qsci import (QsciScintilla ,
25
25
QsciScintillaBase ,
26
26
QsciLexerPython )
27
- from console_sci import PythonEdit
27
+
28
28
import sys
29
29
30
30
class writeOut :
31
31
def __init__ (self , edit , out = None , style = None ):
32
32
"""
33
33
This class allow to write stdout and stderr
34
34
"""
35
- self .editor = edit
35
+ self .outputArea = edit
36
36
self .out = None
37
37
self .style = style
38
38
39
39
def write (self , m ):
40
40
if self .style == "traceback" :
41
- self .editor .SendScintilla (QsciScintilla .SCI_SETSTYLING , len (m ), 1 )
42
- self .editor .append (m )
43
- self .editor .SendScintilla (QsciScintilla .SCI_SETSTYLING , len (m ), 1 )
41
+ self .outputArea .SendScintilla (QsciScintilla .SCI_SETSTYLING , len (m ), 1 )
42
+ self .outputArea .append (m )
43
+ self .outputArea .SendScintilla (QsciScintilla .SCI_SETSTYLING , len (m ), 1 )
44
44
else :
45
- self .editor .append (m )
45
+ self .outputArea .append (m )
46
46
self .move_cursor_to_end ()
47
47
48
48
if self .out :
@@ -51,14 +51,14 @@ def write(self, m):
51
51
def move_cursor_to_end (self ):
52
52
"""Move cursor to end of text"""
53
53
line , index = self .get_end_pos ()
54
- self .editor .setCursorPosition (line , index )
55
- self .editor .ensureCursorVisible ()
56
- self .editor .ensureLineVisible (line )
54
+ self .outputArea .setCursorPosition (line , index )
55
+ self .outputArea .ensureCursorVisible ()
56
+ self .outputArea .ensureLineVisible (line )
57
57
58
58
def get_end_pos (self ):
59
59
"""Return (line, index) position of the last character"""
60
- line = self .editor .lines () - 1
61
- return (line , self .editor .text (line ).length ())
60
+ line = self .outputArea .lines () - 1
61
+ return (line , self .outputArea .text (line ).length ())
62
62
63
63
def flush (self ):
64
64
pass
@@ -67,13 +67,15 @@ class EditorOutput(QsciScintilla):
67
67
def __init__ (self , parent = None ):
68
68
#QsciScintilla.__init__(self, parent)
69
69
super (EditorOutput ,self ).__init__ (parent )
70
- # Enable non-ascii chars for editor
70
+ self .parent = parent
71
+ self .edit = self .parent .edit
72
+
73
+ # Enable non-ascii chars for editor
71
74
self .setUtf8 (True )
72
75
73
76
sys .stdout = writeOut (self , sys .stdout )
74
77
sys .stderr = writeOut (self , sys .stderr , "traceback" )
75
78
76
- self .edit = PythonEdit ()
77
79
self .setLexers ()
78
80
self .setReadOnly (True )
79
81
@@ -101,7 +103,7 @@ def __init__(self, parent=None):
101
103
#self.setFoldMarginColors(QColor("#99CC66"),QColor("#333300"))
102
104
#self.setWrapMode(QsciScintilla.WrapCharacter)
103
105
104
- ## Edge Mode : does not seems to work
106
+ ## Edge Mode
105
107
#self.setEdgeMode(QsciScintilla.EdgeLine)
106
108
#self.setEdgeColumn(80)
107
109
#self.setEdgeColor(QColor("#FF0000"))
@@ -114,7 +116,7 @@ def __init__(self, parent=None):
114
116
# Reimplemeted copy action to prevent paste prompt (>>>,...) in command view
115
117
self .copyShortcut = QShortcut (QKeySequence (Qt .CTRL + Qt .Key_C ), self )
116
118
self .copyShortcut .activated .connect (self .copy )
117
-
119
+
118
120
def refreshLexerProperties (self ):
119
121
self .setLexers ()
120
122
@@ -174,4 +176,15 @@ def enteredSelected(self):
174
176
cmd = self .selectedText ()
175
177
self .edit .insertFromDropPaste (cmd )
176
178
self .edit .entered ()
177
-
179
+
180
+ def keyPressEvent (self , e ):
181
+ # empty text indicates possible shortcut key sequence so stay in output
182
+ txt = e .text ()
183
+ if txt .length () and txt >= " " :
184
+ self .edit .append (txt )
185
+ self .edit .move_cursor_to_end ()
186
+ self .edit .setFocus ()
187
+ e .ignore ()
188
+ else :
189
+ # possible shortcut key sequence, accept it
190
+ e .accept ()
0 commit comments