def main(): app = QtWidgets.QApplication(sys.argv) window = QtWidgets.QWidget() layout = QtWidgets.QVBoxLayout(window) outputbox = OutputBox(layout) funcs = [ regular_print_stdout, regular_print_stderr, libc_printf, echo_hello, multiprocessing_Process, ] for f in funcs: button = QtWidgets.QPushButton(f.__name__) button.clicked.connect(f) layout.addWidget(button) redirect_stdout = OutputInterceptor('localhost', outputbox.port) redirect_sterr = OutputInterceptor('localhost', outputbox.port, streamname='stderr') redirect_stdout.connect() redirect_sterr.connect() window.resize(800, 500) window.show() app.exec_() redirect_stdout.disconnect() redirect_sterr.disconnect() outputbox.shutdown()
def __init__(self, imagepath): self.qapplication = QtWidgets.QApplication.instance() if self.qapplication is None: self.qapplication = QtWidgets.QApplication(sys.argv) QtWidgets.QFrame.__init__(self) self.icon = QtGui.QPixmap() self.icon.load(imagepath) if self.icon.isNull(): raise ValueError("Invalid image file: {}.\n".format(imagepath)) self.icon = self.icon.scaled(self.imwidth, self.imheight, Qt.KeepAspectRatio, Qt.SmoothTransformation) self.text = 'Loading' self.setWindowFlags(Qt.SplashScreen) self.setWindowOpacity(self.alpha) self.label = QtWidgets.QLabel(self.text) self.setStyleSheet("background-color: %s; font-size: 10pt" % self.BG) # Frame not necessary on macos, and looks ugly. if sys.platform != 'darwin': self.setFrameShape(QtWidgets.QFrame.StyledPanel) self.label.setWordWrap(True) self.label.setAlignment(Qt.AlignCenter) self.resize(self.w, self.h) image_label = QtWidgets.QLabel() image_label.setPixmap(self.icon) image_label.setAlignment(Qt.AlignCenter) layout = QtWidgets.QVBoxLayout(self) layout.addWidget(image_label) layout.addWidget(self.label) center_point = QtWidgets.QDesktopWidget().availableGeometry().center() x0, y0 = center_point.x(), center_point.y() self.move(x0 - self.w / 2, y0 - self.h / 2) self._first_paint_complete = False