コード例 #1
0
class Splash(QObject, LogMixin, EventMixin):
    """Splash screen class"""
    def __init__(self, parent, msg=""):
        """
        Constructor of Splash screen

        :param parent: ui parent
        :param msg: initial message text

        """
        super().__init__()
        self._parent = parent
        self.isHidden = True
        self._progress = 0
        self._progressBar = None
        self.msg = msg

        pixmap = QtGui.QPixmap(380, 100)
        pixmap.fill(QtGui.QColor("darkgreen"))

        self._splash = QSplashScreen(pixmap)
        self._splash.setParent(self._parent)

        self.add_progressbar()

    def add_progressbar(self):
        """Add separate progress bar to splash screen"""

        self._progressBar = QProgressBar(self._splash)
        self._progressBar.setGeometry(self._splash.width() / 10,
                                      8 * self._splash.height() / 10,
                                      8 * self._splash.width() / 10,
                                      self._splash.height() / 10)
        self._progressBar.hide()

    def setProgress(self, val):
        """
        Set progress bar to ``val``

        If splash has no progressbar, it will be added dynamically.
        Remove progressbar with ``val`` as None.

        :param val: absolut percent value
        :return:
        """
        if val is not None:
            self._progressBar.show()
            self._progressBar.setTextVisible(True)
            self.progress = val
            try:
                self._progressBar.setValue(self.progress)
            except:
                pass
        else:
            self._progressBar.setTextVisible(False)
            self._progressBar.hide()
            self._progressBar.reset()

        if self.isHidden is True:
            self.isHidden = False
            self.show_()

    def incProgress(self, val):
        """
        Increase progressbar value by ``val``

        If splash has no progressbar, it will be added dynamically.
        Remove progressbar with ``val`` as None.

        :param val: value to increase by
        :return:
        """

        if val is not None:
            self._progressBar.show()
            self._progressBar.setTextVisible(True)
            self.progress = self.progress + val
            try:
                self._progressBar.setValue(self.progress)
                qApp.processEvents()
            except:
                pass
        else:
            self._progressBar.setTextVisible(False)
            self._progressBar.hide()
            self._progressBar.reset()

        if self.isHidden is True:
            self.isHidden = False
            self.show_()

    def setParent(self, parent):
        """Set splash's parent"""
        self._parent = parent
        self._splash.setParent(parent)

    @pyqtSlot()
    @pyqtSlot(bool)
    def close(self, dummy=True):
        self.logger.debug("Hide splash")
        self.isHidden = True
        self._progressBar.hide()
        self._progressBar.reset()
        self._splash.close()

    @pyqtSlot()
    @pyqtSlot(str)
    def show_(self, msg=""):

        if msg != "":
            self._splash.showMessage(msg, QtCore.Qt.AlignCenter,
                                     QtCore.Qt.white)
        else:
            self.logger.debug("Show splash, parent: " + str(self._parent))
            self._splash.showMessage(self.msg, QtCore.Qt.AlignCenter,
                                     QtCore.Qt.white)

        try:
            #if platform.system() == "Linux":
            parentUi = self._parent.centralwidget.geometry(
            )  # need to use centralwidget for linux preferably, don't know why
        except:
            #else:
            parentUi = self._parent.childrenRect()

        mysize = self._splash.geometry()

        hpos = parentUi.x() + ((parentUi.width() - mysize.width()) / 2)
        vpos = parentUi.y() + ((parentUi.height() - mysize.height()) / 2)

        self._splash.move(hpos, vpos)
        self._splash.show()

        qApp.processEvents()

    @property
    def progress(self):
        return self._progress

    @progress.setter
    def progress(self, value):
        # create new exception handling vor properties
        # if (value != "True") and (value != "False"):
        #    raise ValueError("describe exception")
        if value > 100:
            value = 0
        if value < 0:
            value = 0
        self._progress = value
コード例 #2
0
ファイル: gui.py プロジェクト: wahlby-lab/FlaskTissUUmaps
def main():
    parser = OptionParser(usage='Usage: %prog [options] [slide-directory]')
    parser.add_option('-B',
                      '--ignore-bounds',
                      dest='DEEPZOOM_LIMIT_BOUNDS',
                      default=False,
                      action='store_false',
                      help='display entire scan area')
    parser.add_option('-c',
                      '--config',
                      metavar='FILE',
                      dest='config',
                      help='config file')
    parser.add_option('-d',
                      '--debug',
                      dest='DEBUG',
                      action='store_true',
                      help='run in debugging mode (insecure)')
    parser.add_option('-e',
                      '--overlap',
                      metavar='PIXELS',
                      dest='DEEPZOOM_OVERLAP',
                      type='int',
                      help='overlap of adjacent tiles [1]')
    parser.add_option('-f',
                      '--format',
                      metavar='{jpeg|png}',
                      dest='DEEPZOOM_FORMAT',
                      help='image format for tiles [jpeg]')
    parser.add_option('-l',
                      '--listen',
                      metavar='ADDRESS',
                      dest='host',
                      default='127.0.0.1',
                      help='address to listen on [127.0.0.1]')
    parser.add_option('-p',
                      '--port',
                      metavar='PORT',
                      dest='port',
                      type='int',
                      default=5000,
                      help='port to listen on [5000]')
    parser.add_option('-Q',
                      '--quality',
                      metavar='QUALITY',
                      dest='DEEPZOOM_TILE_QUALITY',
                      type='int',
                      help='JPEG compression quality [75]')
    parser.add_option('-s',
                      '--size',
                      metavar='PIXELS',
                      dest='DEEPZOOM_TILE_SIZE',
                      type='int',
                      help='tile size [254]')
    parser.add_option('-D',
                      '--depth',
                      metavar='LEVELS',
                      dest='FOLDER_DEPTH',
                      type='int',
                      help='folder depth search for opening files [4]')

    (opts, args) = parser.parse_args()
    # Overwrite only those settings specified on the command line
    for k in dir(opts):
        if not k.startswith('_') and getattr(opts, k) is None:
            delattr(opts, k)
    views.app.config.from_object(opts)
    views.app.config["isStandalone"] = True

    qInstallMessageHandler(lambda x, y, z: None)

    fmt = QtGui.QSurfaceFormat()
    fmt.setColorSpace(QtGui.QSurfaceFormat.sRGBColorSpace)
    fmt.setVersion(4, 1)

    fmt.setProfile(QtGui.QSurfaceFormat.CoreProfile)
    fmt.setSamples(4)
    QtGui.QSurfaceFormat.setDefaultFormat(fmt)

    vp = QtGui.QOpenGLVersionProfile(fmt)

    qt_app = QApplication([])

    logo = QtGui.QPixmap('static/misc/design/logo.png')
    logo = logo.scaledToWidth(512, Qt.SmoothTransformation)
    splash = QSplashScreen(logo, Qt.WindowStaysOnTopHint)

    desktop = qt_app.desktop()
    scrn = desktop.screenNumber(QtGui.QCursor.pos())
    currentDesktopsCenter = desktop.availableGeometry(scrn).center()
    splash.move(currentDesktopsCenter - splash.rect().center())

    splash.show()
    #splash.showMessage('Loading TissUUmaps...',Qt.AlignBottom | Qt.AlignCenter,Qt.white)

    qt_app.processEvents()

    port = 5000
    print("Starting port detection")
    while (is_port_in_use(port)):
        port += 1
        if port == 6000:
            exit(0)
    print("Ending port detection", port)

    def flaskThread():
        views.app.run(host="127.0.0.1", port=port, threaded=True, debug=False)

    threading.Thread(target=flaskThread, daemon=True).start()

    ui = MainWindow(qt_app, views.app, args)
    ui.browser.setLocation("http://127.0.0.1:" + str(port) + "/")

    QTimer.singleShot(1000, splash.close)
    ui.browser.run()
コード例 #3
0
    splashLabel.setScaledContents(True)
    splashLabel.setMaximumSize(QSize(splashWidth, splashHeight))
    splashLabel.setMinimumSize(QSize(splashWidth, splashHeight))
    splash = QSplashScreen()
    splashLayout = QVBoxLayout()
    splashLayout.setContentsMargins(0, 0, 0, 0)
    splashLayout.setSpacing(0)
    splashLayout.addWidget(splashLabel)
    splashProgressBar = QProgressBar()
    splashProgressBar.setMaximumSize(QSize(splashWidth, 20))
    splashProgressBar.setMinimumSize(QSize(splashWidth, 20))
    splashLayout.addWidget(splashProgressBar)
    splash.setLayout(splashLayout)
    x = (screenGeometry.width() - splashLabel.width()) / 2
    y = (screenGeometry.height() - splashLabel.height()) / 2
    splash.move(x, y)
    splash.show()
    import matplotlib
    splashProgressBar.setValue(20)
    matplotlib.use('Qt5agg')
    splashProgressBar.setValue(40)
    from matplotlib import rcParams
    splashProgressBar.setValue(60)
    rcParams['figure.dpi'] = 80
    splashProgressBar.setValue(80)
    from VisualPIC.Views.mainWindow import MainWindow
    splashProgressBar.setValue(100)

    mainWindow = MainWindow()
    x = (screenGeometry.width() - mainWindow.width()) / 2
    y = (screenGeometry.height() - mainWindow.height()) / 2 - 20
コード例 #4
0
ファイル: splash.py プロジェクト: pandel/opsiPackageBuilder
class Splash(QObject, LogMixin, EventMixin):
    """Splash screen class"""

    def __init__(self, parent, msg = ""):
        """
        Constructor of Splash screen

        :param parent: ui parent
        :param msg: initial message text

        """
        super().__init__()
        self._parent = parent
        self.isHidden = True
        self._progress = 0
        self._progressBar = None
        self.msg = msg

        pixmap = QtGui.QPixmap(380, 100)
        pixmap.fill(QtGui.QColor("darkgreen"))

        self._splash = QSplashScreen(pixmap)
        self._splash.setParent(self._parent)

        self.add_progressbar()

    def add_progressbar(self):
        """Add separate progress bar to splash screen"""

        self._progressBar = QProgressBar(self._splash)
        self._progressBar.setGeometry(self._splash.width() / 10, 8 * self._splash.height() / 10,
                               8 * self._splash.width() / 10, self._splash.height() / 10)
        self._progressBar.hide()

    def setProgress(self, val):
        """
        Set progress bar to ``val``

        If splash has no progressbar, it will be added dynamically.
        Remove progressbar with ``val`` as None.

        :param val: absolut percent value
        :return:
        """
        if val is not None:
            self._progressBar.show()
            self._progressBar.setTextVisible(True)
            self.progress = val
            try:
                self._progressBar.setValue(self.progress)
            except:
                pass
        else:
            self._progressBar.setTextVisible(False)
            self._progressBar.hide()
            self._progressBar.reset()

        if self.isHidden is True:
            self.isHidden = False
            self.show_()

    def incProgress(self, val):
        """
        Increase progressbar value by ``val``

        If splash has no progressbar, it will be added dynamically.
        Remove progressbar with ``val`` as None.

        :param val: value to increase by
        :return:
        """

        if val is not None:
            self._progressBar.show()
            self._progressBar.setTextVisible(True)
            self.progress = self.progress + val
            try:
                self._progressBar.setValue(self.progress)
                qApp.processEvents()
            except:
                pass
        else:
            self._progressBar.setTextVisible(False)
            self._progressBar.hide()
            self._progressBar.reset()

        if self.isHidden is True:
            self.isHidden = False
            self.show_()

    def setParent(self, parent):
        """Set splash's parent"""
        self._parent = parent
        self._splash.setParent(parent)

    @pyqtSlot()
    @pyqtSlot(bool)
    def close(self, dummy = True):
        self.logger.debug("Hide splash")
        self.isHidden = True
        self._progressBar.hide()
        self._progressBar.reset()
        self._splash.close()

    @pyqtSlot()
    @pyqtSlot(str)
    def show_(self, msg = ""):

        if msg != "":
            self._splash.showMessage(msg, QtCore.Qt.AlignCenter, QtCore.Qt.white)
        else:
            self.logger.debug("Show splash, parent: " + str(self._parent))
            self._splash.showMessage(self.msg, QtCore.Qt.AlignCenter, QtCore.Qt.white)

        try:
        #if platform.system() == "Linux":
            parentUi = self._parent.centralwidget.geometry()  # need to use centralwidget for linux preferably, don't know why
        except:
        #else:
            parentUi = self._parent.childrenRect()

        mysize = self._splash.geometry()

        hpos = parentUi.x() + ((parentUi.width() - mysize.width()) / 2)
        vpos = parentUi.y() + ((parentUi.height() - mysize.height()) / 2)

        self._splash.move(hpos, vpos)
        self._splash.show()

        qApp.processEvents()

    @property
    def progress(self):
        return self._progress

    @progress.setter
    def progress(self, value):
        # create new exception handling vor properties
        # if (value != "True") and (value != "False"):
        #    raise ValueError("describe exception")
        if value > 100:
            value = 0
        if value < 0:
            value = 0
        self._progress = value