Example #1
0
 def fadeStatus(self):
     if self.windowOpacity() == 1:
         self.animationTimer = RepeatTimer(0.025, self.fadeOut, 40)
         self.animationTimer.start()
     else:
         self.animationTimer = RepeatTimer(0.025, self.fadeIn, 40)
         self.animationTimer.start()
Example #2
0
 def fadeStatus(self):
     if self.windowOpacity() == 1:
         self.animationTimer = RepeatTimer(0.025, self.fadeOut, 40)
         self.animationTimer.start()
     else:
         self.animationTimer = RepeatTimer(0.025, self.fadeIn, 40)
         self.animationTimer.start()
Example #3
0
class SystemMessage(QFrame):
    def __init__(self, parent=None):
        super(SystemMessage, self).__init__(parent)

        self.info = QLabel(u'')

        self.layout = QVBoxLayout()
        self.layout.addWidget(self.info)
        self.setLayout(self.layout)

        self.countdownTimer = QTimer()

        self.setAttribute(Qt.WA_Hover, True)
        self.filter = MessageFilter()
        self.installEventFilter(self.filter)

        self.initComponents()
        self.initComposition()

        self.isShown = False

    def initComposition(self):
        self.setWindowFlags(Qt.ToolTip)
        self.updateStyle()

    def initComponents(self):
        self.info.setAlignment(Qt.AlignCenter)
        self.info.setWordWrap(True)

        self.countdownTimer.setSingleShot(True)
        self.countdownTimer.timeout.connect(self.fadeStatus)

        self.info.setFont(QFont(FONTS_DICT['message'][0], FONTS_DICT['message'][2]))

    def updateStyle(self, error=False):
        if not error:
            self.setStyleSheet('''QFrame { background-color: black;
            border: 1px solid white;
            border-radius: 4px; }
            QLabel { border: none; color: white; }''')
        else:
            self.setStyleSheet('''QFrame { background-color: red;
                            border: 1px solid white;
                            border-radius: 4px; }
                            QLabel { border: none; color: white; }''')

    def showInfo(self, message, error=False, adjust=True):
        if not self.isShown:
            self.info.setText('')
            self.updateStyle(error)
            if isinstance(message, int):
                tip = infoTips(message)
                if tip is not None:
                    self.info.setText(tip)
                    self.updateAndShow(adjust)
            else:
                self.info.setText(message)
                self.updateAndShow(adjust)
        else:
            if isinstance(message, int):
                tip = infoTips(message)
                if tip is not None:
                    self.info.setText(tip)
            else:
                self.info.setText(message)

            self.updateStyle(error)
            if adjust:
                self.adjustSize()
            self.updatePosition()

    def updateAndShow(self, adjust):
        if self.info.text() != '':
            self.show()
            self.setWindowOpacity(0)

            self.isShown = True
            QTimer.singleShot(TIP_VISIBLE + STATUS_CHECK_DELAY, self.updateStatus)

            if adjust:
                self.adjustSize()
            self.updatePosition()
            self.fadeStatus()
            self.countdownTimer.start(TIP_VISIBLE)

    def updatePosition(self):
        desktop = QApplication.desktop()
        if self.parent().y() + self.parent().height() + M_INTERVAL > desktop.height() - BOTTOM_SPACE:
            self.move(self.parent().x() + (self.parent().width() - self.width()) / 2, self.parent().y() + self.parent().height() - BOTTOM_SPACE)
        else:
            self.move(self.parent().x() + (self.parent().width() - self.width())/2, self.parent().y() + self.parent().height() + M_INTERVAL)

    def updateStatus(self):
        self.isShown = False

    def fadeStatus(self):
        if self.windowOpacity() == 1:
            self.animationTimer = RepeatTimer(0.025, self.fadeOut, 40)
            self.animationTimer.start()
        else:
            self.animationTimer = RepeatTimer(0.025, self.fadeIn, 40)
            self.animationTimer.start()

    def fadeIn(self):
        self.setWindowOpacity(self.windowOpacity() + 0.1)

    def fadeOut(self):
        self.setWindowOpacity(self.windowOpacity() - 0.1)
Example #4
0
class InfoMessage(QFrame):
    def __init__(self, parent=None):
        super(InfoMessage, self).__init__(parent)

        self.info = QLabel(u'')

        self.layout = QVBoxLayout()
        self.layout.addWidget(self.info)
        self.setLayout(self.layout)

        self.initComponents()
        self.initComposition()

        self.isShown = False

    def initComposition(self):
#        self.setWindowFlags(Qt.WindowStaysOnTopHint | Qt.CustomizeWindowHint)
        self.setWindowFlags(Qt.ToolTip)
#        self.setStyleSheet('QFrame { background-color: black; border: 1px solid white; border-radius: 4px; } QLabel { border: none; color: white; }')
        self.updateStyle()
        self.setMinimumWidth(self.parent().width() * 0.2)

    def initComponents(self):
        self.info.setAlignment(Qt.AlignCenter)
        self.info.setWordWrap(True)

    def updateStyle(self, error=False):
        if not error: self.setStyleSheet('QFrame { background-color: black; border: 1px solid white; border-radius: 4px; } QLabel { border: none; color: white; }')
        else: self.setStyleSheet('QFrame { background-color: red; border: 1px solid white; border-radius: 4px; } QLabel { border: none; color: white; }')

    def showInfo(self, message, error=False):
        if self.isShown:
            self.info.setText(message)
        elif not self.isShown:
            self.info.setText('')
            self.updateStyle(error)
#            if isinstance(message, int):
#                tip = infoTips(message)
#                if tip is not None:
            self.info.setText(message)
            self.updateAndShow()
#            else:
#                self.info.setText(message)
#                self.updateAndShow()

    def updateAndShow(self):
        if self.info.text() != '':
            self.show()
            self.setWindowOpacity(0)

            self.isShown = True
            QTimer.singleShot(TIP_VISIBLE + STATUS_CHECK_DELAY, self.updateStatus)

            self.updatePosition()
            self.fadeStatus()
            QTimer.singleShot(TIP_VISIBLE, self.fadeStatus)

    def updatePosition(self):
        self.move(self.parent().x() + (self.parent().width() - self.width())/2, self.parent().y() + self.parent().height() + self.height())

    def updateStatus(self):
        self.isShown = False

    def fadeStatus(self):
        if self.windowOpacity() == 1:
            self.animationTimer = RepeatTimer(0.025, self.fadeOut, 40)
            self.animationTimer.start()
        else:
            self.animationTimer = RepeatTimer(0.025, self.fadeIn, 40)
            self.animationTimer.start()

    def fadeIn(self):
        self.setWindowOpacity(self.windowOpacity() + 0.1)

    def fadeOut(self):
        self.setWindowOpacity(self.windowOpacity() - 0.1)