Skip to content

Commit

Permalink
fix issue #15
Browse files Browse the repository at this point in the history
- also fix the "follow" mode of the logger by using scrollToBotton instead of scrollTo
  • Loading branch information
cwiede committed May 19, 2020
1 parent 841a0be commit 7d294b6
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions nexxT/services/gui/GuiLogger.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
"""
import datetime
from queue import Queue
import time
from collections import deque
import traceback
import logging
from PySide2.QtCore import Qt, QTimer, QAbstractItemModel, QModelIndex
from PySide2.QtWidgets import QTableView, QHeaderView, QAction, QActionGroup
Expand All @@ -19,15 +18,22 @@
from nexxT.interface import Services
from nexxT.core.Utils import assertMainThread, handleException

logger = logging.getLogger(__name__)

class LogHandler(logging.Handler):
def __init__(self, logView):
super().__init__()
self.logView = logView

def emit(self, record):
msg = record.getMessage()
if record.exc_info is not None:
msg += "\n" + "".join(traceback.format_exception(*record.exc_info))
if msg[-1] == "\n":
msg = msg[:-1]
items = (str(datetime.datetime.fromtimestamp(record.created)),
record.levelno,
record.getMessage(),
msg,
record.name, record.filename, str(record.lineno))
self.logView.addLogRecord(items)

Expand Down Expand Up @@ -130,6 +136,7 @@ def __init__(self):
self.horizontalHeader().setSectionResizeMode(4, QHeaderView.ResizeToContents)
self.horizontalHeader().setSectionResizeMode(5, QHeaderView.ResizeToContents)
self.horizontalHeader().setStretchLastSection(False)
self.verticalHeader().setSectionResizeMode(QHeaderView.ResizeToContents)
self.timer = QTimer()
self.timer.setSingleShot(False)
self.timer.start(100)
Expand All @@ -143,7 +150,7 @@ def update(self):
if not self.queue.empty():
self.model.update(self.queue)
if self.follow:
self.scrollTo(self.model.index(self.model.rowCount(QModelIndex())-1, 0, QModelIndex()))
self.scrollToBottom()

def setFollow(self, follow):
self.follow = follow
Expand Down

0 comments on commit 7d294b6

Please sign in to comment.