Skip to content

Loading…

reimplement/revert API for capturing print statements from console #470

Closed
wants to merge 1 commit into from

2 participants

@slarosa

No description provided.

@brushtyler brushtyler was assigned
@slarosa slarosa was assigned
@slarosa

I have to review it and will apply manually

@slarosa slarosa closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Showing with 21 additions and 12 deletions.
  1. +10 −7 python/console/console_output.py
  2. +11 −5 python/console/console_sci.py
View
17 python/console/console_output.py
@@ -36,7 +36,8 @@ def __init__(self, edit, out=None, style=None):
self.outputArea = edit
self.out = None
self.style = style
-
+ self.data = ''
+
def write(self, m):
if self.style == "traceback":
# Show errors in red
@@ -45,12 +46,9 @@ def write(self, m):
self.outputArea.append(m)
self.outputArea.SendScintilla(QsciScintilla.SCI_SETSTYLING, len(m), 1)
else:
- self.outputArea.append(m)
+ self.data += m
self.move_cursor_to_end()
- if self.out:
- self.out.write(m)
-
def move_cursor_to_end(self):
"""Move cursor to end of text"""
line, index = self.get_end_pos()
@@ -62,6 +60,11 @@ def get_end_pos(self):
"""Return (line, index) position of the last character"""
line = self.outputArea.lines() - 1
return (line, self.outputArea.text(line).length())
+
+ def get_and_clean_data(self):
+ tmp = self.data
+ self.data = ''
+ return tmp
def flush(self):
pass
@@ -87,8 +90,8 @@ def __init__(self, parent=None):
# Enable non-ascii chars for editor
self.setUtf8(True)
- sys.stdout = writeOut(self, sys.stdout)
- sys.stderr = writeOut(self, sys.stderr, "traceback")
+ sys.stdout = writeOut(self)
+ sys.stderr = writeOut(self, style='traceback')
self.insertInitText()
self.setLexers()
View
16 python/console/console_sci.py
@@ -492,7 +492,7 @@ def currentCommand(self):
return cmd
def runCommand(self, cmd):
- self.write_stdout(cmd)
+ self.writeCMD(cmd)
import webbrowser
self.updateHistory(cmd)
line, pos = self.getCursorPosition()
@@ -524,14 +524,20 @@ def runCommand(self, cmd):
more = self.runsource(src, "<input>")
if not more:
self.buffer = []
- self.move_cursor_to_end()
+
+ output = sys.stdout.get_and_clean_data()
+ if output:
+ self.parent.textEditOut.append(output)
+
self.displayPrompt(more)
+ sys.stdout.move_cursor_to_end()
def write(self, txt):
sys.stderr.write(txt)
- def write_stdout(self, txt):
- if len(txt) > 0:
+ def writeCMD(self, cmd):
+ if len(cmd) > 0:
getCmdString = self.text()
prompt = getCmdString[0:4]
- sys.stdout.write(prompt+txt+'\n')
+ self.parent.textEditOut.append(prompt+cmd+'\n')
+ sys.stdout.move_cursor_to_end()
Something went wrong with that request. Please try again.