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
except KeyError: # If we don't already have this figure, make a window # to put it in: self.new_figure(fig, identifier) else: if not plot.is_shown: plot.show() plot.update_window_size() plot.set_window_title(identifier, self.filepath) if plot.lock_axes: plot.restore_axis_limits() plot.draw() def new_figure(self, fig, identifier): self.plots[fig] = Plot(fig, identifier, self.filepath) def reset_figs(self): pass if __name__ == '__main__': filepath = from_parent.get() # Set a meaningful client id for zprocess.locking: zprocess.locking.set_client_process_name('lyse-' + os.path.basename(filepath)) qapplication = QtWidgets.QApplication(sys.argv) worker = AnalysisWorker(filepath, to_parent, from_parent) qapplication.exec_()