gui: wrap very long words too (fixes #187).

This commit is contained in:
whitequark 2016-01-14 18:57:24 +00:00
parent 79986791bc
commit 00b688cab0
1 changed files with 9 additions and 2 deletions

View File

@ -1,6 +1,7 @@
import asyncio import asyncio
import logging import logging
import time import time
import re
from functools import partial from functools import partial
from quamash import QtGui, QtCore from quamash import QtGui, QtCore
@ -14,13 +15,19 @@ except AttributeError:
QSortFilterProxyModel = QtGui.QSortFilterProxyModel 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): class Model(QtCore.QAbstractTableModel):
def __init__(self, init): def __init__(self, init):
QtCore.QAbstractTableModel.__init__(self) QtCore.QAbstractTableModel.__init__(self)
self.headers = ["Level", "Source", "Time", "Message"] self.headers = ["Level", "Source", "Time", "Message"]
self.entries = init self.entries = list(map(_make_wrappable, init))
self.pending_entries = [] self.pending_entries = []
self.depth = 1000 self.depth = 1000
timer = QtCore.QTimer(self) timer = QtCore.QTimer(self)
@ -52,7 +59,7 @@ class Model(QtCore.QAbstractTableModel):
pass pass
def append(self, v): 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()): def insertRows(self, position, rows=1, index=QtCore.QModelIndex()):
self.beginInsertRows(QtCore.QModelIndex(), position, position+rows-1) self.beginInsertRows(QtCore.QModelIndex(), position, position+rows-1)