59 lines
2 KiB
Python
59 lines
2 KiB
Python
|
|
"""Боковая панель"""
|
||
|
|
import tkinter as tk
|
||
|
|
from app.config import Config
|
||
|
|
from app.ui.calendar_widget import CalendarWidget
|
||
|
|
from app.ui.notes_list import NotesList
|
||
|
|
|
||
|
|
|
||
|
|
class Sidebar(tk.Frame):
|
||
|
|
"""Левая боковая панель"""
|
||
|
|
|
||
|
|
def __init__(self, parent, db, on_date_select=None, on_note_select=None, on_note_delete=None):
|
||
|
|
super().__init__(parent, bg=Config.COLORS['sidebar_bg'], width=Config.SIDEBAR_WIDTH)
|
||
|
|
self.db = db
|
||
|
|
self.on_note_select = on_note_select
|
||
|
|
|
||
|
|
self.pack_propagate(False)
|
||
|
|
self.pack(side='left', fill='y')
|
||
|
|
|
||
|
|
self.create_widgets(on_date_select, on_note_delete)
|
||
|
|
|
||
|
|
def create_widgets(self, on_date_select, on_note_delete):
|
||
|
|
# Календарь
|
||
|
|
self.calendar = CalendarWidget(
|
||
|
|
self,
|
||
|
|
self.db,
|
||
|
|
on_date_select=self.on_date_selected
|
||
|
|
)
|
||
|
|
self.calendar.pack(fill='x')
|
||
|
|
|
||
|
|
# Разделитель
|
||
|
|
separator = tk.Frame(self, height=2, bg=Config.COLORS['separator'])
|
||
|
|
separator.pack(fill='x', padx=10, pady=(5, 0))
|
||
|
|
|
||
|
|
# Список заметок
|
||
|
|
self.notes_list = NotesList(
|
||
|
|
self,
|
||
|
|
self.db,
|
||
|
|
on_note_select=self.on_note_selected,
|
||
|
|
on_note_delete=on_note_delete
|
||
|
|
)
|
||
|
|
self.notes_list.pack(fill='both', expand=True)
|
||
|
|
|
||
|
|
def on_date_selected(self, date):
|
||
|
|
"""Обработчик выбора даты в календаре"""
|
||
|
|
self.notes_list.refresh(date)
|
||
|
|
|
||
|
|
def on_note_selected(self, note):
|
||
|
|
"""Обработчик выбора заметки"""
|
||
|
|
if self.on_note_select:
|
||
|
|
self.on_note_select(note)
|
||
|
|
|
||
|
|
def refresh_notes(self):
|
||
|
|
"""Обновить список заметок для текущей даты"""
|
||
|
|
if self.calendar:
|
||
|
|
self.notes_list.refresh(self.calendar.selected_date)
|
||
|
|
|
||
|
|
def get_selected_date(self):
|
||
|
|
"""Получить выбранную дату"""
|
||
|
|
return self.calendar.selected_date if self.calendar else None
|