From d42054363d463f66218f5fc2816a54934a9b2b56 Mon Sep 17 00:00:00 2001
From: hanjinliu <hanjin.liu@bs.s.u-tokyo.ac.jp>
Date: Wed, 18 Aug 2021 00:10:23 +0900
Subject: [PATCH] highlight log

---
 impy/viewer/widgets/log.py | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/impy/viewer/widgets/log.py b/impy/viewer/widgets/log.py
index 8d30d06c..ca7a13c7 100644
--- a/impy/viewer/widgets/log.py
+++ b/impy/viewer/widgets/log.py
@@ -2,6 +2,9 @@
 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"):
@@ -9,9 +12,14 @@ def __init__(self, viewer:"napari.Viewer"):
         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