from PyQt5.QtWidgets import QLabel,QWidget
from PyQt5.QtCore import  QTimer, Qt

class BlinkingText(QWidget):
    BLINKING_TIMEOUT = 1000

    def __init__(self, text_to_show):
        super(BlinkingText, self).__init__()
        self.__info_label_hidden = False
        self.create_info_label(text_to_show)

    @property
    def info_label(self):
        return self.__info_label

    def create_info_label(self, text_to_show):
        self.__info_label = QLabel()
        self.__info_label.setText("<font>" + text_to_show + "</font>")
        self.__info_label.setAlignment(Qt.AlignCenter)

    def start_blinking(self):
        timer = QTimer(self)
        timer.timeout.connect(self.flash_label)
        timer.start(BlinkingText.BLINKING_TIMEOUT)

    def flash_label(self):
        if self.__info_label_hidden == False:
            self.__info_label.setStyleSheet("QLabel{ color : red; }")
            self.__info_label_hidden = True
        else:
            self.__info_label.setStyleSheet("QLabel{ color : black; }")
            self.__info_label_hidden = False