zapret-kvn/xray_fluent/ui/fluent_dialog.py
loop-uh a7cf61a05e
All checks were successful
Windows project source guards / test (push) Successful in 36s
Prepare v0.4.79: unified theming, responsive layout, real flags
- Single source of truth for theme: theme.py tokens, FluentDialog base
  for all dialogs, setCustomStyleSheet migration, theme applied before
  window creation, SystemThemeListener for auto mode
- Responsive layout: ScrollablePage base with as-needed horizontal
  scrolling, word wrap on dashboard labels, adaptive dashboard grid,
  realistic 860x560 window minimum
- Real country flags (flagcdn PNG set) with themed border and fallback
- Active server row marked by accent stripe only (no synthesized bold)
- Subscription polish from parallel work (QR utils, http, diagnostics)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-11 23:21:28 +03:00

44 lines
1.7 KiB
Python

"""Base dialog that participates in the qfluentwidgets theme mechanism.
Plain ``QDialog`` subclasses get the OS default backdrop, which breaks the
half-transparent fluent QSS in dark mode and leaves ``QPalette`` roles
(``PlaceholderText``/``Text``) out of sync with the theme. ``FluentDialog``
paints its surface from the :mod:`theme` tokens and re-applies everything on
``qconfig.themeChanged``.
"""
from __future__ import annotations
from PyQt6.QtGui import QPalette
from PyQt6.QtWidgets import QDialog, QWidget
from qfluentwidgets import qconfig
from .theme import placeholder_text_color, surface_color, text_color
class FluentDialog(QDialog):
"""QDialog with a fluent surface that follows theme changes."""
def __init__(self, parent: QWidget | None = None):
super().__init__(parent)
self._apply_dialog_theme()
# Bound-method connection: Qt disconnects automatically on destroy.
qconfig.themeChanged.connect(self._on_fluent_theme_changed)
def _on_fluent_theme_changed(self) -> None:
self._apply_dialog_theme()
def _apply_dialog_theme(self) -> None:
surface = surface_color()
# The leaf class name matches the QSS class selector, keeping the
# background scoped to this dialog (children keep fluent styling).
selector = type(self).__name__
self.setStyleSheet(f"{selector} {{ background-color: {surface.name()}; }}")
palette = self.palette()
text = text_color()
palette.setColor(QPalette.ColorRole.Window, surface)
palette.setColor(QPalette.ColorRole.WindowText, text)
palette.setColor(QPalette.ColorRole.Text, text)
palette.setColor(QPalette.ColorRole.PlaceholderText, placeholder_text_color())
self.setPalette(palette)