Add ConsoleWidget.write(scrollToBottom) argument
This commit is contained in:
parent
f2baf31d51
commit
b9f6a28884
@ -101,7 +101,6 @@ class ConsoleWidget(QtGui.QWidget):
|
|||||||
pickle.dump(open(self.historyFile, 'wb'), history)
|
pickle.dump(open(self.historyFile, 'wb'), history)
|
||||||
|
|
||||||
def runCmd(self, cmd):
|
def runCmd(self, cmd):
|
||||||
#cmd = str(self.input.lastCmd)
|
|
||||||
self.stdout = sys.stdout
|
self.stdout = sys.stdout
|
||||||
self.stderr = sys.stderr
|
self.stderr = sys.stderr
|
||||||
encCmd = re.sub(r'>', '>', re.sub(r'<', '<', cmd))
|
encCmd = re.sub(r'>', '>', re.sub(r'<', '<', cmd))
|
||||||
@ -114,22 +113,20 @@ class ConsoleWidget(QtGui.QWidget):
|
|||||||
sys.stdout = self
|
sys.stdout = self
|
||||||
sys.stderr = self
|
sys.stderr = self
|
||||||
if self.multiline is not None:
|
if self.multiline is not None:
|
||||||
self.write("<br><b>%s</b>\n"%encCmd, html=True)
|
self.write("<br><b>%s</b>\n"%encCmd, html=True, scrollToBottom=True)
|
||||||
self.execMulti(cmd)
|
self.execMulti(cmd)
|
||||||
else:
|
else:
|
||||||
self.write("<br><div style='background-color: #CCF; color: black'><b>%s</b>\n"%encCmd, html=True)
|
self.write("<br><div style='background-color: #CCF; color: black'><b>%s</b>\n"%encCmd, html=True, scrollToBottom=True)
|
||||||
self.inCmd = True
|
self.inCmd = True
|
||||||
self.execSingle(cmd)
|
self.execSingle(cmd)
|
||||||
|
|
||||||
if not self.inCmd:
|
if not self.inCmd:
|
||||||
self.write("</div>\n", html=True)
|
self.write("</div>\n", html=True, scrollToBottom=True)
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
sys.stdout = self.stdout
|
sys.stdout = self.stdout
|
||||||
sys.stderr = self.stderr
|
sys.stderr = self.stderr
|
||||||
|
|
||||||
sb = self.output.verticalScrollBar()
|
|
||||||
sb.setValue(sb.maximum())
|
|
||||||
sb = self.ui.historyList.verticalScrollBar()
|
sb = self.ui.historyList.verticalScrollBar()
|
||||||
sb.setValue(sb.maximum())
|
sb.setValue(sb.maximum())
|
||||||
|
|
||||||
@ -201,11 +198,23 @@ class ConsoleWidget(QtGui.QWidget):
|
|||||||
self.displayException()
|
self.displayException()
|
||||||
self.multiline = None
|
self.multiline = None
|
||||||
|
|
||||||
def write(self, strn, html=False):
|
def write(self, strn, html=False, scrollToBottom='auto'):
|
||||||
|
"""Write a string into the console.
|
||||||
|
|
||||||
|
If scrollToBottom is 'auto', then the console is automatically scrolled
|
||||||
|
to fit the new text only if it was already at the bottom.
|
||||||
|
"""
|
||||||
isGuiThread = QtCore.QThread.currentThread() == QtCore.QCoreApplication.instance().thread()
|
isGuiThread = QtCore.QThread.currentThread() == QtCore.QCoreApplication.instance().thread()
|
||||||
if not isGuiThread:
|
if not isGuiThread:
|
||||||
self.stdout.write(strn)
|
self.stdout.write(strn)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
sb = self.output.verticalScrollBar()
|
||||||
|
scroll = sb.value()
|
||||||
|
if scrollToBottom == 'auto':
|
||||||
|
atBottom = scroll == sb.maximum()
|
||||||
|
scrollToBottom = atBottom
|
||||||
|
|
||||||
self.output.moveCursor(QtGui.QTextCursor.End)
|
self.output.moveCursor(QtGui.QTextCursor.End)
|
||||||
if html:
|
if html:
|
||||||
self.output.textCursor().insertHtml(strn)
|
self.output.textCursor().insertHtml(strn)
|
||||||
@ -213,9 +222,12 @@ class ConsoleWidget(QtGui.QWidget):
|
|||||||
if self.inCmd:
|
if self.inCmd:
|
||||||
self.inCmd = False
|
self.inCmd = False
|
||||||
self.output.textCursor().insertHtml("</div><br><div style='font-weight: normal; background-color: #FFF; color: black'>")
|
self.output.textCursor().insertHtml("</div><br><div style='font-weight: normal; background-color: #FFF; color: black'>")
|
||||||
#self.stdout.write("</div><br><div style='font-weight: normal; background-color: #FFF;'>")
|
|
||||||
self.output.insertPlainText(strn)
|
self.output.insertPlainText(strn)
|
||||||
#self.stdout.write(strn)
|
|
||||||
|
if scrollToBottom:
|
||||||
|
sb.setValue(sb.maximum())
|
||||||
|
else:
|
||||||
|
sb.setValue(scroll)
|
||||||
|
|
||||||
def displayException(self):
|
def displayException(self):
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user