aboutsummaryrefslogtreecommitdiffstats
path: root/StatusbarWidget.py
blob: 6325767862c4d2934cc41ee8caf7f9aba5d19737 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# Soundboard Engine - customizable soundboard
# Copyright (C) 2026  Vidhu Kant Sharma <vidhukant@vidhukant.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.

from PySide6.QtCore import Signal
from PySide6.QtWidgets import QHBoxLayout, QLabel, QPushButton, QWidget

from AudioPlayer import PlayerStatus
from Soundboard import SoundboardSound


class StatusbarWidget(QWidget):
    play_requested = Signal(SoundboardSound)
    stop_requested = Signal()

    def __init__(self, parent=None):
        super().__init__(parent)

        layout = QHBoxLayout(self)
        layout.setContentsMargins(12, 16, 12, 8)

        self.now_playing_label = QLabel("Welcome to soundboard")
        layout.addWidget(self.now_playing_label, stretch=1)

        self.btn_replay = QPushButton("Play Again")
        self.btn_replay.clicked.connect(
            lambda: self.play_requested.emit(self.status.sound)
        )
        self.btn_replay.setEnabled(False)
        layout.addWidget(self.btn_replay)

        self.btn_stop = QPushButton("Stop")
        self.btn_stop.clicked.connect(lambda: self.stop_requested.emit())
        self.btn_stop.setEnabled(False)
        layout.addWidget(self.btn_stop)

    def set_status(self, status: PlayerStatus):
        self.status = status
        self.now_playing_label.setText(
            f"[{self.status.status}] {self.status.sound.title}"
        )

        if self.status.status == "PLAYING":
            self.btn_stop.setEnabled(True)
        else:
            self.btn_stop.setEnabled(False)

        self.btn_replay.setEnabled(True)