Skip to content

Commit

Permalink
Add automatic color highlighting to the LogView plugin. (#831)
Browse files Browse the repository at this point in the history
  • Loading branch information
larsbijl committed Dec 15, 2020
1 parent 70810ac commit 0ec4136
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 1 deletion.
4 changes: 4 additions & 0 deletions cuegui/cuegui/Constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,7 @@
COLOR_USER_4 = QtGui.QColor(50, 30, 0)

QT_MAX_INT = 2147483647

LOG_HIGHLIGHT_ERROR = ['error', 'aborted', 'fatal', 'failed', 'killed', 'command not found', 'no licenses could be found', 'killMessage']
LOG_HIGHLIGHT_WARN = ['warning', 'not found']
LOG_HIGHLIGHT_INFO = ['info:', 'rqd cmd:']
9 changes: 8 additions & 1 deletion cuegui/cuegui/DarkPalette.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,5 +127,12 @@ def ColorF(r, g, b):
COLOR_SHOW_FOREGROUND = GreyF(0.79)
COLOR_JOB_FOREGROUND = GreyF(0.79)

#Log file Colors
LOG_TIME = QtGui.QColor(170, 149, 171)
LOG_ERROR = QtGui.QColor(224, 52, 52)
LOG_WARNING = QtGui.QColor(255, 201, 25)
LOG_INFO = QtGui.QColor(111, 140, 255)
LOG_COMPLETE = QtGui.QColor(132, 201, 12)

KILL_ICON_COLOUR = QtGui.QColor(224, 52, 52)
PAUSE_ICON_COLOUR = QtGui.QColor(88, 163, 209)
PAUSE_ICON_COLOUR = QtGui.QColor(88, 163, 209)
74 changes: 74 additions & 0 deletions cuegui/cuegui/plugins/LogViewPlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from PySide2 import QtCore
from PySide2 import QtWidgets

import cuegui.Constants
import cuegui.AbstractDockWidget


Expand Down Expand Up @@ -362,6 +363,8 @@ def __init__(self, parent=None):
self._content_box.moveCursor(QtGui.QTextCursor.End)
self._content_box.ensureCursorVisible()

self.highlighter = Highlighter(self._content_box.document())

# Search
search_top_widget = QtWidgets.QWidget(self)
search_top_layout = QtWidgets.QVBoxLayout(search_top_widget)
Expand All @@ -376,6 +379,8 @@ def __init__(self, parent=None):
self._case_stv_checkbox.stateChanged.connect(self._move_to_search_box)

self._search_box = QtWidgets.QLineEdit('', self)
self._search_box.setClearButtonEnabled(True)
self._search_box.setPlaceholderText('Search log...')
search_layout.addWidget(self._search_box)
self._search_box.show()
self._search_box.editingFinished.connect(self._find_text)
Expand Down Expand Up @@ -862,3 +867,72 @@ def __init__(self, parent=None):
self, parent, PLUGIN_NAME, QtCore.Qt.RightDockWidgetArea)
self.logview_widget = LogViewWidget(self)
self.layout().addWidget(self.logview_widget)


class Highlighter(QtGui.QSyntaxHighlighter):
def __init__(self, parent=None):
super(Highlighter, self).__init__(parent)

self.on = True

self.timeFormat = QtGui.QTextCharFormat()
self.timeFormat.setFontWeight(QtGui.QFont.Bold)
self.timeFormat.setForeground(cuegui.Style.ColorTheme.LOG_TIME)

self.errorFormat = QtGui.QTextCharFormat()
self.errorFormat.setFontWeight(QtGui.QFont.Bold)
self.errorFormat.setForeground(cuegui.Style.ColorTheme.LOG_ERROR)

self.warnFormat = QtGui.QTextCharFormat()
self.warnFormat.setFontWeight(QtGui.QFont.Bold)
self.warnFormat.setForeground(cuegui.Style.ColorTheme.LOG_WARNING)

self.infoFormat = QtGui.QTextCharFormat()
self.infoFormat.setFontWeight(QtGui.QFont.Bold)
self.infoFormat.setForeground(cuegui.Style.ColorTheme.LOG_INFO)

self.completeFormat = QtGui.QTextCharFormat()
self.completeFormat.setFontWeight(QtGui.QFont.Bold)
self.completeFormat.setForeground(cuegui.Style.ColorTheme.LOG_COMPLETE)


def highlightBlock(self, text):
if not self.on:
return

line = text.lower()
done = False

for error in cuegui.Constants.LOG_HIGHLIGHT_ERROR:
if error in line:
self.setFormat(0, len(text), self.errorFormat)
done = True
break

if not done:
for warn in cuegui.Constants.LOG_HIGHLIGHT_WARN:
if warn in line:
self.setFormat(0, len(text), self.warnFormat)
done = True
break

if not done:
for info in cuegui.Constants.LOG_HIGHLIGHT_INFO:
if info in line:
self.setFormat(0, len(text), self.infoFormat)
done = True
break

if 'alf_progress' in line:
sidx = line.index('alf_progress')
eidx = line.index('%')
self.setFormat(sidx, eidx + 1, self.infoFormat)

if ' | ' in line:
idx = line.index(' | ')
self.setFormat(0, idx, self.timeFormat)

if 'render job complete' in line:
self.setFormat(0, len(text), self.completeFormat)

self.setCurrentBlockState(0)

0 comments on commit 0ec4136

Please sign in to comment.