Merge pull request #4 from Arduinum/mvp_1_pomodoro
article 9
This commit was merged in pull request #4.
This commit is contained in:
@@ -1,10 +1,8 @@
|
|||||||
from sqlalchemy import select, insert, update, delete
|
from sqlalchemy import select, insert, update, delete
|
||||||
from sqlalchemy.exc import NoResultFound
|
|
||||||
|
|
||||||
from kawai_focus.schemas import TimerModel, TimerListModel
|
from kawai_focus.schemas import TimerModel, TimerListModel
|
||||||
from kawai_focus.database.session import db
|
from kawai_focus.database.session import db
|
||||||
from kawai_focus.database.models import Timer
|
from kawai_focus.database.models import Timer
|
||||||
from kawai_focus.utils.errors import ErrorMessage
|
|
||||||
from kawai_focus.database.decor_erors import crud_error_guard
|
from kawai_focus.database.decor_erors import crud_error_guard
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ from kivy.uix.screenmanager import Screen
|
|||||||
from kawai_focus.custom_widgets.timer_wigets import TimeTomatoInput
|
from kawai_focus.custom_widgets.timer_wigets import TimeTomatoInput
|
||||||
from kawai_focus.schemas import TimerModel
|
from kawai_focus.schemas import TimerModel
|
||||||
from kawai_focus.database.cruds import new_timer
|
from kawai_focus.database.cruds import new_timer
|
||||||
from kawai_focus.utils.utils import calculate_time, custom_timer
|
from kawai_focus.utils.utils import calculate_time, gen_types_timers
|
||||||
from kawai_focus.screens.validators_fields import validate_title
|
from kawai_focus.screens.validators_fields import validate_title
|
||||||
|
|
||||||
|
|
||||||
@@ -38,7 +38,10 @@ class TimerConstructorScreen(Screen):
|
|||||||
time_culc = calculate_time(mm_user=timer.pomodoro_time)
|
time_culc = calculate_time(mm_user=timer.pomodoro_time)
|
||||||
screen_timer.timer_start_time = time_culc
|
screen_timer.timer_start_time = time_culc
|
||||||
screen_timer.ids.time_label.text = time_culc
|
screen_timer.ids.time_label.text = time_culc
|
||||||
screen_timer.timer_generator = custom_timer(mm_user=timer.pomodoro_time)
|
screen_timer.ids.title_label.text = timer.title
|
||||||
|
screen_timer.source_timer_names = gen_types_timers(count_pomodoro=timer.count_pomodoro)
|
||||||
|
|
||||||
|
self.manager.state_machine = screen_timer.source_timer_names.copy()
|
||||||
self.manager.current = 'timers_screen'
|
self.manager.current = 'timers_screen'
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ from kivy.uix.screenmanager import Screen
|
|||||||
from kivy.clock import Clock
|
from kivy.clock import Clock
|
||||||
from kivy.core.audio import SoundLoader
|
from kivy.core.audio import SoundLoader
|
||||||
|
|
||||||
from kawai_focus.utils.utils import data_json
|
from kawai_focus.utils.utils import data_json, custom_timer, calculate_time
|
||||||
|
|
||||||
|
|
||||||
class TimerScreen(Screen):
|
class TimerScreen(Screen):
|
||||||
@@ -22,6 +22,28 @@ class TimerScreen(Screen):
|
|||||||
self.sound_stop_event = None
|
self.sound_stop_event = None
|
||||||
self.timer = None
|
self.timer = None
|
||||||
self.timer_start_time = None
|
self.timer_start_time = None
|
||||||
|
self.source_timer_names = None
|
||||||
|
|
||||||
|
def choice_timer(self) -> None:
|
||||||
|
"""Метод для выбора таймера"""
|
||||||
|
|
||||||
|
current_timer_name = self.manager.state_machine.pop(0)
|
||||||
|
|
||||||
|
if current_timer_name == 'pomodoro':
|
||||||
|
self.timer_generator = custom_timer(mm_user=self.timer.pomodoro_time)
|
||||||
|
self.ids.time_label.text = calculate_time(mm_user=self.timer.pomodoro_time)
|
||||||
|
self.ids.type_timer_label.text = 'Помидор'
|
||||||
|
elif current_timer_name == 'break':
|
||||||
|
self.timer_generator = custom_timer(mm_user=self.timer.break_time)
|
||||||
|
self.ids.time_label.text = calculate_time(mm_user=self.timer.break_time)
|
||||||
|
self.ids.type_timer_label.text = 'Перерыв'
|
||||||
|
else:
|
||||||
|
self.timer_generator = custom_timer(mm_user=self.timer.break_long_time)
|
||||||
|
self.ids.time_label.text = calculate_time(mm_user=self.timer.break_long_time)
|
||||||
|
self.ids.type_timer_label.text = 'Перерывище'
|
||||||
|
|
||||||
|
self.ids.stop_button.opacity = 0
|
||||||
|
self.ids.stop_button.disabled = True
|
||||||
|
|
||||||
def start_timer(self, instance) -> None:
|
def start_timer(self, instance) -> None:
|
||||||
"""Метод для запуска таймера"""
|
"""Метод для запуска таймера"""
|
||||||
@@ -30,8 +52,14 @@ class TimerScreen(Screen):
|
|||||||
self.paused = False
|
self.paused = False
|
||||||
else:
|
else:
|
||||||
# Инициализация генератора таймера
|
# Инициализация генератора таймера
|
||||||
|
if len(self.manager.state_machine) and self.timer_generator is None:
|
||||||
|
self.choice_timer()
|
||||||
|
|
||||||
|
self.ids.stop_button.opacity = 1
|
||||||
|
self.ids.stop_button.disabled = False
|
||||||
|
|
||||||
self.remaining_time = next(self.timer_generator, self.zero_time)
|
self.remaining_time = next(self.timer_generator, self.zero_time)
|
||||||
|
|
||||||
# Запуск обновления времени каждую секунду
|
# Запуск обновления времени каждую секунду
|
||||||
Clock.schedule_interval(self.update_time, 1)
|
Clock.schedule_interval(self.update_time, 1)
|
||||||
|
|
||||||
@@ -57,6 +85,11 @@ class TimerScreen(Screen):
|
|||||||
Clock.unschedule(self.sound_stop_event)
|
Clock.unschedule(self.sound_stop_event)
|
||||||
self.sound_stop_event = None
|
self.sound_stop_event = None
|
||||||
|
|
||||||
|
if not len(self.manager.state_machine):
|
||||||
|
self.manager.state_machine = self.source_timer_names.copy()
|
||||||
|
|
||||||
|
self.choice_timer()
|
||||||
|
|
||||||
def play_sound(self, dt) -> None:
|
def play_sound(self, dt) -> None:
|
||||||
"""Метод для воспроизведения звука"""
|
"""Метод для воспроизведения звука"""
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
{
|
{
|
||||||
"sound_timer": "alarm-beep.mp3",
|
"sound_timer": "alarm-beep.mp3",
|
||||||
"zero_time": "00:00:00",
|
"zero_time": "00:00:00"
|
||||||
"custom_time": "00:00:12"
|
|
||||||
}
|
}
|
||||||
@@ -71,3 +71,12 @@ def calculate_time(mm_user: int) -> str:
|
|||||||
f"{'0' + str(valid_data.hh) if valid_data.hh <= 9 else valid_data.hh}:"
|
f"{'0' + str(valid_data.hh) if valid_data.hh <= 9 else valid_data.hh}:"
|
||||||
f"{'0' + str(valid_data.mm) if valid_data.mm <= 9 else valid_data.mm}:00"
|
f"{'0' + str(valid_data.mm) if valid_data.mm <= 9 else valid_data.mm}:00"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def gen_types_timers(count_pomodoro: int) -> list[str]:
|
||||||
|
"""Функция для генерирования списка типов таймеров для очереди"""
|
||||||
|
|
||||||
|
types_timers_list = ['break' if num % 2 == 0 else 'pomodoro' for num in range(1, count_pomodoro * 2)]
|
||||||
|
types_timers_list.append('long_break')
|
||||||
|
|
||||||
|
return types_timers_list
|
||||||
|
|||||||
@@ -2,6 +2,19 @@
|
|||||||
|
|
||||||
<TimerScreen>:
|
<TimerScreen>:
|
||||||
FloatLayout:
|
FloatLayout:
|
||||||
|
# Label для названия таймера
|
||||||
|
Label:
|
||||||
|
id: title_label
|
||||||
|
size_hint: None, None
|
||||||
|
pos_hint: {'center_x': 0.3, 'center_y': 0.7}
|
||||||
|
|
||||||
|
# Label для типа таймера
|
||||||
|
Label:
|
||||||
|
id: type_timer_label
|
||||||
|
text: 'Помидор'
|
||||||
|
size_hint: None, None
|
||||||
|
pos_hint: {'center_x': 0.7, 'center_y': 0.7}
|
||||||
|
|
||||||
# Кнопка "Старт"
|
# Кнопка "Старт"
|
||||||
Button:
|
Button:
|
||||||
text: 'Старт'
|
text: 'Старт'
|
||||||
@@ -22,7 +35,10 @@
|
|||||||
|
|
||||||
# Кнопка "Стоп"
|
# Кнопка "Стоп"
|
||||||
Button:
|
Button:
|
||||||
|
id: stop_button
|
||||||
text: 'Стоп'
|
text: 'Стоп'
|
||||||
|
opacity: 0
|
||||||
|
disabled: True
|
||||||
size_hint: None, None
|
size_hint: None, None
|
||||||
height: 40
|
height: 40
|
||||||
width: 100
|
width: 100
|
||||||
@@ -32,6 +48,5 @@
|
|||||||
# Label для отображения времени
|
# Label для отображения времени
|
||||||
Label:
|
Label:
|
||||||
id: time_label
|
id: time_label
|
||||||
# text: root.get_init_time(self)
|
|
||||||
size_hint: None, None
|
size_hint: None, None
|
||||||
pos_hint: {'center_x': 0.5, 'center_y': 0.6}
|
pos_hint: {'center_x': 0.5, 'center_y': 0.6}
|
||||||
Reference in New Issue
Block a user