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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
# 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 AboutWindow import AboutWindow
from PySide6.QtWidgets import (
QMainWindow,
QStackedWidget,
QVBoxLayout,
QWidget,
)
from AudioPlayer import AudioPlayer, PlayerStatus
from CategoryCardWidget import CategoryCardWidget
from CategoryListWidget import CategoryListWidget
from SoundListItemWidget import QHBoxLayout, QLabel
from Soundboard import Soundboard
from SoundsListWidget import SoundsListWidget
from StatusbarWidget import StatusbarWidget
APP_VERSION = "0.1.0"
class SoundboardEngineWindow(QMainWindow):
def __init__(self, soundboard: Soundboard, app_version):
super().__init__()
self.soundboard = soundboard
self.app_version = app_version
self.about_window = None
self.audio_player = AudioPlayer(self)
self.audio_player.status_updated.connect(self.player_state_changed)
self.init_ui()
def init_ui(self):
self.setWindowTitle(self.soundboard.soundboard_name)
self.setMinimumSize(450, 480)
self.resize(450, 480)
central_widget = QWidget()
self.setCentralWidget(central_widget)
self.main_layout = QVBoxLayout(central_widget)
self.main_layout.setContentsMargins(0, 0, 0, 0)
# add status bar
self.statusbar_widget = StatusbarWidget()
self.statusbar_widget.play_requested.connect(self.audio_player.play_sound)
self.statusbar_widget.stop_requested.connect(self.audio_player.stop_sound)
self.main_layout.addWidget(self.statusbar_widget)
# stacked screen thingy
self.screen_stack = QStackedWidget()
self.main_layout.addWidget(self.screen_stack, stretch=1)
# add category grid
self.category_grid = CategoryListWidget()
self.category_grid.title_label.setText(self.soundboard.soundboard_name)
self.category_grid.play_random.connect(self.play_random)
self.screen_stack.addWidget(self.category_grid)
# add sounds list
self.sounds_list = SoundsListWidget()
self.sounds_list.back_requested.connect(self.show_home)
self.sounds_list.play_requested.connect(self.audio_player.play_sound)
self.screen_stack.addWidget(self.sounds_list)
self.footer_layout = QHBoxLayout()
self.footer_layout.setContentsMargins(0, 0, 0, 10)
self.footer_layout.addStretch()
self.footer_label = QLabel(f"Soundboard Engine {self.app_version} | <a href='about'>About</a>")
self.footer_label.linkActivated.connect(self.toggle_about_page)
self.footer_layout.addWidget(self.footer_label)
self.footer_layout.addStretch()
self.main_layout.addLayout(self.footer_layout)
self.populate_categories()
def populate_categories(self):
cards = []
for category in self.soundboard.categories:
card = CategoryCardWidget(category)
card.list_clicked.connect(self.show_sounds_list)
card.play_requested.connect(self.audio_player.play_sound)
cards.append(card)
self.category_grid.set_cards(cards)
def show_sounds_list(self, category):
self.sounds_list.load_category(category)
self.screen_stack.setCurrentIndex(1)
def show_home(self):
self.screen_stack.setCurrentIndex(0)
def player_state_changed(self, status: PlayerStatus):
self.statusbar_widget.set_status(status)
def play_random(self):
_category = random.choice(self.soundboard.categories)
_sound = random.choice(_category.sounds)
self.audio_player.play_sound(_sound)
def toggle_about_page(self):
if self.about_window is None:
self.about_window = AboutWindow(self.soundboard, self.app_version)
self.about_window.show()
else:
self.about_window.close()
self.about_window = None
|