64 lines
2.6 KiB
Python
64 lines
2.6 KiB
Python
import customtkinter as ctk
|
|
from customtkinter import FontManager
|
|
from view.ui_utils import AssetLoader
|
|
|
|
class ThemeManager:
|
|
_instance = None
|
|
|
|
# 폰트 설정 (상수)
|
|
# TTF 파일 내부의 패밀리 이름을 정확히 알아야 함 (보통 Gmarket Sans TTF Medium)
|
|
# 여기서는 'Gmarket Sans TTF Medium' (또는 'Gmarket Sans')으로 추정
|
|
FONT_FAMILY = "Gmarket Sans TTF Medium"
|
|
|
|
def __new__(cls, *args, **kwargs):
|
|
if not cls._instance:
|
|
cls._instance = super(ThemeManager, cls).__new__(cls, *args, **kwargs)
|
|
cls._instance.current_theme = "System"
|
|
cls._instance._load_custom_font()
|
|
return cls._instance
|
|
|
|
def _load_custom_font(self):
|
|
"""커스텀 폰트 파일 로드"""
|
|
assets_dir = AssetLoader.get_assets_dir()
|
|
# 파일명은 사용자 제공대로 (확장자 주의)
|
|
font_path = assets_dir / "GmarketSansTTFMedium.ttf"
|
|
|
|
if font_path.exists():
|
|
try:
|
|
# CustomTkinter의 FontManager를 통해 폰트 로드 시도
|
|
success = FontManager.load_font(str(font_path))
|
|
if success:
|
|
print(f"[Theme] 폰트 로드 성공: {font_path.name}")
|
|
else:
|
|
# 실패 시 시스템 기본 폰트로 폴백될 수 있음
|
|
print(f"[Theme] 폰트 로드 실패 (반환값 False): {font_path.name}")
|
|
# 실패하더라도 일단 상수 유지, 시스템이 못 찾으면 기본 폰트 사용
|
|
except Exception as e:
|
|
print(f"[Theme] 폰트 로드 예외 발생: {e}")
|
|
# 예외 발생 시 기본 폰트로 변경
|
|
self.FONT_FAMILY = "Malgun Gothic" # 윈도우 기본
|
|
else:
|
|
print(f"[Theme] 폰트 파일을 찾을 수 없음: {font_path}")
|
|
self.FONT_FAMILY = "Malgun Gothic"
|
|
|
|
def set_theme(self, theme_mode):
|
|
"""테마 적용 (Dark, Light, System)"""
|
|
self.current_theme = theme_mode
|
|
ctk.set_appearance_mode(theme_mode)
|
|
ctk.set_default_color_theme("blue") # 기본 색상 테마
|
|
|
|
def toggle_theme(self):
|
|
"""다크 <-> 라이트 전환"""
|
|
new_mode = "Light" if self.current_theme == "Dark" else "Dark"
|
|
self.set_theme(new_mode)
|
|
return new_mode
|
|
|
|
@classmethod
|
|
def get_font(cls, size=12, weight="normal"):
|
|
"""일관된 폰트 반환 헬퍼 (튜플 형태)"""
|
|
# weight 인자는 무시될 가능성 높음 (단일 폰트 파일인 경우)
|
|
family = cls.FONT_FAMILY
|
|
return (family, size)
|
|
|
|
theme_manager = ThemeManager()
|