Esempio n. 1
0
class AnimationLabel(QtWidgets.QLabel):
	def __init__(self, *args, **kwargs):
		QtWidgets.QLabel.__init__(self, *args, **kwargs)
		self.animation = QVariantAnimation()
		self.animation.valueChanged.connect(self.changeColor)

	@pyqtSlot(QVariant)
	def changeColor(self, color):
		palette = self.palette()
		palette.setColor(QtGui.QPalette.WindowText, color)
		self.setPalette(palette)

	def startFadeIn(self):
		self.animation.stop()
		self.animation.setStartValue(QtGui.QColor(0, 0, 0, 0))
		self.animation.setEndValue(QtGui.QColor(0, 0, 0, 255))
		self.animation.setDuration(2000)
		self.animation.setEasingCurve(QtCore.QEasingCurve.InBack)
		self.animation.start()

	def startFadeOut(self):
		self.animation.stop()
		self.animation.setStartValue(QtGui.QColor(0, 0, 0, 255))
		self.animation.setEndValue(QtGui.QColor(0, 0, 0, 0))
		self.animation.setDuration(2000)
		self.animation.setEasingCurve(QtCore.QEasingCurve.OutBack)
		self.animation.start()

	def startAnimation(self):
		print("starting an")
		self.startFadeOut()
		loop = QtCore.QEventLoop()
		self.animation.finished.connect(loop.quit)
		loop.exec_()
		QTimer.singleShot(2000, self.startFadeIn)
Esempio n. 2
0
class RectItem(QGraphicsRectItem):
    def __init__(self, rect=QRectF()):
        super(RectItem, self).__init__(rect)
        self.setFlag(QGraphicsItem.ItemIsSelectable, True)
        self.setFlag(QGraphicsItem.ItemSendsGeometryChanges, True)
        self._pos_animation = QVariantAnimation()
        self._pos_animation.valueChanged.connect(self.setPos)

    def move_smooth(self, end, duration):
        if self._pos_animation.state() == QAbstractAnimation.Running:
            self._pos_animation.stop()
        self._pos_animation.setDuration(duration)
        self._pos_animation.setStartValue(self.pos())
        self._pos_animation.setEndValue(end)
        self._pos_animation.start()
Esempio n. 3
0
class ResultLab(QLabel):
    name = "result_lab"

    def __init__(self, parent):
        super().__init__(parent=parent)
        self.parent = parent
        self.setObjectName(ResultLab.name)
        self.setText("Waiting...")

        sizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Preferred)
        sizePolicy.setHeightForWidth(self.sizePolicy().hasHeightForWidth())
        self.setSizePolicy(sizePolicy)

        self.animation = QVariantAnimation()
        self.animation_dur = 2000
        self.animation.valueChanged.connect(self.changeColor)

    def changeColor(self, color: QColor):
        palette = self.palette()
        palette.setColor(QPalette.WindowText, color)
        self.setPalette(palette)

    def animate(self, count=-1):
        self.animation.setLoopCount(count)
        self.animation.setStartValue(QColor(0, 0, 0, 255))
        self.animation.setEndValue(QColor(0, 0, 0, 0))
        self.animation.setDuration(self.animation_dur)
        self.animation.setEasingCurve(QEasingCurve.InBack)
        self.animation.start()

    def stop(self):
        self.animation.stop()

        palette = self.palette()
        palette.setColor(QPalette.WindowText, QColor(0, 0, 0, 255))
        self.setPalette(palette)

        self.setText("Finished!")
Esempio n. 4
0
class WindowSettingsEvent(object):
    play_pbtn = False
    repeat_pbtn = False

    def __init__(self, master=None):
        self.master = master

        # Animation
        self.timeline_info = None
        self.timeline = None
        self.animation = QVariantAnimation()
        self.animation.setProperty('Play', False)
        self.animation.setProperty('MovePlayed', False)
        self.animation.valueChanged.connect(self.play_slider_sound)

    def play_slider_sound(self):
        self.timeline.setValue(self.animation.currentValue())

    def event_play_slider(self):
        if self.animation.property('Play') == True:
            self.animation.stop()
        self.animation.setDuration((self.timeline_info['duration']))
        self.animation.setStartValue(self.timeline_info['start'])
        self.animation.setEndValue(self.timeline_info['end'])
        self.animation.setProperty('Play', True)
        self.animation.start()

    def event_start_paused_animation(self):
        self.animation.start()

    def event_move_stop_slider(self):
        if self.animation.property('Play') is True:
            self.animation.stop()
            self.animation.setProperty('Play', False)
            self.animation.setProperty('MovePlayed', True)

    def switch_play_pbtn(self, btn, timeline, timeline_info):
        self.timeline = timeline

        self.timeline_info = self.timeline.update_slider_info()

        if self.play_pbtn is True:
            self.event_move_stop_slider()
            self.animation.setProperty('MovePlayed', False)
            self.play_pbtn = False
            btn.setIcon(QIcon('./interface-stylesheets/interface-element/play.gif'))
            btn.setToolTip('Play music')
        else:
            self.event_play_slider()
            self.play_pbtn = True
            btn.setIcon(QIcon('./interface-stylesheets/interface-element/end.gif'))
            btn.setToolTip('Stop music')

    def switch_repeat_pbtn(self, btn):

        if self.repeat_pbtn is True:

            self.repeat_pbtn = False
            btn.setStyleSheet("""QPushButton{background: #202533;}
                                 QPushButton:hover{background:  #262B39;}
                                 QPushButton:pressed{background:  #16a4b5;}""")
            btn.setToolTip('Play music')
        else:
            self.repeat_pbtn = True
            btn.setStyleSheet("""QPushButton{background: #16a4b5;}
                                 QPushButton:hover{background:  #2AB8C9;}
                                 QPushButton:pressed{background:  #202533;}""")
            btn.setToolTip('Stop music')

    def set_lbl_time(self, timeline, time_lbl, timeline_val):
        if timeline.value() == timeline.maximum():
            print('Max')
        if timeline_val % 60 < 10:
            time_lbl.setText(str(timeline_val // 60) + ":0" + str(timeline_val % 60))
        else:
            time_lbl.setText(str(timeline_val // 60) + ":" + str(timeline_val % 60))

    def update_release_slider(self, timeline):
        self.timeline_info = timeline
        if self.animation.property('Play') is True or self.animation.property('MovePlayed') is True:
            self.animation.setProperty('MovePlayed', False)
            self.event_play_slider()