Compare commits

..

1 Commits
main ... p376

Author SHA1 Message Date
2o
90b6c969e8 Backport to Python 3.7.6
Note that for compatability with Win7SP1, Pyside 6.1.3 and playsound 1.2.2 will be needed(instead of the latest versions).
2024-10-18 11:44:18 +03:00
3 changed files with 37 additions and 42 deletions

View File

@ -28,22 +28,22 @@ class Bell:
@dataclasses.dataclass
class CustomSound:
name: str
times: list[list[int]]
times: list
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[int] = dataclasses.field(default_factory=lambda: [8, 0])
lessons_start: list = 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[bool] = dataclasses.field(default_factory=lambda: [True, True, True, True, True, True, False])
sound_files: list[str] = dataclasses.field(default_factory=lambda: ["", "", ""])
workdays: list = dataclasses.field(default_factory=lambda: [True, True, True, True, True, True, False])
sound_files: list = dataclasses.field(default_factory=lambda: ["", "", ""])
first_bell_before_first_lesson: bool = dataclasses.field(default_factory=lambda: True)
custom_sounds: list[CustomSound] = dataclasses.field(default_factory=lambda: [])
custom_sounds: list = 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[str]:
bells_list: list[str] = []
def get_bells_list(self) -> list:
bells_list: list = []
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,11 +95,10 @@ class Scheduler:
return bells_list
def menu_event(self, button) -> None:
match button:
case 0: self.apply_config()
case 1: self.save_config()
case 2: self.bells_enabled = True
case 3: self.bells_enabled = False
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
def update(self) -> None:
if not self.bells_enabled:
@ -109,11 +108,10 @@ 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)
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)
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)
break
def load_config(self) -> None:

View File

@ -222,10 +222,9 @@ class SoundFilesBox(BasicBox):
file_name, _ = QtWidgets.QFileDialog.getOpenFileName(self.grid_widget, "SBC - Відкрити файл", "", "Підтримувані файли (*.wav *.mp3 *.flac)")
if file_name is None:
return
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)
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)
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"
VERSION = "0.2.0_p376"
class MainWindow(QtWidgets.QMainWindow):
def __init__(self, show_sound_diag):
@ -86,21 +86,19 @@ class MenuActions:
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:
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:
self.button_start.setEnabled(False)
self.button_stop .setEnabled(True)
QtWidgets.QMessageBox.information(self.window, "SBC - Інформація", "Дзвінки запущено. Якщо ви налаштували щось не так, самі винні!")
case 3:
elif button == 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 - Про програму", \
elif button == 4:
QtWidgets.QMessageBox.information(self.window, "SBC - Про програму", \
f"SBC {VERSION}\nАвтор: 2o\nTelegram: @xfdtw\nDiscord: @2o___\nЯкщо щось не зрозуміло/не працює пишіть туди.")
class ToolBar(QtWidgets.QToolBar):