aboutsummaryrefslogtreecommitdiffstats
path: root/SoundListItemWidget.py
blob: 194b633d9e6e511f016896bc61ad81faa629b5ba (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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# 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/>.

import sys
import shutil
from pathlib import Path

from PySide6.QtCore import Signal
from PySide6.QtWidgets import QFrame, QHBoxLayout, QLabel, QPushButton, QFileDialog

from Soundboard import SoundboardSound


class SoundListItemWidget(QFrame):
    play_requested = Signal(SoundboardSound)

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

        self.sound = sound

        self.setFixedHeight(48)
        self.setStyleSheet("""
            SoundListItemWidget {
                 border: none;
                 border-bottom: 1px solid palette(shadow);
                 background-color: palette(window);
            }

            SoundListItemWidget:hover {
                background-color: palette(mid);
            }
        """)

        layout = QHBoxLayout(self)
        layout.setContentsMargins(12, 6, 12, 6)
        layout.setSpacing(10)

        self.title_label = QLabel(sound.title)
        font = self.title_label.font()
        font.setBold(True)
        self.title_label.setFont(font)
        layout.addWidget(self.title_label, stretch=1)

        self.btn_download = QPushButton("Download")
        self.btn_download.clicked.connect(self.download)
        layout.addWidget(self.btn_download)

        self.btn_play = QPushButton("Play")
        self.btn_play.clicked.connect(lambda: self.play_requested.emit(self.sound))
        layout.addWidget(self.btn_play)

    def download(self):
        selected_folder = QFileDialog.getSaveFileName(
            self,
            "Save Audio File",
            self.sound.title + Path(self.sound.path).suffix,
            "All Files (*)"
        )
        if selected_folder:
            self.download_dest = Path(selected_folder[0])
            print(self.download_dest)

        shutil.copy2(self.sound.path, self.download_dest)