diff options
| author | Vidhu Kant Sharma <vidhukant@vidhukant.com> | 2026-07-24 18:00:52 +0530 |
|---|---|---|
| committer | Vidhu Kant Sharma <vidhukant@vidhukant.com> | 2026-07-24 18:00:52 +0530 |
| commit | bc7d62ca9a406bc30419e985016c7f4f56e54e76 (patch) | |
| tree | b4f1091e7f008df31d20039f0fa4c683d05785e5 /CategoryCardWidget.py | |
first commit
Diffstat (limited to 'CategoryCardWidget.py')
| -rw-r--r-- | CategoryCardWidget.py | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/CategoryCardWidget.py b/CategoryCardWidget.py new file mode 100644 index 0000000..27a7993 --- /dev/null +++ b/CategoryCardWidget.py @@ -0,0 +1,102 @@ +# 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 random + +from PySide6.QtCore import Signal +from PySide6.QtGui import QPixmap, Qt +from PySide6.QtWidgets import ( + QFrame, + QHBoxLayout, + QLabel, + QPushButton, + QVBoxLayout, +) + +from Soundboard import SoundboardCategory, SoundboardSound + + +class CategoryCardWidget(QFrame): + list_clicked = Signal(SoundboardCategory) + play_requested = Signal(SoundboardSound) + CARD_HEIGHT = 150 + CARD_WIDTH = 400 + + def __init__(self, category: SoundboardCategory, parent=None): + super().__init__(parent) + + self.category = category + + self.setFixedSize(self.CARD_WIDTH, self.CARD_HEIGHT) + self.setStyleSheet(""" + CategoryCardWidget { + border: 1px solid palette(shadow); + background-color: palette(window); + } + """) + + layout = QHBoxLayout(self) + layout.setContentsMargins(0, 0, 0, 0) + layout.setSpacing(0) + + # category image + self.image_label = QLabel() + self.image_label.setFixedHeight(self.CARD_HEIGHT) + pixmap = QPixmap(category.image_path).scaled( + self.image_label.width(), + self.image_label.height(), + Qt.AspectRatioMode.KeepAspectRatio, + Qt.TransformationMode.SmoothTransformation, + ) + self.image_label.setPixmap(pixmap) + self.image_label.setAlignment(Qt.AlignmentFlag.AlignLeft) + layout.addWidget(self.image_label, alignment=Qt.AlignmentFlag.AlignLeft) + + content_layout = QVBoxLayout() + content_layout.setContentsMargins(20, 0, 20, 0) + content_layout.setSpacing(6) + content_layout.addStretch() + + self.name_label = QLabel(category.name) + self.name_label.setAlignment(Qt.AlignmentFlag.AlignCenter) + name_font = self.name_label.font() + name_font.setBold(True) + name_font.setPointSize(18) + self.name_label.setFont(name_font) + content_layout.addWidget(self.name_label) + + self.sounds_count_label = QLabel(f"{len(category.sounds)} sounds") + self.sounds_count_label.setAlignment(Qt.AlignmentFlag.AlignCenter) + content_layout.addWidget(self.sounds_count_label) + + btn_layout = QHBoxLayout() + btn_layout.setSpacing(6) + + self.btn_list = QPushButton("All Sounds") + self.btn_list.clicked.connect(lambda: self.list_clicked.emit(self.category)) + btn_layout.addWidget(self.btn_list) + + self.btn_random = QPushButton("Play Random") + self.btn_random.clicked.connect(self.play_random) + btn_layout.addWidget(self.btn_random) + + content_layout.addLayout(btn_layout) + content_layout.addStretch() + + layout.addLayout(content_layout) + + def play_random(self): + self.play_requested.emit(random.choice(self.category.sounds)) |