gui console: better formatting of input/output

Change-Id: I2ffb3712bb4ef5dcdfbcae869e4971bdc7a116ad
Reviewed-on: https://forge.frm2.tum.de/review/c/secop/frappy/+/30490
Tested-by: Jenkins Automated Tests <pedersen+jenkins@frm2.tum.de>
Reviewed-by: Georg Brandl <g.brandl@fz-juelich.de>
This commit is contained in:
Georg Brandl 2023-02-21 16:45:53 +01:00 committed by Markus Zolliker
parent a1141c87c9
commit ee9f8536b2

View File

@ -1,6 +1,5 @@
from collections import OrderedDict from collections import OrderedDict
import json import json
import pprint
import frappy.gui.resources # pylint: disable=unused-import import frappy.gui.resources # pylint: disable=unused-import
from frappy.gui.qt import QFont, QFontMetrics, QLabel, QTextCursor, QWidget, \ from frappy.gui.qt import QFont, QFontMetrics, QLabel, QTextCursor, QWidget, \
@ -31,7 +30,7 @@ class Console(QWidget):
self._addLogEntry( self._addLogEntry(
'<span style="font-weight:bold">Request:</span> ' '<span style="font-weight:bold">Request:</span> '
'%s:' % msg, '<tt>%s</tt>' % toHtmlEscaped(msg),
raw=True) raw=True)
# msg = msg.split(' ', 2) # msg = msg.split(' ', 2)
try: try:
@ -40,22 +39,16 @@ class Console(QWidget):
_, eid, stuff = self._node.decode_message(reply) _, eid, stuff = self._node.decode_message(reply)
reply = '%s %s %s' % (_, eid, json.dumps( reply = '%s %s %s' % (_, eid, json.dumps(
stuff, indent=2, separators=(',', ':'), sort_keys=True)) stuff, indent=2, separators=(',', ':'), sort_keys=True))
self._addLogEntry(reply, newline=True, pretty=False) self._addLogEntry(reply.rstrip('\n'))
else: else:
self._addLogEntry(reply, newline=True, pretty=False) self._addLogEntry(reply.rstrip('\n'))
except SECoPError as e: except SECoPError as e:
einfo = e.args[0] if len(e.args) == 1 else json.dumps(e.args) einfo = e.args[0] if len(e.args) == 1 else json.dumps(e.args)
self._addLogEntry( self._addLogEntry('%s: %s' % (e.name, einfo), error=True)
'%s: %s' % (e.name, einfo),
newline=True,
pretty=False,
error=True)
except Exception as e: except Exception as e:
self._addLogEntry( self._addLogEntry('error when sending %r: %r' % (msg, e), error=True)
'error when sending %r: %r' % (msg, e),
newline=True, self.msgLineEdit.selectAll()
pretty=False,
error=True)
@pyqtSlot() @pyqtSlot()
def on_clearPushButton_clicked(self): def on_clearPushButton_clicked(self):
@ -64,20 +57,12 @@ class Console(QWidget):
def _clearLog(self): def _clearLog(self):
self.logTextBrowser.clear() self.logTextBrowser.clear()
self._addLogEntry('SECoP Communication Shell') self._addLogEntry('<div style="font-weight: bold">'
self._addLogEntry('=========================') 'SECoP Communication Shell<br/>'
self._addLogEntry('', newline=True) '=========================<br/></div>',
raw=True)
def _addLogEntry(self,
msg,
newline=False,
pretty=False,
raw=False,
error=False):
if pretty:
msg = pprint.pformat(msg, width=self._getLogWidth())
msg = msg[1:-1]
def _addLogEntry(self, msg, raw=False, error=False):
if not raw: if not raw:
if error: if error:
msg = '<div style="color:#FF0000"><b><pre>%s</pre></b></div>' % toHtmlEscaped( msg = '<div style="color:#FF0000"><b><pre>%s</pre></b></div>' % toHtmlEscaped(
@ -91,9 +76,6 @@ class Console(QWidget):
content = self.logTextBrowser.toHtml() content = self.logTextBrowser.toHtml()
content += msg content += msg
if newline:
content += '<br />'
self.logTextBrowser.setHtml(content) self.logTextBrowser.setHtml(content)
self.logTextBrowser.moveCursor(QTextCursor.End) self.logTextBrowser.moveCursor(QTextCursor.End)