@Aloya228
Подпольный аккаунт @Bad-Coder

Почему Popup все равно генерируеться?

# Create popup in window.
class Popup:
    """Class for generating popups in window."""

    def summon(self, title=None, text=None, interval=None):
        """Summon popup in window."""
        if title is None:
            self.title = 'Constructor.'

        if title is not None:
            self.title = title

        if text is None:
            self.text = 'Hello, World!'

        if text is not None:
            self.text = text

        if interval is None:
            self.interval = 3

        if interval is not None:
            self.interval = interval

        self.running = False

        self.create = lambda: self.summoner(self.title, self.text, self.interval)

        self.popup = Thread(target=self.create)
        self.popup.start()

    def summoner(self, title, text, interval):
        """Function for summoning."""
        log('Generating popup.')

        if self.running:
            log('Can\'t summon popup, another popup yet running.')

        elif not self.running:
            # This block has shitty code...

            self.running = True

            form.popupTitle.setText(title)
            form.popupText.setText(text)

            effect = QGraphicsOpacityEffect()
            effect.setOpacity(0)

            sleep(.1)

            form.popup.setGraphicsEffect(effect)

            effect = QGraphicsOpacityEffect()
            effect.setOpacity(0.100000)

            sleep(.1)

            form.popup.setGraphicsEffect(effect)

            effect = QGraphicsOpacityEffect()
            effect.setOpacity(0.200000)

            sleep(.1)

            form.popup.setGraphicsEffect(effect)

            effect = QGraphicsOpacityEffect()
            effect.setOpacity(0.300000)

            sleep(.1)

            form.popup.setGraphicsEffect(effect)

            effect = QGraphicsOpacityEffect()
            effect.setOpacity(0.400000)

            sleep(.1)

            form.popup.setGraphicsEffect(effect)

            effect = QGraphicsOpacityEffect()
            effect.setOpacity(0.500000)

            sleep(.1)

            form.popup.setGraphicsEffect(effect)

            effect = QGraphicsOpacityEffect()
            effect.setOpacity(0.600000)

            sleep(.1)

            form.popup.setGraphicsEffect(effect)

            effect = QGraphicsOpacityEffect()
            effect.setOpacity(0.700000)

            sleep(.1)

            form.popup.setGraphicsEffect(effect)

            effect = QGraphicsOpacityEffect()
            effect.setOpacity(0.800000)

            sleep(.1)

            form.popup.setGraphicsEffect(effect)

            effect = QGraphicsOpacityEffect()
            effect.setOpacity(0.900000)

            sleep(.1)

            form.popup.setGraphicsEffect(effect)
            
            effect = QGraphicsOpacityEffect()
            effect.setOpacity(1)

            sleep(.1)

            form.popup.setGraphicsEffect(effect)

            sleep(interval)

            effect = QGraphicsOpacityEffect()
            effect.setOpacity(1)

            sleep(.1)

            form.popup.setGraphicsEffect(effect)

            effect = QGraphicsOpacityEffect()
            effect.setOpacity(0.900000)

            sleep(.1)

            form.popup.setGraphicsEffect(effect)

            effect = QGraphicsOpacityEffect()
            effect.setOpacity(0.800000)

            sleep(.1)

            form.popup.setGraphicsEffect(effect)

            effect = QGraphicsOpacityEffect()
            effect.setOpacity(0.700000)

            sleep(.1)

            form.popup.setGraphicsEffect(effect)

            effect = QGraphicsOpacityEffect()
            effect.setOpacity(0.600000)

            sleep(.1)

            form.popup.setGraphicsEffect(effect)

            effect = QGraphicsOpacityEffect()
            effect.setOpacity(0.500000)

            sleep(.1)

            form.popup.setGraphicsEffect(effect)

            effect = QGraphicsOpacityEffect()
            effect.setOpacity(0.400000)

            sleep(.1)

            form.popup.setGraphicsEffect(effect)

            effect = QGraphicsOpacityEffect()
            effect.setOpacity(0.300000)

            sleep(.1)

            form.popup.setGraphicsEffect(effect)

            effect = QGraphicsOpacityEffect()
            effect.setOpacity(0.200000)

            sleep(.1)

            form.popup.setGraphicsEffect(effect)

            effect = QGraphicsOpacityEffect()
            effect.setOpacity(0.100000)

            sleep(.1)

            form.popup.setGraphicsEffect(effect)

            effect = QGraphicsOpacityEffect()
            effect.setOpacity(0)

            sleep(.1)

            form.popup.setGraphicsEffect(effect)

            sleep(.1)

            self.running = False

            log('Popup generated.')

# Init main class.
popups = Popup()

# Generate popup via function.
def popup(title=None, text=None, interval=None):
    """Generate popup."""
    log('Generating popup from function.')

    popups.summon(title, text, interval)

    log('Popup from function generated.')


Почему если два раза (или больше), вызвать popups.summon, то popup все равно сгенерируется, а не выведется Can't summon popup, another popup yet running.?
  • Вопрос задан
  • 86 просмотров
Решения вопроса 1
@Vindicar
self.running = False
self.create = lambda: ...
Потому что ты ему разрешаешь в вызове summon().
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы