From 00b688cab07ee16fe648f26401344260e5c7dedf Mon Sep 17 00:00:00 2001 From: whitequark Date: Thu, 14 Jan 2016 18:57:24 +0000 Subject: [PATCH] gui: wrap very long words too (fixes #187). --- artiq/gui/log.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/artiq/gui/log.py b/artiq/gui/log.py index 6ab5d0ae0..b07fb1c84 100644 --- a/artiq/gui/log.py +++ b/artiq/gui/log.py @@ -1,6 +1,7 @@ import asyncio import logging import time +import re from functools import partial from quamash import QtGui, QtCore @@ -14,13 +15,19 @@ except AttributeError: QSortFilterProxyModel = QtGui.QSortFilterProxyModel +def _make_wrappable(row, width=30): + level, source, time, msg = row + msg = re.sub("(\\S{{{}}})".format(width), "\\1\u200b", msg) + return [level, source, time, msg] + + class Model(QtCore.QAbstractTableModel): def __init__(self, init): QtCore.QAbstractTableModel.__init__(self) self.headers = ["Level", "Source", "Time", "Message"] - self.entries = init + self.entries = list(map(_make_wrappable, init)) self.pending_entries = [] self.depth = 1000 timer = QtCore.QTimer(self) @@ -52,7 +59,7 @@ class Model(QtCore.QAbstractTableModel): pass def append(self, v): - self.pending_entries.append(v) + self.pending_entries.append(_make_wrappable(v)) def insertRows(self, position, rows=1, index=QtCore.QModelIndex()): self.beginInsertRows(QtCore.QModelIndex(), position, position+rows-1)