handOver2/ui/dialogs/weather_location_dialog.py

141 lines
4.3 KiB
Python

# -*- coding: utf-8 -*-
"""
날씨 지역 설정 다이얼로그 모듈
날씨 정보를 표시할 지역을 설정합니다.
"""
from PySide6.QtWidgets import QLabel
from PySide6.QtGui import QFont
from ui.base.base_dialog import BaseDialog
from ui.components.custom_input import CustomComboBox, LabeledInput
from core.config import ConfigManager
from core.logger import get_logger
logger = get_logger(__name__)
# 주요 도시 목록
CITIES = [
"서울", "부산", "대구", "인천", "광주", "대전", "울산",
"수원", "고양", "용인", "성남", "부천", "화성", "안산",
"안양", "평택", "의정부", "시흥", "김포", "광명", "이천"
]
# 도시별 좌표 (위도, 경도)
CITY_COORDINATES = {
"서울": (37.5665, 126.9780),
"부산": (35.1796, 129.0756),
"대구": (35.8714, 128.6014),
"인천": (37.4563, 126.7052),
"광주": (35.1595, 126.8526),
"대전": (36.3504, 127.3845),
"울산": (35.5384, 129.3114),
"수원": (37.2636, 127.0286),
"고양": (37.6584, 126.8320),
"용인": (37.2411, 127.1776),
"성남": (37.4201, 127.1267),
"부천": (37.5034, 126.7660),
"화성": (37.1995, 126.8311),
"안산": (37.3219, 126.8309),
"안양": (37.3925, 126.9269),
"평택": (36.9909, 127.0856),
"의정부": (37.7381, 127.0477),
"시흥": (37.3800, 126.8029),
"김포": (37.6156, 126.7155),
"광명": (37.4783, 126.8646),
"이천": (37.2720, 127.4420),
}
# 도시별 기상청 지역 코드
CITY_CODES = {
"서울": "1168000000",
"부산": "2638057200",
"대구": "2720000000",
"인천": "2810000000",
"광주": "2911000000",
"대전": "3011000000",
"울산": "3117000000",
"수원": "4111000000",
"고양": "4128000000",
"용인": "4146000000",
"성남": "4113000000",
"부천": "4119000000",
"화성": "4159000000",
"안산": "4127000000",
"안양": "4117000000",
"평택": "4122000000",
"의정부": "4115000000",
"시흥": "4153000000",
"김포": "4157000000",
"광명": "4121000000",
"이천": "4150000000",
}
class WeatherLocationDialog(BaseDialog):
"""
날씨 지역 설정 다이얼로그
날씨 정보를 표시할 지역을 선택합니다.
"""
def __init__(self, parent=None):
self.config = ConfigManager()
super().__init__(
parent,
title="날씨 지역 설정",
width=400,
height=300,
resizable=False
)
self._setup_content()
self.add_confirm_cancel_buttons("저장", "취소")
def _setup_content(self):
"""컨텐츠 설정"""
theme = self.config.theme
is_dark = theme == 'dark'
# 설명
info = QLabel("날씨 정보를 표시할 지역을 선택하세요.")
info.setFont(QFont("GmarketSans", 11))
info.setStyleSheet(f"color: {'#94a3b8' if is_dark else '#64748b'};")
info.setWordWrap(True)
self.content_layout.addWidget(info)
# 지역 선택
self.location_combo = CustomComboBox(items=CITIES)
current_location = self.config.get('weather', 'location_name', '부산')
if current_location in CITIES:
self.location_combo.set_selected_value(current_location)
else:
self.location_combo.set_selected_value('부산')
self.content_layout.addWidget(
LabeledInput("지역", self.location_combo)
)
self.content_layout.addStretch()
def _on_confirm(self):
"""저장 버튼 클릭"""
selected_city = self.location_combo.currentText()
if selected_city in CITY_COORDINATES:
lat, lon = CITY_COORDINATES[selected_city]
code = CITY_CODES.get(selected_city, "2638057200") # 기본값: 부산
# 설정 저장
self.config.set('weather', 'location_name', selected_city)
self.config.set('weather', 'location_lat', lat)
self.config.set('weather', 'location_lon', lon)
self.config.set('weather', 'location_code', code) # 지역 코드도 저장
self.config.save()
logger.info("날씨 지역 변경: %s (%.4f, %.4f, %s)", selected_city, lat, lon, code)
self.accept()