diff options
Diffstat (limited to 'SoundboardEngine.py')
| -rw-r--r-- | SoundboardEngine.py | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/SoundboardEngine.py b/SoundboardEngine.py new file mode 100644 index 0000000..899f9d2 --- /dev/null +++ b/SoundboardEngine.py @@ -0,0 +1,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 |