Skip to content

Commit

Permalink
canvas/outputview: Copy the document and connect to stdout/err
Browse files Browse the repository at this point in the history
  • Loading branch information
ales-erjavec committed Dec 8, 2017
1 parent 9402238 commit 5ea0f16
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions Orange/canvas/application/canvasmain.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@
from AnyQt.QtWidgets import (
QMainWindow, QWidget, QAction, QActionGroup, QMenu, QMenuBar, QDialog,
QFileDialog, QMessageBox, QVBoxLayout, QSizePolicy, QToolBar, QToolButton,
QDockWidget, QApplication, QShortcut, QPlainTextEdit, QFileIconProvider
QDockWidget, QApplication, QShortcut, QPlainTextEdit,
QPlainTextDocumentLayout, QFileIconProvider,
)
from AnyQt.QtGui import (
QColor, QIcon, QDesktopServices, QKeySequence, QTextDocument
)
from AnyQt.QtGui import QColor, QIcon, QDesktopServices, QKeySequence

from AnyQt.QtCore import (
Qt, QEvent, QSize, QUrl, QTimer, QFile, QByteArray, QSettings,
Expand Down Expand Up @@ -59,7 +62,7 @@ def user_documents_path():
CategoryPopupMenu, popup_position_from_source
from .aboutdialog import AboutDialog
from .schemeinfo import SchemeInfoDialog
from .outputview import OutputView
from .outputview import OutputView, TextStream
from .settings import UserSettingsDialog

from ..document.schemeedit import SchemeEditWidget
Expand Down Expand Up @@ -896,10 +899,22 @@ def create_new_window(self):
window.set_tool_dock_expanded(self.dock_widget.expanded())

logview = window.log_view() # type: OutputView

te = logview.findChild(QPlainTextEdit)
te1 = self.log_view().findChild(QPlainTextEdit)
te.setDocument(te1.document())

doc = self.log_view().findChild(QPlainTextEdit).document()
# first clone the existing document and set it on the new instance
doc = doc.clone(parent=te) # type: QTextDocument
doc.setDocumentLayout(QPlainTextDocumentLayout(doc))
te.setDocument(doc)

# route the stdout/err if possible
stdout, stderr = sys.stdout, sys.stderr
if isinstance(stdout, TextStream):
stdout.stream.connect(logview.write)

if isinstance(stderr, TextStream):
logview._err_formater = logview.formated(color=Qt.red)
stderr.stream.connect(logview._err_formater.write)

CanvasMainWindow._instances.append(window)
window.destroyed.connect(
Expand Down

0 comments on commit 5ea0f16

Please sign in to comment.