console fixes

- add fileno method since console occludes sys.stdout
- fix editor spawning
- don't store sys.stdout, since this is not guaranteed to be the real stdout
This commit is contained in:
Luke Campagnola 2020-07-05 23:06:05 -07:00
parent ac417a6567
commit 6f69b11c26

View File

@ -109,8 +109,10 @@ class ConsoleWidget(QtGui.QWidget):
pickle.dump(pf, history)
def runCmd(self, cmd):
self.stdout = sys.stdout
self.stderr = sys.stderr
#cmd = str(self.input.lastCmd)
orig_stdout = sys.stdout
orig_stderr = sys.stderr
encCmd = re.sub(r'>', '&gt;', re.sub(r'<', '&lt;', cmd))
encCmd = re.sub(r' ', '&nbsp;', encCmd)
@ -132,8 +134,8 @@ class ConsoleWidget(QtGui.QWidget):
self.write("</div>\n", html=True, scrollToBottom=True)
finally:
sys.stdout = self.stdout
sys.stderr = self.stderr
sys.stdout = orig_stdout
sys.stderr = orig_stderr
sb = self.ui.historyList.verticalScrollBar()
sb.setValue(sb.maximum())
@ -178,7 +180,6 @@ class ConsoleWidget(QtGui.QWidget):
self.displayException()
def execMulti(self, nextLine):
#self.stdout.write(nextLine+"\n")
if nextLine.strip() != '':
self.multiline += "\n" + nextLine
return
@ -214,7 +215,7 @@ class ConsoleWidget(QtGui.QWidget):
"""
isGuiThread = QtCore.QThread.currentThread() == QtCore.QCoreApplication.instance().thread()
if not isGuiThread:
self.stdout.write(strn)
sys.__stdout__.write(strn)
return
sb = self.output.verticalScrollBar()
@ -237,6 +238,11 @@ class ConsoleWidget(QtGui.QWidget):
else:
sb.setValue(scroll)
def fileno(self):
# Need to implement this since we temporarily occlude sys.stdout, and someone may be looking for it (faulthandler, for example)
return 1
def displayException(self):
"""
Display the current exception and stack.
@ -319,8 +325,8 @@ class ConsoleWidget(QtGui.QWidget):
if editor is None:
return
tb = self.currentFrame()
lineNum = tb.tb_lineno
fileName = tb.tb_frame.f_code.co_filename
lineNum = tb.f_lineno
fileName = tb.f_code.co_filename
subprocess.Popen(self.editor.format(fileName=fileName, lineNum=lineNum), shell=True)
def updateSysTrace(self):