From 136c6e9fada48e409707f58269859b0537c9d03b Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 26 Sep 2025 21:35:18 +0300 Subject: [PATCH] fix white theme --- app/core/dialogs.py | 72 ++++++++++++++++++++++++++++++++ app/core/theme.py | 13 ++++++ app/ui/views/login_view.py | 11 ++--- app/ui/views/yobble_home_view.py | 39 +++++++++++++---- main.py | 63 ++++++++++++++++++++++++++-- 5 files changed, 180 insertions(+), 18 deletions(-) create mode 100644 app/core/dialogs.py diff --git a/app/core/dialogs.py b/app/core/dialogs.py new file mode 100644 index 0000000..44a599e --- /dev/null +++ b/app/core/dialogs.py @@ -0,0 +1,72 @@ +from PySide6.QtWidgets import QMessageBox +from .theme import theme_manager, set_dark_title_bar + +def show_themed_messagebox(parent, icon, title, text, buttons=QMessageBox.Ok): + msg = QMessageBox(parent) + msg.setIcon(icon) + msg.setWindowTitle(title) + msg.setText(text) + msg.setStandardButtons(buttons) + + if theme_manager.is_dark(): + msg.setStyleSheet(""" + QMessageBox { + background-color: #2e2e2e; + color: white; + border: none; + outline: none; + } + QMessageBox QLabel { + color: white; + border: none; + outline: none; + } + QMessageBox QPushButton { + background-color: #444; + color: white; + border: none; + outline: none; + border-radius: 6px; + padding: 6px 12px; + } + QMessageBox QPushButton:hover { + background-color: #666; + } + """) + else: + msg.setStyleSheet(""" + QMessageBox { + background-color: white; + color: black; + border: none; + outline: none; + } + QMessageBox QLabel { + color: black; + border: none; + outline: none; + background: transparent; + } + QMessageBox QPushButton { + background-color: #e0e0e0; + color: black; + border: none; + outline: none; + border-radius: 6px; + padding: 6px 12px; + } + QMessageBox QPushButton:focus, + QMessageBox QPushButton:pressed { + border: none; + outline: none; + } + QMessageBox QPushButton:hover { + background-color: #d0d0d0; + } + """) + + + hwnd = int(msg.winId()) + set_dark_title_bar(hwnd, theme_manager.is_dark()) + + return msg.exec() diff --git a/app/core/theme.py b/app/core/theme.py index f71b75a..c2286cc 100644 --- a/app/core/theme.py +++ b/app/core/theme.py @@ -1,4 +1,17 @@ +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) diff --git a/app/ui/views/login_view.py b/app/ui/views/login_view.py index fe06420..433a4c9 100644 --- a/app/ui/views/login_view.py +++ b/app/ui/views/login_view.py @@ -13,6 +13,7 @@ from app.core.theme import theme_manager import app.core.config as config import asyncio from app.core.services import auth_service +from app.core.dialogs import show_themed_messagebox def validate_username(username, is_login=False): @@ -259,7 +260,7 @@ class LoginView(QWidget): if not is_login_valid or not is_password_valid: # Показываем первую попавшуюся ошибку, они должны быть общими error_msg = login_msg if not is_login_valid else password_msg - QMessageBox.warning(self, localizer.translate("Ошибка"), error_msg) + show_themed_messagebox(self, QMessageBox.Warning, localizer.translate("Ошибка"), error_msg) return # Отключаем кнопку на время запроса @@ -273,7 +274,7 @@ class LoginView(QWidget): if success: self.on_login(login) else: - QMessageBox.warning(self, localizer.translate("Ошибка"), message) + show_themed_messagebox(self, QMessageBox.Warning, localizer.translate("Ошибка"), message) finally: # Включаем кнопку обратно в любом случае @@ -304,7 +305,7 @@ class LoginView(QWidget): self.confirm_password_input.is_valid, self.invite_code_input.is_valid ]): - QMessageBox.warning(self, localizer.translate("Ошибка"), localizer.translate("Пожалуйста, исправьте ошибки в форме")) + show_themed_messagebox(self, QMessageBox.Warning, localizer.translate("Ошибка"), "Пожалуйста, исправьте ошибки в форме") return login = self.reg_login_input.text() @@ -319,10 +320,10 @@ class LoginView(QWidget): success, message = await auth_service.register(login, password, invite) if success: - QMessageBox.information(self, localizer.translate("Успех"), message) + show_themed_messagebox(self, QMessageBox.Information, localizer.translate("Успех"), message) self.show_login_form() else: - QMessageBox.warning(self, localizer.translate("Ошибка"), message) + show_themed_messagebox(self, QMessageBox.Warning, localizer.translate("Ошибка"), message) finally: # Возвращаем кнопку в исходное состояние diff --git a/app/ui/views/yobble_home_view.py b/app/ui/views/yobble_home_view.py index e492975..d946b10 100644 --- a/app/ui/views/yobble_home_view.py +++ b/app/ui/views/yobble_home_view.py @@ -1,13 +1,14 @@ import asyncio from PySide6.QtWidgets import ( QWidget, QVBoxLayout, QHBoxLayout, QPushButton, QLabel, QFrame, - QStackedWidget, QSpacerItem, QSizePolicy, QGraphicsDropShadowEffect, + QStackedWidget, QSizePolicy, QGraphicsDropShadowEffect, QGraphicsOpacityEffect, QMessageBox ) -from PySide6.QtCore import Qt, QSize, QPropertyAnimation, QEasingCurve, Property -from PySide6.QtGui import QIcon, QColor +from PySide6.QtCore import Qt, QPropertyAnimation, QEasingCurve +from PySide6.QtGui import QColor from app.core.theme import theme_manager +from app.core.dialogs import show_themed_messagebox from app.ui.views.side_menu_view import SideMenuView from app.core.services.auth_service import get_user_role from app.core.database import get_current_access_token @@ -161,12 +162,14 @@ class YobbleHomeView(QWidget): self.search_button.setFocusPolicy(Qt.NoFocus) self.search_button.setCursor(Qt.PointingHandCursor) top_bar_layout.addWidget(self.search_button) + self.search_button.clicked.connect(self.handle_search_click) self.notification_button = QPushButton("🔔") self.notification_button.setObjectName("NotificationButton") self.notification_button.setFocusPolicy(Qt.NoFocus) self.notification_button.setCursor(Qt.PointingHandCursor) top_bar_layout.addWidget(self.notification_button) + self.notification_button.clicked.connect(self.handle_notification_click) return top_bar_widget @@ -328,12 +331,12 @@ class YobbleHomeView(QWidget): def show_error_message(self, message): """Показывает диалоговое окно с сообщением об ошибке.""" - msg_box = QMessageBox(self) - msg_box.setIcon(QMessageBox.Warning) - msg_box.setText(message) - msg_box.setWindowTitle(localizer.translate("Ошибка доступа")) - msg_box.setStandardButtons(QMessageBox.Ok) - msg_box.exec() + show_themed_messagebox( + self, + QMessageBox.Warning, + localizer.translate("Ошибка доступа"), + message + ) def update_tab_selection(self, selected_index): if not hasattr(self, 'bottom_bar'): @@ -366,6 +369,24 @@ class YobbleHomeView(QWidget): self.music_label = denied self.content_stack.insertWidget(1, denied) + def handle_search_click(self): + """Пустышка для кнопки поиска.""" + show_themed_messagebox( + self, + QMessageBox.Information, + "Поиск", + "🔍 Функция поиска пока в разработке." + ) + + def handle_notification_click(self): + """Пустышка для кнопки уведомлений.""" + show_themed_messagebox( + self, + QMessageBox.Information, + "Уведомления", + "🔔 Центр уведомлений пока в разработке." + ) + def get_stylesheet(self): """Возвращает QSS стили для компонента в зависимости от темы.""" is_dark = theme_manager.is_dark() diff --git a/main.py b/main.py index d7130f6..05a9448 100644 --- a/main.py +++ b/main.py @@ -1,11 +1,11 @@ import asyncio +import sys +import qasync from PySide6.QtWidgets import QApplication, QMainWindow from PySide6.QtGui import QIcon from app.controllers.main_controller import MainController -from app.core.theme import theme_manager +from app.core.theme import theme_manager, set_dark_title_bar import app.core.config as config -import sys -import qasync from app.core.database import init_db class MainWindow(QMainWindow): @@ -21,11 +21,66 @@ class MainWindow(QMainWindow): self.apply_theme(theme_manager.get_theme()) def apply_theme(self, theme): - if theme == "dark": + is_dark = theme == "dark" + if is_dark: self.setStyleSheet("background-color: #2e2e2e;") else: self.setStyleSheet("background-color: #f0f0f0;") + # if is_dark: + # self.setStyleSheet(""" + # QMainWindow { + # background-color: #2e2e2e; + # } + # QMessageBox { + # background-color: #2e2e2e; + # color: white; + # } + # QMessageBox QLabel { + # color: white; + # font-size: 14px; + # } + # QMessageBox QPushButton { + # background-color: #3c3c3c; + # color: white; + # border-radius: 6px; + # padding: 5px 12px; + # } + # QMessageBox QPushButton:hover { + # background-color: #505050; + # } + # """) + # else: + # self.setStyleSheet(""" + # QMainWindow { + # background-color: #f0f0f0; + # } + # QMessageBox { + # background-color: #ffffff; + # color: black; + # } + # QMessageBox QLabel { + # color: black; + # font-size: 14px; + # } + # QMessageBox QPushButton { + # background-color: #e0e0e0; + # color: black; + # border-radius: 6px; + # padding: 5px 12px; + # } + # QMessageBox QPushButton:hover { + # background-color: #d0d0d0; + # } + # """) + + # получаем HWND и красим системный бар + hwnd = int(self.winId()) + try: + set_dark_title_bar(hwnd, is_dark) + except Exception as e: + print("Не удалось поменять цвет системного бара:", e) + async def main(): init_db() app = QApplication(sys.argv)