from PySide6 import QtWidgets, QtGui, QtCore from widgets import BellStatusBox, ScheduleBox, DaysSelectBox, AdditionalSoundsBox, StatusBox, SoundFilesBox, SoundEditorBox import sys VERSION = "0.2.0" class MainWindow(QtWidgets.QMainWindow): def __init__(self, show_sound_diag): super().__init__() self.setWindowTitle("SBC - Головне вікно") self.setWindowIcon(QtGui.QIcon("icon.png")) self.setMinimumSize(800, 768) self.main_widget = QtWidgets.QWidget() self.main_layout = QtWidgets.QGridLayout(self.main_widget) self.bell_status_box = BellStatusBox() self.schedule_box = ScheduleBox() self.days_select_box = DaysSelectBox() self.additional_sounds_box = AdditionalSoundsBox(show_sound_diag) self.status_box = StatusBox() self.sound_files_box = SoundFilesBox() self.main_layout.addWidget(self.bell_status_box, 0, 0, 3, 1) self.main_layout.addWidget(self.schedule_box, 0, 1, 1, 1) self.main_layout.addWidget(self.days_select_box, 1, 1, 1, 1) self.main_layout.addWidget(self.additional_sounds_box, 2, 1, 1, 1) self.main_layout.addWidget(self.status_box, 0, 2, 1, 1) self.main_layout.addWidget(self.sound_files_box, 1, 2, 1, 1) self.setCentralWidget(self.main_widget) def get_settings(self, config, CustomSound): first_lesson_input = self.schedule_box.first_lesson_input.time() config.lessons_start = [first_lesson_input.hour(), first_lesson_input.minute()] config.lesson_length = self.schedule_box.lesson_length_input.value() config.break_length = self.schedule_box.break_length_input .value() config.first_bell = self.schedule_box.first_bell_input .value() config.num_lessons = self.schedule_box.num_lessons_input .value() config.first_bell_before_first_lesson = self.schedule_box.first_bell_before_first_lesson_checkbox.isChecked() config.workdays = [checkbox.isChecked() for checkbox in self.days_select_box.days_checkboxes] config.sound_files = [ self.sound_files_box.first_bell_file_text .text(), self.sound_files_box.second_bell_file_text .text(), self.sound_files_box.break_file_text .text() ] config.custom_sounds = [CustomSound(*sound) for sound in self.additional_sounds_box.sounds] def set_settings(self, config): self.schedule_box.first_lesson_input .setTime (QtCore.QTime(*config.lessons_start)) self.schedule_box.lesson_length_input.setValue(config.lesson_length) self.schedule_box.break_length_input .setValue(config.break_length) self.schedule_box.first_bell_input .setValue(config.first_bell) self.schedule_box.num_lessons_input .setValue(config.num_lessons) self.schedule_box.first_bell_before_first_lesson_checkbox.setChecked(config.first_bell_before_first_lesson) for i in range(0, 7): self.days_select_box.days_checkboxes[i].setChecked(config.workdays[i]) self.sound_files_box.first_bell_file_text .setText(config.sound_files[0]) self.sound_files_box.second_bell_file_text .setText(config.sound_files[1]) self.sound_files_box.break_file_text .setText(config.sound_files[2]) self.additional_sounds_box.sounds = [[sound.name, sound.times, sound.sound_file] for sound in config.custom_sounds] for sound in config.custom_sounds: self.additional_sounds_box.sound_list.add_item(QtWidgets.QLabel(sound.name)) def set_schedule(self, bells): self.bell_status_box.bells_list.clear() for bell in bells: self.bell_status_box.bells_list.addItem(bell) def select_bell(self, bell_n): self.bell_status_box.bells_list.setCurrentItem(self.bell_status_box.bells_list.item(bell_n)) class MenuActions: def __init__(self, window, callback): self.window = window self.callback = callback self.button_apply = QtGui.QAction(QtGui.QIcon("apply.png"), "Застосувати", window) self.button_save = QtGui.QAction(QtGui.QIcon("save.png"), "Зберегти налаштування", window) self.button_start = QtGui.QAction(QtGui.QIcon("start.png"), "Запустити дзвоники", window) self.button_stop = QtGui.QAction(QtGui.QIcon("stop.png"), "Зупинити все", window) self.button_about = QtGui.QAction( "Про програму", window) self.button_start.setEnabled(False) self.button_apply.triggered.connect(lambda: self.handle_button(0)) self.button_save .triggered.connect(lambda: self.handle_button(1)) self.button_start.triggered.connect(lambda: self.handle_button(2)) self.button_stop .triggered.connect(lambda: self.handle_button(3)) self.button_about.triggered.connect(lambda: self.handle_button(4)) def handle_button(self, button): match button: case 0 | 1 | 2 | 3: self.callback(button) match button: case 0: QtWidgets.QMessageBox.information(self.window, "SBC - Інформація", "Налаштування застосовано!") case 1: QtWidgets.QMessageBox.information(self.window, "SBC - Інформація", "Налаштування збережено!") case 2: self.button_start.setEnabled(False) self.button_stop .setEnabled(True) QtWidgets.QMessageBox.information(self.window, "SBC - Інформація", "Дзвінки запущено. Якщо ви налаштували щось не так, самі винні!") case 3: self.button_start.setEnabled(True) self.button_stop .setEnabled(False) QtWidgets.QMessageBox.information(self.window, "SBC - Інформація", "Дзвінки зупинено. Щось пішло не так, еге ж? Піди і виправи це негайно!") case 4: QtWidgets.QMessageBox.information(self.window, "SBC - Про програму", \ f"SBC {VERSION}\nАвтор: 2o\nTelegram: @xfdtw\nDiscord: @2o___\nЯкщо щось не зрозуміло/не працює пишіть туди.") class ToolBar(QtWidgets.QToolBar): def __init__(self, window, menu_actions): super().__init__("Toolbar") window.addToolBar(self) self.setIconSize(QtCore.QSize(16, 16)) self.addAction(menu_actions.button_apply) self.addAction(menu_actions.button_save) self.addSeparator() self.addAction(menu_actions.button_start) self.addAction(menu_actions.button_stop) class MenuBar(QtWidgets.QMenuBar): def __init__(self, window, menu_actions): super().__init__() window.setMenuBar(self) self.settings_menu = self.addMenu("&Налаштування") self.bells_menu = self.addMenu("&Дзвінки") self.help_menu = self.addMenu("Д&опомога") self.settings_menu.addAction(menu_actions.button_apply) self.settings_menu.addAction(menu_actions.button_save) self.bells_menu.addAction(menu_actions.button_start) self.bells_menu.addAction(menu_actions.button_stop) self.help_menu.addAction(menu_actions.button_about) class Tray(QtWidgets.QSystemTrayIcon): def __init__(self, window): super().__init__() self.window = window self.setIcon(QtGui.QIcon("icon.png")) self.setVisible(True) self.menu = QtWidgets.QMenu(self.window) open_window = QtGui.QAction("Показати головне вікно", self) close_all = QtGui.QAction("Вийти", self) open_window.triggered.connect(self.window.show) close_all.triggered.connect(self.close_all_diag) self.menu.addAction(open_window) self.menu.addAction(close_all) self.setContextMenu(self.menu) def close_all_diag(self): if QtWidgets.QMessageBox.question(self.window, "SBC - Вихід", \ "Ви дійсно хочете вийти з програми? Після цього дітки кричатимуть чого в них уроки по 5 годин...", \ QtWidgets.QMessageBox.StandardButton.Yes | QtWidgets.QMessageBox.StandardButton.No) == QtWidgets.QMessageBox.StandardButton.Yes: sys.exit() class SoundEditorWindow(QtWidgets.QMainWindow): def __init__(self): super().__init__() self.setWindowTitle("SBC - Редактор звуків") self.setWindowIcon(QtGui.QIcon("icon.png")) self.setMinimumSize(256, 384) def set_add_sound_callback(self, add_sound_callback): self.sound_editor_box = SoundEditorBox(add_sound_callback, self.hide) self.setCentralWidget(self.sound_editor_box) def show(self, edit_n=None, name="", times=[], sound_file=""): self.sound_editor_box.edit_n = edit_n self.sound_editor_box.sound_name_input.setText(name) for sound_time in times: self.sound_editor_box.time_select_widget \ .add_item(QtWidgets.QTimeEdit(QtCore.QTime(*sound_time))) self.sound_editor_box.file_name_select_text.setText(sound_file) super().show() def closeEvent(self, *args, **kwargs): self.sound_editor_box.clear_edit() super().closeEvent(*args, **kwargs)