Exemple #1
0
class HoverButton(QPushButton):
    def __init__(self, parent=None, id=0):
        self.id = id
        self.selected = False
        QPushButton.__init__(self, parent)
        self.setMouseTracking(True)
        self.anim = QVariantAnimation(self)
        self.anim.setDuration(300)
        self.anim.valueChanged.connect(self.animationEvent)
        self.a = 0
        self.ss = "border: none;"\
            "margin: 0px;"\
            "padding: 0px;"\
            "color: rgb(255, 255, 255);"\
            "background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, "\
            "y2:0, stop:0 rgba(0, 115, 119, 0), stop:0.5 rgba(0, 115, 119, "\
            "{0}), stop:1 rgba(0, 115, 119, 0));"
        self.setStyleSheet("QPushButton {" + self.ss.format(0) + "}")

    def setSelected(self, sel):
        self.selected = sel
        if sel:
            self.a = 255
            self.setStyleSheet("QPushButton {" + self.ss.format(255) + "}")
        else:
            self.leaveEvent()

    def enterEvent(self, event):
        if self.selected:
            return
        val = self.anim.currentValue()
        if val is None:
            val = self.a
        self.anim.setStartValue(val)
        self.anim.setEndValue(255)
        self.anim.start()
        self.a = 255

    def leaveEvent(self, event=None):
        if self.selected:
            return
        val = self.anim.currentValue()
        if val is None:
            val = self.a
        self.anim.setStartValue(val)
        self.anim.setEndValue(0)
        self.anim.start()
        self.a = 0

    def animationEvent(self):
        val = self.anim.currentValue()
        self.setStyleSheet("QPushButton {" + self.ss.format(val) + "}")
Exemple #2
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()
Exemple #3
0
class ResultsBar(QProgressBar):
    def __init__(self, id, targets, parent=None):
        super(ResultsBar, self).__init__(parent)
        self.a = False
        self.id = id
        self.setObjectName(id)
        self.targets = targets
        self.setValue2(targets[1] / 2)
        self.setTextVisible(False)
        self.actval = 0
        if parent is None:
            self.anim = QVariantAnimation(self)
        else:
            self.anim = QVariantAnimation(parent)
        self.anim.setStartValue(0)
        self.anim.setEasingCurve(QEasingCurve.OutBounce)
        self.anim.currentLoopChanged.connect(self.animationEvent)
        self.anim.finished.connect(self.animFinished)

    def setValue2(self, val, update=True):
        v = (val / self.targets[1]) * 100
        if v > 99:
            v = 100
        self.setProperty("value", v)
        self.setValue(v)
        self.updateStyleSheet(v)

    def animationEvent(self):
        v = self.anim.currentValue()
        self.setValue2(v)

    def setActual(self, val):
        self.actval = (val / self.targets[1]) * 100
        if self.actval > 99:
            self.actval = 100
        if self.a:
            self.anim.setEndValue(self.actval)
        else:
            self.setValue2(val)

    def startAnimation(self):
        self.anim.setStartValue(0)
        self.anim.setEndValue(self.actval)
        self.anim.setDuration(20 * self.actval)
        self.anim.start()
        self.a = True

    def animFinished(self):
        self.a = False
        return

    def updateStyleSheet(self, val):
        ss = \
            "#@ID {\n" \
            "    background-color: rgba(0,0,0,0);\n" \
            "    border: none;\n" \
            "}\n" \
            "#@ID::chunk {\n" \
            "    background-color: qlineargradient(spread:pad, x1:0, " \
            "y1:0, x2:0, y2:1, stop:0 @Colour1, stop:1 "  \
            "@Colour2);\n" \
            "    width: 1px;\n" \
            "    border: none;\n" \
            "}"
        if val == 100:
            col1 = "rgb(150,220,90)"
            col2 = "rgb(160,230,100)"
        elif val < (self.targets[0] / self.targets[1]) * 100:
            col1 = "rgb(250,70,65)"
            col2 = "rgb(255,80,75)"
        else:
            col1 = "rgb(245,170,40)"
            col2 = "rgb(255,180,50)"
        ss = ss.replace("@Colour1",
                        col1).replace("@Colour2",
                                      col2).replace("@ID", self.id)
        self.setStyleSheet(ss)