From f4da6d9f12d72634475704d49d0cb51129d28dba Mon Sep 17 00:00:00 2001 From: Arduinum628 Date: Thu, 19 Jun 2025 10:28:26 +0300 Subject: [PATCH] feat: added demo timer_constructor; docs: added db in the .gitignore --- .gitignore | 1 + kawai_focus/custom_widgets/__init__.py | 0 kawai_focus/custom_widgets/timer_wigets.py | 52 +++++++ kawai_focus/main.py | 3 + .../screens/timer_constructor_screen.py | 42 ++++++ kawai_focus/screens/timer_screen.py | 15 +- kv/timer_constructor_screen.kv | 133 ++++++++++++++++++ kv/timer_screen.kv | 2 +- timer.db | Bin 16384 -> 0 bytes 9 files changed, 242 insertions(+), 6 deletions(-) create mode 100644 kawai_focus/custom_widgets/__init__.py create mode 100644 kawai_focus/custom_widgets/timer_wigets.py create mode 100644 kawai_focus/screens/timer_constructor_screen.py create mode 100644 kv/timer_constructor_screen.kv delete mode 100644 timer.db diff --git a/.gitignore b/.gitignore index 199fea6..e2811d0 100644 --- a/.gitignore +++ b/.gitignore @@ -60,6 +60,7 @@ cover/ local_settings.py db.sqlite3 db.sqlite3-journal +timer.db # Flask stuff: instance/ diff --git a/kawai_focus/custom_widgets/__init__.py b/kawai_focus/custom_widgets/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/kawai_focus/custom_widgets/timer_wigets.py b/kawai_focus/custom_widgets/timer_wigets.py new file mode 100644 index 0000000..99e1805 --- /dev/null +++ b/kawai_focus/custom_widgets/timer_wigets.py @@ -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' diff --git a/kawai_focus/main.py b/kawai_focus/main.py index bf51bd3..4f3f1c6 100644 --- a/kawai_focus/main.py +++ b/kawai_focus/main.py @@ -9,6 +9,7 @@ from kivy.logger import Logger import logging from kawai_focus.screens.timer_screen import TimerScreen +from kawai_focus.screens.timer_constructor_screen import TimerConstructorScreen Logger.setLevel(logging.DEBUG) @@ -22,8 +23,10 @@ class KawaiFocusApp(App): def build(self): # Загрузка kv файла Builder.load_file('kv/timer_screen.kv') + Builder.load_file('kv/timer_constructor_screen.kv') screen_manager = ScreenManager() + screen_manager.add_widget(TimerConstructorScreen(name='timer_constructor_screen')) screen_manager.add_widget(TimerScreen(name='timers_screen')) return screen_manager diff --git a/kawai_focus/screens/timer_constructor_screen.py b/kawai_focus/screens/timer_constructor_screen.py new file mode 100644 index 0000000..ad89881 --- /dev/null +++ b/kawai_focus/screens/timer_constructor_screen.py @@ -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 diff --git a/kawai_focus/screens/timer_screen.py b/kawai_focus/screens/timer_screen.py index 9289721..de51c59 100644 --- a/kawai_focus/screens/timer_screen.py +++ b/kawai_focus/screens/timer_screen.py @@ -21,6 +21,7 @@ class TimerScreen(Screen): self.paused = False self.remaining_time = None self.sound_stop_event = None + self.timer = None def start_timer(self, instance) -> None: """Метод для запуска таймера""" @@ -29,8 +30,8 @@ class TimerScreen(Screen): self.paused = False else: # Инициализация генератора таймера - vaid_timer_data = TimerTimeModel(ss=12) # Установите необходимое время - self.timer_generator = custom_timer(valid_data=vaid_timer_data) + self.valid_timer_data = TimerTimeModel(mm=self.timer.pomodoro_time) + self.timer_generator = custom_timer(valid_data=self.valid_timer_data) self.remaining_time = next(self.timer_generator, self.zero_time) # Запуск обновления времени каждую секунду @@ -50,9 +51,13 @@ class TimerScreen(Screen): # Остановка обновления времени Clock.unschedule(self.update_time) self.paused = False - # TODO: временное решение, время будет задаваться в интерфейсе - self.remaining_time = data_json.get_text('custom_time') - self.ids.time_label.text = self.remaining_time + self.remaining_time = TimerTimeModel(mm=self.timer.pomodoro_time).mm + # Todo: временное решение: нужно сделать механизм для + # автоматического рассчёта часов, минут и секунд из + # колличества минут, введённого пользователем + 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() diff --git a/kv/timer_constructor_screen.kv b/kv/timer_constructor_screen.kv new file mode 100644 index 0000000..79183a2 --- /dev/null +++ b/kv/timer_constructor_screen.kv @@ -0,0 +1,133 @@ +#:kivy 2.3.1 + +: + 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) \ No newline at end of file diff --git a/kv/timer_screen.kv b/kv/timer_screen.kv index 55d64f1..e95306e 100644 --- a/kv/timer_screen.kv +++ b/kv/timer_screen.kv @@ -32,6 +32,6 @@ # Label для отображения времени Label: id: time_label - text: '00:00:12' + # text: root.get_init_time(self) size_hint: None, None pos_hint: {'center_x': 0.5, 'center_y': 0.6} \ No newline at end of file diff --git a/timer.db b/timer.db deleted file mode 100644 index 4d2ca7797d33860377594b6c23842c2b754721a1..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 16384 zcmeI(O=}ZD7zgl~q&7`pT~FPc41qwFh_sF9MZq;JT8ydPMxm!=(~Pi~7frU}u??sP z4}J>oB^s>S#*_EiPtmJKk3PGmC0T0eQObXknSGgg=H<708A3MJt9~HGvu>~L1)|KZ zFwWUsAsAzel;|ayjZQ(?fbTK zR>UX@4|l@%(QxO8puW|2^@&Q#(U9lr;9DHEAHJjJyWxPwiesmzJ66NfhxePOuH&(@ z`p9xN#Y1~j6#b@|Gj~m%F-j#q$i~iIOST*SmitQf`hK^QxJ=F1Cn}?-FbQ)z+wBwn z^2)4!Wv#YRcPwHSi5}b+&$qHYuT-~W%8eng+2V1fVyAOHaf zKmY;|fB*y_009U<;J+0xQkep$#7<5E*$>>n&#;WPK#3WA(qd9Ue;{#}Z_i)7^anp% B6F>j}