Skip to content

Commit

Permalink
highlight log
Browse files Browse the repository at this point in the history
  • Loading branch information
hanjinliu committed Aug 17, 2021
1 parent 084c39b commit d420543
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions impy/viewer/widgets/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,24 @@
import napari
from qtpy.QtWidgets import QPlainTextEdit
from qtpy.QtGui import QFont
from qtpy.QtCore import Qt

from .textedit import WordHighlighter

class LoggerWidget(QPlainTextEdit):
def __init__(self, viewer:"napari.Viewer"):
super().__init__(viewer.window._qt_window)
self.setReadOnly(True)
self.setMaximumBlockCount(500)
self.setFont(QFont("Consolas"))

self.highlighter = WordHighlighter(self.document())
self.highlighter.appendRule(r"[a-zA-Z]+Warning", fcolor=Qt.yellow)
self.highlighter.appendRule(r"[a-zA-Z]+Error", fcolor=Qt.red)

def appendPlainText(self, text:str):
super().appendPlainText(text)
self.highlighter.setDocument(self.document())
self.verticalScrollBar().setValue(self.verticalScrollBar().maximum())
return None

Expand Down

0 comments on commit d420543

Please sign in to comment.