source: orange/Orange/OrangeCanvas/application/outputview.py @ 11167:74773cf295d6

Revision 11167:74773cf295d6, 1.5 KB checked in by Ales Erjavec <ales.erjavec@…>, 18 months ago (diff)

Added 'Output' window showing redirected stdout/stderr.

Line 
1"""
2"""
3
4from PyQt4.QtGui import (
5    QWidget, QPlainTextEdit, QVBoxLayout, QTextCursor
6)
7
8from PyQt4.QtCore import Qt
9
10
11class OutputText(QWidget):
12    def __init__(self, parent=None, **kwargs):
13        QWidget.__init__(self, parent, **kwargs)
14
15        self.__lines = 5000
16
17        self.setLayout(QVBoxLayout())
18        self.layout().setContentsMargins(0, 0, 0, 0)
19
20        self.__text = QPlainTextEdit()
21        self.__text.setTextInteractionFlags(Qt.TextBrowserInteraction)
22        self.__text.setMaximumBlockCount(self.__lines)
23        font = self.__text.font()
24        font.setFamily("Monaco")
25        self.__text.setFont(font)
26
27        self.layout().addWidget(self.__text)
28
29    def setMaximumLines(self, lines):
30        """Set the maximum number of lines to keep displayed.
31        """
32        if self.__lines != lines:
33            self.__lines = lines
34            self.__text.setMaximumBlockCount(lines)
35
36    def maximumLines(self):
37        """Return the maximum number of lines in the display.
38        """
39        return self.__lines
40
41    def clear(self):
42        """Clear the displayed text.
43        """
44        self.__text.clear()
45
46    def toPlainText(self):
47        """Return the full contents of the output view.
48        """
49        return self.__text.toPlainText()
50
51    # A file like interface.
52    def write(self, string):
53        self.__text.moveCursor(QTextCursor.End, QTextCursor.MoveAnchor)
54        self.__text.insertPlainText(string)
55
56    def writelines(self, lines):
57        for line in lines:
58            self.write(line)
59
60    def flush(self):
61        pass
Note: See TracBrowser for help on using the repository browser.