Compare commits

..

No commits in common. "p376" and "main" have entirely different histories.
p376 ... main

3 changed files with 42 additions and 37 deletions

View File

@ -28,22 +28,22 @@ class Bell:
@dataclasses.dataclass
class CustomSound:
name: str
times: list
times: list[list[int]]
sound_file: str
@dataclasses.dataclass
class Config:
# yes, this is permanently "borrowed" from the internet
# thx to https://stackoverflow.com/questions/53632152/why-cant-dataclasses-have-mutable-defaults-in-their-class-attributes-declaratio
lessons_start: list = dataclasses.field(default_factory=lambda: [8, 0])
lessons_start: list[int] = dataclasses.field(default_factory=lambda: [8, 0])
lesson_length: int = dataclasses.field(default_factory=lambda: 40)
break_length: int = dataclasses.field(default_factory=lambda: 5)
first_bell: int = dataclasses.field(default_factory=lambda: 1)
num_lessons: int = dataclasses.field(default_factory=lambda: 12)
workdays: list = dataclasses.field(default_factory=lambda: [True, True, True, True, True, True, False])
sound_files: list = dataclasses.field(default_factory=lambda: ["", "", ""])
workdays: list[bool] = dataclasses.field(default_factory=lambda: [True, True, True, True, True, True, False])
sound_files: list[str] = dataclasses.field(default_factory=lambda: ["", "", ""])
first_bell_before_first_lesson: bool = dataclasses.field(default_factory=lambda: True)
custom_sounds: list = dataclasses.field(default_factory=lambda: [])
custom_sounds: list[CustomSound] = dataclasses.field(default_factory=lambda: [])
class Scheduler:
def __init__(self) -> None:
@ -86,8 +86,8 @@ class Scheduler:
self.ui.set_schedule(self.get_bells_list())
def get_bells_list(self) -> list:
bells_list: list = []
def get_bells_list(self) -> list[str]:
bells_list: list[str] = []
for bell in self.bells:
if bell.sound != SoundType.CUSTOM: bell_name: str = BELL_NAMES[bell.sound]
else: bell_name: str = '"' + bell.custom_name + '"'
@ -95,10 +95,11 @@ class Scheduler:
return bells_list
def menu_event(self, button) -> None:
if button == 0: self.apply_config()
elif button == 1: self.save_config()
elif button == 2: self.bells_enabled = True
elif button == 3: self.bells_enabled = False
match button:
case 0: self.apply_config()
case 1: self.save_config()
case 2: self.bells_enabled = True
case 3: self.bells_enabled = False
def update(self) -> None:
if not self.bells_enabled:
@ -108,10 +109,11 @@ class Scheduler:
if (not bell.played) and (bell.hour == t.tm_hour) and (bell.minute == t.tm_min):
bell.played = True
self.ui.select_bell(bell_n)
if bell.sound == SoundType.FIRST_BELL: play(self.config.sound_files[0])
elif bell.sound == SoundType.SECOND_BELL: play(self.config.sound_files[1])
elif bell.sound == SoundType.BREAK: play(self.config.sound_files[2])
elif bell.sound == SoundType.CUSTOM: play(bell.custom_file)
match bell.sound:
case SoundType.FIRST_BELL: play(self.config.sound_files[0])
case SoundType.SECOND_BELL: play(self.config.sound_files[1])
case SoundType.BREAK: play(self.config.sound_files[2])
case SoundType.CUSTOM: play(bell.custom_file)
break
def load_config(self) -> None:

View File

@ -222,9 +222,10 @@ class SoundFilesBox(BasicBox):
file_name, _ = QtWidgets.QFileDialog.getOpenFileName(self.grid_widget, "SBC - Відкрити файл", "", "Підтримувані файли (*.wav *.mp3 *.flac)")
if file_name is None:
return
if sound_type == 0: self.first_bell_file_text .setText(file_name)
elif sound_type == 1: self.second_bell_file_text.setText(file_name)
elif sound_type == 2: self.break_file_text .setText(file_name)
match sound_type:
case 0: self.first_bell_file_text .setText(file_name)
case 1: self.second_bell_file_text.setText(file_name)
case 2: self.break_file_text .setText(file_name)
class SoundEditorBox(BasicBox):
def __init__(self, add_sound_callback, quit_callback):

View File

@ -2,7 +2,7 @@ from PySide6 import QtWidgets, QtGui, QtCore
from widgets import BellStatusBox, ScheduleBox, DaysSelectBox, AdditionalSoundsBox, StatusBox, SoundFilesBox, SoundEditorBox
import sys
VERSION = "0.2.0_p376"
VERSION = "0.2.0"
class MainWindow(QtWidgets.QMainWindow):
def __init__(self, show_sound_diag):
@ -86,19 +86,21 @@ class MenuActions:
self.button_about.triggered.connect(lambda: self.handle_button(4))
def handle_button(self, button):
if button in [0, 1, 2, 3]: self.callback(button)
if button == 0: QtWidgets.QMessageBox.information(self.window, "SBC - Інформація", "Налаштування застосовано!")
elif button == 1: QtWidgets.QMessageBox.information(self.window, "SBC - Інформація", "Налаштування збережено!")
elif button == 2:
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 - Інформація", "Дзвінки запущено. Якщо ви налаштували щось не так, самі винні!")
elif button == 3:
case 3:
self.button_start.setEnabled(True)
self.button_stop .setEnabled(False)
QtWidgets.QMessageBox.information(self.window, "SBC - Інформація", "Дзвінки зупинено. Щось пішло не так, еге ж? Піди і виправи це негайно!")
elif button == 4:
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):