102 lines
3.1 KiB
Python
102 lines
3.1 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""
|
|
알람 위젯 모듈
|
|
알람 설정(켜기/끄기, 시간 설정)을 위한 재사용 가능한 위젯입니다.
|
|
"""
|
|
|
|
from datetime import time, datetime
|
|
from typing import Optional
|
|
|
|
from PySide6.QtWidgets import (
|
|
QWidget, QHBoxLayout, QLabel, QCheckBox
|
|
)
|
|
from PySide6.QtCore import Qt, Signal, QTime
|
|
from PySide6.QtGui import QFont
|
|
|
|
from ui.components.custom_calendar import TimeSelector
|
|
from core.config import ConfigManager
|
|
|
|
class AlarmWidget(QWidget):
|
|
"""
|
|
알람 설정 위젯
|
|
|
|
알람 활성화 여부와 시간을 설정할 수 있습니다.
|
|
"""
|
|
|
|
alarm_changed = Signal(bool, object) # is_enabled, time (QTime)
|
|
|
|
def __init__(self, parent=None, initial_time: Optional[time] = None):
|
|
super().__init__(parent)
|
|
|
|
self.config = ConfigManager()
|
|
self._is_enabled = False
|
|
|
|
self._setup_ui()
|
|
|
|
if initial_time:
|
|
self.set_alarm(True, initial_time)
|
|
|
|
def _setup_ui(self):
|
|
"""UI 설정"""
|
|
layout = QHBoxLayout(self)
|
|
layout.setContentsMargins(0, 0, 0, 0)
|
|
layout.setSpacing(12)
|
|
|
|
theme = self.config.theme
|
|
text_color = "#f8fafc" if theme == 'dark' else "#1e293b"
|
|
|
|
# 알람 토글
|
|
self.toggle = QCheckBox("알람")
|
|
self.toggle.setFont(QFont("GmarketSans", 11))
|
|
self.toggle.setStyleSheet(f"""
|
|
QCheckBox {{
|
|
color: {text_color};
|
|
spacing: 8px;
|
|
}}
|
|
QCheckBox::indicator {{
|
|
width: 20px;
|
|
height: 20px;
|
|
border: 2px solid {'#475569' if theme == 'dark' else '#e2e8f0'};
|
|
border-radius: 4px;
|
|
}}
|
|
QCheckBox::indicator:checked {{
|
|
background-color: #3b82f6;
|
|
border-color: #3b82f6;
|
|
}}
|
|
""")
|
|
self.toggle.stateChanged.connect(self._on_toggle_changed)
|
|
layout.addWidget(self.toggle)
|
|
|
|
# 시간 선택기
|
|
self.time_selector = TimeSelector(minute_step=10)
|
|
self.time_selector.time_changed.connect(self._on_time_changed)
|
|
self.time_selector.setVisible(False)
|
|
layout.addWidget(self.time_selector)
|
|
|
|
layout.addStretch()
|
|
|
|
def _on_toggle_changed(self, state: int):
|
|
"""토글 변경 시"""
|
|
self._is_enabled = (state == Qt.Checked)
|
|
self.time_selector.setVisible(self._is_enabled)
|
|
|
|
current_time = self.time_selector.get_time()
|
|
self.alarm_changed.emit(self._is_enabled, current_time)
|
|
|
|
def _on_time_changed(self, t: time):
|
|
"""시간 변경 시"""
|
|
if self._is_enabled:
|
|
self.alarm_changed.emit(True, t)
|
|
|
|
def set_alarm(self, enabled: bool, t: Optional[time] = None):
|
|
"""알람 설정"""
|
|
self.toggle.setChecked(enabled)
|
|
if t:
|
|
self.time_selector.set_time(t)
|
|
|
|
def get_alarm(self) -> tuple[bool, Optional[time]]:
|
|
"""알람 설정 반환"""
|
|
if not self._is_enabled:
|
|
return False, None
|
|
return True, self.time_selector.get_time()
|