Removed background highlighting in shell.

This commit is contained in:
Juan Pablo Caram
2016-03-25 21:28:02 -04:00
parent f543dca448
commit 05a9e05c97

View File

@@ -19,13 +19,13 @@ class _ExpandableTextEdit(QTextEdit):
historyNext = pyqtSignal() historyNext = pyqtSignal()
historyPrev = pyqtSignal() historyPrev = pyqtSignal()
def __init__(self, termWidget, *args): def __init__(self, termwidget, *args):
QTextEdit.__init__(self, *args) QTextEdit.__init__(self, *args)
self.setStyleSheet("font: 9pt \"Courier\";") self.setStyleSheet("font: 9pt \"Courier\";")
self._fittedHeight = 1 self._fittedHeight = 1
self.textChanged.connect(self._fit_to_document) self.textChanged.connect(self._fit_to_document)
self._fit_to_document() self._fit_to_document()
self._termWidget = termWidget self._termWidget = termwidget
def sizeHint(self): def sizeHint(self):
""" """
@@ -39,10 +39,10 @@ class _ExpandableTextEdit(QTextEdit):
""" """
Update widget height to fit all text Update widget height to fit all text
""" """
documentSize = self.document().size().toSize() documentsize = self.document().size().toSize()
self._fittedHeight = documentSize.height() + (self.height() - self.viewport().height()) self._fittedHeight = documentsize.height() + (self.height() - self.viewport().height())
self.setMaximumHeight(self._fittedHeight) self.setMaximumHeight(self._fittedHeight)
self.updateGeometry(); self.updateGeometry()
def keyPressEvent(self, event): def keyPressEvent(self, event):
""" """
@@ -55,26 +55,26 @@ class _ExpandableTextEdit(QTextEdit):
return return
elif event.matches(QKeySequence.MoveToNextLine): elif event.matches(QKeySequence.MoveToNextLine):
text = self.toPlainText() text = self.toPlainText()
cursorPos = self.textCursor().position() cursor_pos = self.textCursor().position()
textBeforeEnd = text[cursorPos:] textBeforeEnd = text[cursor_pos:]
# if len(textBeforeEnd.splitlines()) <= 1: # if len(textBeforeEnd.splitlines()) <= 1:
if len(textBeforeEnd.split('\n')) <= 1: if len(textBeforeEnd.split('\n')) <= 1:
self.historyNext.emit() self.historyNext.emit()
return return
elif event.matches(QKeySequence.MoveToPreviousLine): elif event.matches(QKeySequence.MoveToPreviousLine):
text = self.toPlainText() text = self.toPlainText()
cursorPos = self.textCursor().position() cursor_pos = self.textCursor().position()
textBeforeStart = text[:cursorPos] text_before_start = text[:cursor_pos]
# lineCount = len(textBeforeStart.splitlines()) # lineCount = len(textBeforeStart.splitlines())
lineCount = len(textBeforeStart.split('\n')) line_count = len(text_before_start.split('\n'))
if len(textBeforeStart) > 0 and \ if len(text_before_start) > 0 and \
(textBeforeStart[-1] == '\n' or textBeforeStart[-1] == '\r'): (text_before_start[-1] == '\n' or text_before_start[-1] == '\r'):
lineCount += 1 line_count += 1
if lineCount <= 1: if line_count <= 1:
self.historyPrev.emit() self.historyPrev.emit()
return return
elif event.matches(QKeySequence.MoveToNextPage) or \ elif event.matches(QKeySequence.MoveToNextPage) or \
event.matches(QKeySequence.MoveToPreviousPage): event.matches(QKeySequence.MoveToPreviousPage):
return self._termWidget.browser().keyPressEvent(event) return self._termWidget.browser().keyPressEvent(event)
QTextEdit.keyPressEvent(self, event) QTextEdit.keyPressEvent(self, event)
@@ -94,8 +94,9 @@ class TermWidget(QWidget):
self._browser = QTextEdit(self) self._browser = QTextEdit(self)
self._browser.setStyleSheet("font: 9pt \"Courier\";") self._browser.setStyleSheet("font: 9pt \"Courier\";")
self._browser.setReadOnly(True) self._browser.setReadOnly(True)
self._browser.document().setDefaultStyleSheet(self._browser.document().defaultStyleSheet() + self._browser.document().setDefaultStyleSheet(
"span {white-space:pre;}") self._browser.document().defaultStyleSheet() +
"span {white-space:pre;}")
self._edit = _ExpandableTextEdit(self, self) self._edit = _ExpandableTextEdit(self, self)
self._edit.historyNext.connect(self._on_history_next) self._edit.historyNext.connect(self._on_history_next)
@@ -120,30 +121,12 @@ class TermWidget(QWidget):
assert style in ('in', 'out', 'err') assert style in ('in', 'out', 'err')
text = cgi.escape(text) text = cgi.escape(text)
text = text.replace('\n', '<br/>') text = text.replace('\n', '<br/>')
if style != 'out': if style == 'in':
def_bg = self._browser.palette().color(QPalette.Base) text = '<span style="font-weight: bold;">%s</span>' % text
h, s, v, a = def_bg.getHsvF() elif style == 'err':
text = '<span style="font-weight: bold; color: red;">%s</span>' % text
if style == 'in':
if v > 0.5: # white background
v = v - (v / 8) # make darker
else:
v = v + ((1 - v) / 4) # make ligher
else: # err
if v < 0.5:
v = v + ((1 - v) / 4) # make ligher
if h == -1: # make red
h = 0
s = .4
else:
h = h + ((1 - h) * 0.5) # make more red
bg = QColor.fromHsvF(h, s, v).name()
text = '<span style="background-color: %s; font-weight: bold;">%s</span>' % (str(bg), text)
else: else:
text = '<span>%s</span>' % text # without span <br/> is ignored!!! text = '<span>%s</span>' % text # without span <br/> is ignored!!!