from icecream import ic from dataclasses import dataclass from random import randint import pygame import time import sys import os def resource_path(relative_path): """ Get absolute path to resource, works for dev and for PyInstaller """ try: # PyInstaller creates a temp folder and stores path in _MEIPASS base_path = sys._MEIPASS except Exception: base_path = os.path.abspath(".") return os.path.join(base_path, relative_path) class Queue(object): def __init__(self): self.tasks = [] self.task_slots = {} self.task_brake = self.set_break() self.run_task = False self.task_slots_max = 6 self.current_task = None self.current_task_time = 0 self.current_task_time_current = 0 self.current_task_time_max = 0 pygame.mixer.init() def sound(self): sound = pygame.mixer.Sound(resource_path(self.current_task.sound)) sound.play() def set_break(self): task_id = -1 task_name = f"Перерыв 10 минут" task_count = 0 task_description = f"Десятиминутный перерыв" task_time = 0 task_sound = f"./sounds/break.mp3" return Task(task_id, task_name, task_count, task_description, task_time, task_sound, False) def create_task(self, name, description = '', num = 0): task_id = num task_name = name task_count = 0 task_description = description task_time = 0 task_sound = f"./sounds/default.mp3" self.task_slots[str(num)]=Task(task_id, task_name, task_count, task_description, task_time, task_sound, False) def delete_task(self, num): del self.task_slots[str(num)] def start_unic_task(self, num): task_keys = [key for key in list(self.task_slots.keys()) if not self.task_slots[key].finished] if num in task_keys: result = num d = dice() if d == 5: self.current_task = self.task_brake self.current_task_time = timers[d] self.current_task_time_max = time.time() + self.current_task_time else: self.current_task = self.task_slots[result] self.current_task_time = timers[d] self.current_task_time_max = time.time() + self.current_task_time else: return def start_task(self): task_keys = [key for key in list(self.task_slots.keys()) if not self.task_slots[key].finished] ic(task_keys) result = task_keys[randint(0, len(task_keys) - 1)] d = dice() if d == 5: self.current_task = self.task_brake self.current_task_time = timers[d] self.current_task_time_max = time.time() + self.current_task_time else: self.current_task = self.task_slots[result] self.current_task_time = timers[d] self.current_task_time_max = time.time() + self.current_task_time def dice(): return randint(0,5) @dataclass class Task: id: int name: str count: int #1-6 description: str time: int #seconds sound: str #path to sound file finished: bool timers = [ 600, #10minutes 1200, #20minutes 1800, #30minutes 2400, #40minutes 3000, #50minutes 600, #10minutes break ]