feat: added demo timer_constructor; docs: added db in the .gitignore
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -60,6 +60,7 @@ cover/
|
|||||||
local_settings.py
|
local_settings.py
|
||||||
db.sqlite3
|
db.sqlite3
|
||||||
db.sqlite3-journal
|
db.sqlite3-journal
|
||||||
|
timer.db
|
||||||
|
|
||||||
# Flask stuff:
|
# Flask stuff:
|
||||||
instance/
|
instance/
|
||||||
|
|||||||
0
kawai_focus/custom_widgets/__init__.py
Normal file
0
kawai_focus/custom_widgets/__init__.py
Normal file
52
kawai_focus/custom_widgets/timer_wigets.py
Normal file
52
kawai_focus/custom_widgets/timer_wigets.py
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
from kivy.uix.textinput import TextInput
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class BaseNumInput(TextInput):
|
||||||
|
"""Базовый класс для поля числа"""
|
||||||
|
|
||||||
|
def __init__(self, **kwargs):
|
||||||
|
super().__init__(**kwargs)
|
||||||
|
self.text = '0'
|
||||||
|
self.halign = 'center'
|
||||||
|
|
||||||
|
def increment(self):
|
||||||
|
"""Метод для прибавки 1"""
|
||||||
|
|
||||||
|
self.text = str(int(self.text) + 1)
|
||||||
|
|
||||||
|
def decrement(self):
|
||||||
|
"""Метод для вычитания 1"""
|
||||||
|
|
||||||
|
self.text = str(int(self.text) - 1)
|
||||||
|
|
||||||
|
|
||||||
|
class TimeTomatoInput(BaseNumInput):
|
||||||
|
"""Класс для поля ввода колличества помидорово"""
|
||||||
|
|
||||||
|
def __init__(self, **kwargs):
|
||||||
|
super().__init__(**kwargs)
|
||||||
|
self.text = '25'
|
||||||
|
|
||||||
|
|
||||||
|
class TimeBreakInput(BaseNumInput):
|
||||||
|
"""Класс для поля ввода времени перерыва"""
|
||||||
|
|
||||||
|
def __init__(self, **kwargs):
|
||||||
|
super().__init__(**kwargs)
|
||||||
|
self.text = '5'
|
||||||
|
|
||||||
|
class TimeLoongBreakInput(BaseNumInput):
|
||||||
|
"""Класс для поля ввода времени длительного перерыва"""
|
||||||
|
|
||||||
|
def __init__(self, **kwargs):
|
||||||
|
super().__init__(**kwargs)
|
||||||
|
self.text = '15'
|
||||||
|
|
||||||
|
|
||||||
|
class CountTomatosInput(BaseNumInput):
|
||||||
|
"""Класс для поля ввода количества помидоров"""
|
||||||
|
|
||||||
|
def __init__(self, **kwargs):
|
||||||
|
super().__init__(**kwargs)
|
||||||
|
self.text = '4'
|
||||||
@@ -9,6 +9,7 @@ from kivy.logger import Logger
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
from kawai_focus.screens.timer_screen import TimerScreen
|
from kawai_focus.screens.timer_screen import TimerScreen
|
||||||
|
from kawai_focus.screens.timer_constructor_screen import TimerConstructorScreen
|
||||||
|
|
||||||
|
|
||||||
Logger.setLevel(logging.DEBUG)
|
Logger.setLevel(logging.DEBUG)
|
||||||
@@ -22,8 +23,10 @@ class KawaiFocusApp(App):
|
|||||||
def build(self):
|
def build(self):
|
||||||
# Загрузка kv файла
|
# Загрузка kv файла
|
||||||
Builder.load_file('kv/timer_screen.kv')
|
Builder.load_file('kv/timer_screen.kv')
|
||||||
|
Builder.load_file('kv/timer_constructor_screen.kv')
|
||||||
|
|
||||||
screen_manager = ScreenManager()
|
screen_manager = ScreenManager()
|
||||||
|
screen_manager.add_widget(TimerConstructorScreen(name='timer_constructor_screen'))
|
||||||
screen_manager.add_widget(TimerScreen(name='timers_screen'))
|
screen_manager.add_widget(TimerScreen(name='timers_screen'))
|
||||||
return screen_manager
|
return screen_manager
|
||||||
|
|
||||||
|
|||||||
42
kawai_focus/screens/timer_constructor_screen.py
Normal file
42
kawai_focus/screens/timer_constructor_screen.py
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
from kivy.uix.screenmanager import Screen
|
||||||
|
|
||||||
|
from kawai_focus.custom_widgets.timer_wigets import TimeTomatoInput
|
||||||
|
from kawai_focus.schemas import TimerModel
|
||||||
|
from kawai_focus.database.cruds import new_timer
|
||||||
|
|
||||||
|
|
||||||
|
class TimerConstructorScreen(Screen):
|
||||||
|
"""Экран конструктора таймера"""
|
||||||
|
|
||||||
|
def __init__(self, **kwargs):
|
||||||
|
super(TimerConstructorScreen, self).__init__(**kwargs)
|
||||||
|
|
||||||
|
def create_timer(self, instance):
|
||||||
|
"""Метод для создания таймера"""
|
||||||
|
|
||||||
|
timer = new_timer(
|
||||||
|
data=TimerModel(
|
||||||
|
title=self.ids.title.text,
|
||||||
|
pomodoro_time=int(self.ids.time_tomato_input.text),
|
||||||
|
break_time=int(self.ids.time_break_input.text),
|
||||||
|
break_long_time=int(self.ids.time_long_break_input.text),
|
||||||
|
count_pomodoro=int(self.ids.count_tomatos_input.text)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
if timer:
|
||||||
|
screen_timer = self.manager.get_screen('timers_screen')
|
||||||
|
screen_timer.timer = timer
|
||||||
|
# Todo: временное решение: нужно сделать механизм для
|
||||||
|
# автоматического рассчёта часов, минут и секунд из
|
||||||
|
# колличества минут, введённого пользователем
|
||||||
|
screen_timer.ids.time_label.text = f'00:{
|
||||||
|
"0" + str(timer.pomodoro_time) if timer.pomodoro_time <= 9 else timer.pomodoro_time
|
||||||
|
}:00'
|
||||||
|
self.manager.current = 'timers_screen'
|
||||||
|
|
||||||
|
|
||||||
|
def back(self, instance) -> None:
|
||||||
|
"""Метод для кнопки назад - возврат в меню таймеров"""
|
||||||
|
|
||||||
|
pass
|
||||||
@@ -21,6 +21,7 @@ class TimerScreen(Screen):
|
|||||||
self.paused = False
|
self.paused = False
|
||||||
self.remaining_time = None
|
self.remaining_time = None
|
||||||
self.sound_stop_event = None
|
self.sound_stop_event = None
|
||||||
|
self.timer = None
|
||||||
|
|
||||||
def start_timer(self, instance) -> None:
|
def start_timer(self, instance) -> None:
|
||||||
"""Метод для запуска таймера"""
|
"""Метод для запуска таймера"""
|
||||||
@@ -29,8 +30,8 @@ class TimerScreen(Screen):
|
|||||||
self.paused = False
|
self.paused = False
|
||||||
else:
|
else:
|
||||||
# Инициализация генератора таймера
|
# Инициализация генератора таймера
|
||||||
vaid_timer_data = TimerTimeModel(ss=12) # Установите необходимое время
|
self.valid_timer_data = TimerTimeModel(mm=self.timer.pomodoro_time)
|
||||||
self.timer_generator = custom_timer(valid_data=vaid_timer_data)
|
self.timer_generator = custom_timer(valid_data=self.valid_timer_data)
|
||||||
self.remaining_time = next(self.timer_generator, self.zero_time)
|
self.remaining_time = next(self.timer_generator, self.zero_time)
|
||||||
|
|
||||||
# Запуск обновления времени каждую секунду
|
# Запуск обновления времени каждую секунду
|
||||||
@@ -50,9 +51,13 @@ class TimerScreen(Screen):
|
|||||||
# Остановка обновления времени
|
# Остановка обновления времени
|
||||||
Clock.unschedule(self.update_time)
|
Clock.unschedule(self.update_time)
|
||||||
self.paused = False
|
self.paused = False
|
||||||
# TODO: временное решение, время будет задаваться в интерфейсе
|
self.remaining_time = TimerTimeModel(mm=self.timer.pomodoro_time).mm
|
||||||
self.remaining_time = data_json.get_text('custom_time')
|
# Todo: временное решение: нужно сделать механизм для
|
||||||
self.ids.time_label.text = self.remaining_time
|
# автоматического рассчёта часов, минут и секунд из
|
||||||
|
# колличества минут, введённого пользователем
|
||||||
|
self.ids.time_label.text = f'00:{
|
||||||
|
"0" + str(self.remaining_time) if self.remaining_time <= 9 else self.remaining_time
|
||||||
|
}:00'
|
||||||
|
|
||||||
self.sound.stop()
|
self.sound.stop()
|
||||||
|
|
||||||
|
|||||||
133
kv/timer_constructor_screen.kv
Normal file
133
kv/timer_constructor_screen.kv
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
#:kivy 2.3.1
|
||||||
|
|
||||||
|
<TimerConstructorScreen>:
|
||||||
|
FloatLayout:
|
||||||
|
# поле вовода "название"
|
||||||
|
TextInput:
|
||||||
|
id: title
|
||||||
|
size_hint: None, None
|
||||||
|
size: 220, 30
|
||||||
|
pos_hint: {"center_x": 0.5, "center_y": 0.9}
|
||||||
|
hint_text: "название"
|
||||||
|
|
||||||
|
# числовой счётчик "время помидора"
|
||||||
|
Label:
|
||||||
|
text: "помидор"
|
||||||
|
size_hint: None, None
|
||||||
|
pos_hint: {"center_x": 0.3, "center_y": 0.7}
|
||||||
|
|
||||||
|
Button:
|
||||||
|
text: "-"
|
||||||
|
size_hint: None, None
|
||||||
|
size: 40, 40
|
||||||
|
pos_hint: {"center_x": 0.5, "center_y": 0.7}
|
||||||
|
on_press: time_tomato_input.decrement()
|
||||||
|
|
||||||
|
TimeTomatoInput:
|
||||||
|
id: time_tomato_input
|
||||||
|
size_hint: None, None
|
||||||
|
size: 40, 30
|
||||||
|
pos_hint: {"center_x": 0.6, "center_y": 0.7}
|
||||||
|
|
||||||
|
Button:
|
||||||
|
text: "+"
|
||||||
|
size_hint: None, None
|
||||||
|
size: 40, 40
|
||||||
|
pos_hint: {"center_x": 0.7, "center_y": 0.7}
|
||||||
|
on_press: time_tomato_input.increment()
|
||||||
|
|
||||||
|
# числовой счётчик "время прерыва"
|
||||||
|
Label:
|
||||||
|
text: "перерыв"
|
||||||
|
size_hint: None, None
|
||||||
|
pos_hint: {"center_x": 0.3, "center_y": 0.6}
|
||||||
|
|
||||||
|
Button:
|
||||||
|
text: "-"
|
||||||
|
size_hint: None, None
|
||||||
|
size: 40, 40
|
||||||
|
pos_hint: {"center_x": 0.5, "center_y": 0.6}
|
||||||
|
on_press: time_break_input.decrement()
|
||||||
|
|
||||||
|
TimeBreakInput:
|
||||||
|
id: time_break_input
|
||||||
|
size_hint: None, None
|
||||||
|
size: 40, 30
|
||||||
|
pos_hint: {"center_x": 0.6, "center_y": 0.6}
|
||||||
|
|
||||||
|
Button:
|
||||||
|
text: "+"
|
||||||
|
size_hint: None, None
|
||||||
|
size: 40, 40
|
||||||
|
pos_hint: {"center_x": 0.7, "center_y": 0.6}
|
||||||
|
on_press: time_break_input.increment()
|
||||||
|
|
||||||
|
# числовой счётчик "время длительного перерыва"
|
||||||
|
Label:
|
||||||
|
text: "перерывище"
|
||||||
|
size_hint: None, None
|
||||||
|
pos_hint: {"center_x": 0.3, "center_y": 0.5}
|
||||||
|
|
||||||
|
Button:
|
||||||
|
text: "-"
|
||||||
|
size_hint: None, None
|
||||||
|
size: 40, 40
|
||||||
|
pos_hint: {"center_x": 0.5, "center_y": 0.5}
|
||||||
|
on_press: time_long_break_input.decrement()
|
||||||
|
|
||||||
|
TimeLoongBreakInput:
|
||||||
|
id: time_long_break_input
|
||||||
|
size_hint: None, None
|
||||||
|
size: 40, 30
|
||||||
|
pos_hint: {"center_x": 0.6, "center_y": 0.5}
|
||||||
|
|
||||||
|
Button:
|
||||||
|
text: "+"
|
||||||
|
size_hint: None, None
|
||||||
|
size: 40, 40
|
||||||
|
pos_hint: {"center_x": 0.7, "center_y": 0.5}
|
||||||
|
on_press: time_long_break_input.increment()
|
||||||
|
|
||||||
|
# числовой счётчик "колличество помидоров"
|
||||||
|
Label:
|
||||||
|
text: "помидоров"
|
||||||
|
size_hint: None, None
|
||||||
|
pos_hint: {"center_x": 0.3, "center_y": 0.4}
|
||||||
|
|
||||||
|
Button:
|
||||||
|
text: "-"
|
||||||
|
size_hint: None, None
|
||||||
|
size: 40, 40
|
||||||
|
pos_hint: {"center_x": 0.5, "center_y": 0.4}
|
||||||
|
on_press: count_tomatos_input.decrement()
|
||||||
|
|
||||||
|
CountTomatosInput:
|
||||||
|
id: count_tomatos_input
|
||||||
|
size_hint: None, None
|
||||||
|
size: 40, 30
|
||||||
|
pos_hint: {"center_x": 0.6, "center_y": 0.4}
|
||||||
|
|
||||||
|
Button:
|
||||||
|
text: "+"
|
||||||
|
size_hint: None, None
|
||||||
|
size: 40, 40
|
||||||
|
pos_hint: {"center_x": 0.7, "center_y": 0.4}
|
||||||
|
on_press: count_tomatos_input.increment()
|
||||||
|
|
||||||
|
# Кнопка "Создать"
|
||||||
|
Button:
|
||||||
|
text: 'Создать'
|
||||||
|
size_hint: None, None
|
||||||
|
height: 40
|
||||||
|
width: 100
|
||||||
|
pos_hint: {'center_x': 0.7, 'center_y': 0.1}
|
||||||
|
on_press: root.create_timer(self)
|
||||||
|
|
||||||
|
# Кнопка "Назад"
|
||||||
|
Button:
|
||||||
|
text: 'Назад'
|
||||||
|
size_hint: None, None
|
||||||
|
height: 40
|
||||||
|
width: 100
|
||||||
|
pos_hint: {'center_x': 0.3, 'center_y': 0.1}
|
||||||
|
on_press: root.back(self)
|
||||||
@@ -32,6 +32,6 @@
|
|||||||
# Label для отображения времени
|
# Label для отображения времени
|
||||||
Label:
|
Label:
|
||||||
id: time_label
|
id: time_label
|
||||||
text: '00:00:12'
|
# 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