Skip to content
Snippets Groups Projects
Commit 6462f81c authored by Peterson, Peter's avatar Peterson, Peter
Browse files

Duplicate print statements to the console as well

The capture of print statements to the message display is useful, but
makes debuging crashes difficult because the message display disappears
before anything can be read. The solution is to write the print
statements to both places.
parent 4e929437
No related merge requests found
......@@ -29,6 +29,8 @@ from workbench.plugins.base import PluginWidget
# Default logs at notice
DEFAULT_LOG_PRIORITY = 5
ORIGINAL_STDOUT = sys.stdout
ORIGINAL_STDERR = sys.stderr
class LogMessageDisplay(PluginWidget):
......@@ -44,10 +46,10 @@ class LogMessageDisplay(PluginWidget):
self.setWindowTitle(self.get_plugin_title())
# output capture
stdout_capture, stderr_capture = WriteToSignal(), WriteToSignal()
stdout_capture.sig_write_received.connect(self.display.appendNotice)
stderr_capture.sig_write_received.connect(self.display.appendError)
self.stdout, self.stderr = stdout_capture, stderr_capture
self.stdout = WriteToSignal(ORIGINAL_STDOUT)
self.stdout.sig_write_received.connect(self.display.appendNotice)
self.stderr = WriteToSignal(ORIGINAL_STDERR)
self.stderr.sig_write_received.connect(self.display.appendError)
def get_plugin_title(self):
return "Messages"
......
......@@ -18,6 +18,7 @@ from __future__ import (absolute_import)
# std imports
import unittest
import sys
# 3rdparty
from qtpy.QtCore import QCoreApplication, QObject
......@@ -38,7 +39,7 @@ class WriteToSignalTest(GuiTest):
def test_connected_receiver_receives_text(self):
recv = Receiver()
writer = WriteToSignal()
writer = WriteToSignal(sys.stdout)
writer.sig_write_received.connect(recv.capture_text)
txt = "I expect to see this"
writer.write(txt)
......
......@@ -27,6 +27,9 @@ class WriteToSignal(QObject):
used to transform write requests to
Qt-signals. Mainly used to communicate
stdout/stderr across threads"""
def __init__(self, original_out):
QObject.__init__(self)
self.__original_out = original_out
sig_write_received = Signal(str)
......@@ -40,4 +43,7 @@ class WriteToSignal(QObject):
return False
def write(self, txt):
# write to the console
self.__original_out.write(txt)
# emit the signal which will write to logging
self.sig_write_received.emit(txt)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment