43 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			43 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
import ctypes
 | 
						|
from PySide6.QtCore import QSettings, Signal, QObject
 | 
						|
from PySide6.QtWidgets import QMessageBox
 | 
						|
 | 
						|
def set_dark_title_bar(hwnd, enable=True):
 | 
						|
    """Включает тёмный заголовок окна в Windows 10+."""
 | 
						|
    DWMWA_USE_IMMERSIVE_DARK_MODE = 20
 | 
						|
    value = ctypes.c_int(1 if enable else 0)
 | 
						|
    ctypes.windll.dwmapi.DwmSetWindowAttribute(
 | 
						|
        hwnd,
 | 
						|
        DWMWA_USE_IMMERSIVE_DARK_MODE,
 | 
						|
        ctypes.byref(value),
 | 
						|
        ctypes.sizeof(value)
 | 
						|
    )
 | 
						|
 | 
						|
class ThemeManager(QObject):
 | 
						|
    theme_changed = Signal(str)
 | 
						|
 | 
						|
    def __init__(self):
 | 
						|
        super().__init__()
 | 
						|
        self.settings = QSettings("yobble_messenger", "Theme")
 | 
						|
        self.theme = self.settings.value("theme", "dark")
 | 
						|
 | 
						|
    def get_theme(self):
 | 
						|
        return self.theme
 | 
						|
 | 
						|
    def is_dark(self):
 | 
						|
        return self.theme == "dark"
 | 
						|
 | 
						|
    def set_theme(self, theme: str):
 | 
						|
        if theme in ("dark", "light"):
 | 
						|
            self.theme = theme
 | 
						|
            self.settings.setValue("theme", theme)
 | 
						|
            self.theme_changed.emit(self.theme)
 | 
						|
 | 
						|
    def toggle_theme(self):
 | 
						|
        """Переключает тему между светлой и темной."""
 | 
						|
        new_theme = "light" if self.is_dark() else "dark"
 | 
						|
        self.set_theme(new_theme)
 | 
						|
 | 
						|
# Глобальный экземпляр
 | 
						|
theme_manager = ThemeManager()
 |