Skip to content

Commit

Permalink
Merge pull request #1612 from peircej/master
Browse files Browse the repository at this point in the history
FF: better formatting of the Py3 stdout outputs from Builder experiments
  • Loading branch information
peircej committed Dec 6, 2017
2 parents 58da768 + c86d404 commit 7bccf55
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions psychopy/app/builder/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,10 @@
from . import experiment, components
from .. import stdOutRich, dialogs
from .. import projects
from psychopy import logging
from psychopy import logging, constants
from psychopy.tools.filetools import mergeFolder
from .dialogs import (DlgComponentProperties, DlgExperimentProperties,
DlgCodeComponentProperties)

from .flow import FlowPanel
from ..utils import FileDropTarget, WindowFrozen

Expand Down Expand Up @@ -2033,11 +2032,9 @@ def onProcessEnded(self, event=None):
# update the output window and show it
text = u""
if self.scriptProcess.IsInputAvailable():
stream = self.scriptProcess.GetInputStream()
text += u"{}".format(stream.read())
text += extractText(self.scriptProcess.GetInputStream())
if self.scriptProcess.IsErrorAvailable():
stream = self.scriptProcess.GetErrorStream()
text += u"{}".format(stream.read())
text += extractText(self.scriptProcess.GetErrorStream())
if len(text):
# if some text hadn't yet been written (possible?)
self.stdoutFrame.write(text)
Expand Down Expand Up @@ -2361,3 +2358,14 @@ def __init__(self, parent, ID, title, size=wx.DefaultSize,
sizer.Add(btnsizer, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALL, 5)

self.SetSizerAndFit(sizer)

def extractText(stream):
"""Take a byte stream (or any file object of type b?) and return
:param stream: stream from wx.Process or any byte stream from a file
:return: text converted to unicode ready for appending to wx text view
"""
if constants.PY3:
return stream.read().decode('utf-8')
else:
return stream.read()

0 comments on commit 7bccf55

Please sign in to comment.