fix(ui): address PR review controls and material lifecycle
This commit is contained in:
1 parent
a41c6cf928
commit
6f9f820f85
14 files changed
+295
-32
No files matched your search
@@ -1,4 +1,5 @@
|
||||
"""Menu presentation for existing buttons, preserving their live business gates."""
|
||||
from PySide6.QtCore import Qt
|
||||
from PySide6.QtWidgets import QMenu,QWidget
|
||||
|
||||
|
||||
@@ -12,10 +13,15 @@ class CommandMenu(QMenu):
|
||||
self.aboutToShow.connect(self.sync)
|
||||
|
||||
def add_button(self,button):
|
||||
explicitly_hidden = (button.isHidden() and
|
||||
button.testAttribute(Qt.WidgetAttribute.WA_WState_ExplicitShowHide))
|
||||
button.setParent(self.storage)
|
||||
# Only the parent is hidden. Explicit visibility remains the state gate.
|
||||
button.show()
|
||||
# Reparenting hides even new, unshown buttons. Preserve an explicit
|
||||
# business hide, while allowing ordinary newly constructed commands.
|
||||
button.setVisible(not explicitly_hidden)
|
||||
action=self.addAction(button.text())
|
||||
action.setEnabled(button.isEnabled())
|
||||
action.setVisible(not button.isHidden())
|
||||
def invoke():
|
||||
if button.isEnabled() and not button.isHidden():
|
||||
button.click()
|
||||
|
||||
@@ -10,8 +10,10 @@ from ctypes import wintypes
|
||||
import sys
|
||||
|
||||
from PySide6.QtCore import QEvent, QObject, QTimer, Qt
|
||||
from PySide6.QtGui import QColor, QGuiApplication, QPainter
|
||||
from PySide6.QtGui import QColor, QGuiApplication, QPainter, QPalette
|
||||
from PySide6.QtWidgets import QMainWindow
|
||||
from shiboken6 import isValid
|
||||
from .theme import WINDOW_BACKGROUND
|
||||
|
||||
|
||||
class MaterialMainWindow(QMainWindow):
|
||||
@@ -19,7 +21,9 @@ class MaterialMainWindow(QMainWindow):
|
||||
def paintEvent(self, event):
|
||||
if not self.property('acrylicEnabled'):
|
||||
painter = QPainter(self)
|
||||
painter.fillRect(event.rect(), QColor('#edf1f5'))
|
||||
color = (self.palette().color(QPalette.ColorRole.Window)
|
||||
if self.property('highContrastFallback') else QColor(WINDOW_BACKGROUND))
|
||||
painter.fillRect(event.rect(), color)
|
||||
painter.end()
|
||||
super().paintEvent(event)
|
||||
|
||||
@@ -30,6 +34,19 @@ class WindowsAcrylic:
|
||||
if sys.platform == 'win32':
|
||||
self._user = ctypes.WinDLL('user32', use_last_error=True)
|
||||
|
||||
def high_contrast(self) -> bool:
|
||||
if self._user is None:
|
||||
return False
|
||||
class HighContrast(ctypes.Structure):
|
||||
_fields_ = [('size', wintypes.UINT), ('flags', wintypes.DWORD),
|
||||
('scheme', wintypes.LPWSTR)]
|
||||
contrast = HighContrast()
|
||||
contrast.size = ctypes.sizeof(contrast)
|
||||
if not self._user.SystemParametersInfoW(0x0042, contrast.size,
|
||||
ctypes.byref(contrast), 0):
|
||||
raise OSError('Cannot read Windows high-contrast policy')
|
||||
return bool(contrast.flags & 1)
|
||||
|
||||
def available(self) -> bool:
|
||||
if self._user is None or QGuiApplication.platformName() != 'windows':
|
||||
return False
|
||||
@@ -37,15 +54,7 @@ class WindowsAcrylic:
|
||||
return False
|
||||
try:
|
||||
import winreg
|
||||
class HighContrast(ctypes.Structure):
|
||||
_fields_ = [('size', wintypes.UINT), ('flags', wintypes.DWORD),
|
||||
('scheme', wintypes.LPWSTR)]
|
||||
contrast = HighContrast()
|
||||
contrast.size = ctypes.sizeof(contrast)
|
||||
if not self._user.SystemParametersInfoW(0x0042, contrast.size,
|
||||
ctypes.byref(contrast), 0):
|
||||
return False
|
||||
if contrast.flags & 1 or self._user.GetSystemMetrics(0x1000):
|
||||
if self.high_contrast() or self._user.GetSystemMetrics(0x1000):
|
||||
return False
|
||||
try:
|
||||
with winreg.OpenKey(winreg.HKEY_CURRENT_USER,
|
||||
@@ -92,18 +101,20 @@ class AcrylicController(QObject):
|
||||
self._enabled = False
|
||||
self._handle = None
|
||||
self._signature = None
|
||||
self._normal_stylesheet = None
|
||||
window.setProperty('acrylicEnabled', False)
|
||||
window.setProperty('highContrastFallback', False)
|
||||
# Set up an alpha surface before creating HWND; keep the native frame.
|
||||
if QGuiApplication.platformName() == 'windows':
|
||||
window.setAttribute(Qt.WidgetAttribute.WA_TranslucentBackground)
|
||||
window.installEventFilter(self)
|
||||
self._timer = QTimer(self)
|
||||
self._timer.setInterval(2000)
|
||||
self._timer.setInterval(30000)
|
||||
self._timer.timeout.connect(self._poll)
|
||||
self._timer.start()
|
||||
|
||||
def _poll(self):
|
||||
if self.window.isVisible():
|
||||
if isValid(self.window) and self.window.isVisible():
|
||||
self.refresh()
|
||||
|
||||
def set_reduced_transparency(self, reduced: bool):
|
||||
@@ -113,18 +124,31 @@ class AcrylicController(QObject):
|
||||
def _surface(self, enabled, *, repaint=True):
|
||||
self._enabled = bool(enabled)
|
||||
self.window.setProperty('acrylicEnabled', bool(enabled))
|
||||
# Dynamic ancestor selectors affect chrome children as well as the root.
|
||||
self.window.setStyleSheet(self.window.styleSheet())
|
||||
# Named/focused controls override generic palette selectors. Removing
|
||||
# the custom sheet lets Qt honor the system palette for every control.
|
||||
if self.window.property('highContrastFallback'):
|
||||
if self._normal_stylesheet is None:
|
||||
self._normal_stylesheet = self.window.styleSheet()
|
||||
self.window.setStyleSheet('')
|
||||
else:
|
||||
stylesheet = (self._normal_stylesheet if self._normal_stylesheet is not None
|
||||
else self.window.styleSheet())
|
||||
self._normal_stylesheet = None
|
||||
self.window.setStyleSheet(stylesheet)
|
||||
if repaint:
|
||||
self.window.update()
|
||||
|
||||
def refresh(self):
|
||||
if not isValid(self) or not isValid(self.window):
|
||||
return
|
||||
try:
|
||||
allowed = not self.reduced and self.backend.available()
|
||||
high_contrast = bool(getattr(self.backend, 'high_contrast', lambda: False)())
|
||||
allowed = not self.reduced and not high_contrast and self.backend.available()
|
||||
except (OSError, AttributeError):
|
||||
high_contrast = True # An unreadable policy must keep a solid surface.
|
||||
allowed = False
|
||||
handle = int(self.window.winId()) if allowed else self._handle
|
||||
signature = (handle, allowed)
|
||||
signature = (handle, allowed, high_contrast)
|
||||
if signature == self._signature:
|
||||
return
|
||||
self._signature = signature
|
||||
@@ -134,6 +158,8 @@ class AcrylicController(QObject):
|
||||
updates_enabled = self.window.updatesEnabled()
|
||||
self.window.setUpdatesEnabled(False)
|
||||
try:
|
||||
contrast_changed = self.window.property('highContrastFallback') != high_contrast
|
||||
self.window.setProperty('highContrastFallback', high_contrast)
|
||||
if self._enabled:
|
||||
# Paint opaque before removing native blur; avoids an unreadable alpha surface.
|
||||
self._surface(False, repaint=False)
|
||||
@@ -143,6 +169,8 @@ class AcrylicController(QObject):
|
||||
pass
|
||||
self._handle = handle
|
||||
if not allowed:
|
||||
if contrast_changed:
|
||||
self._surface(False, repaint=False)
|
||||
return
|
||||
try:
|
||||
enabled = self.backend.enable(handle)
|
||||
@@ -161,6 +189,6 @@ class AcrylicController(QObject):
|
||||
|
||||
def eventFilter(self, watched, event):
|
||||
if event.type() in (QEvent.Type.Show, QEvent.Type.WinIdChange,
|
||||
QEvent.Type.WindowActivate):
|
||||
QTimer.singleShot(0, self.refresh)
|
||||
QEvent.Type.WindowActivate, QEvent.Type.ApplicationPaletteChange):
|
||||
QTimer.singleShot(0, self, self.refresh)
|
||||
return super().eventFilter(watched, event)
|
||||
@@ -49,11 +49,9 @@ class RunPanel(QWidget):
|
||||
self.more_menu=CommandMenu(self)
|
||||
for button in (self.diagnostics_button,self.cleanup_resources_button,self.history_button,self.reset_layout_button):
|
||||
self.more_menu.add_button(button)
|
||||
self.more_menu.addSeparator()
|
||||
self.more_menu.add_button(self.force_stop_button)
|
||||
self.more_button=QToolButton(objectName='executionMoreMenu')
|
||||
self.more_button.setText('更多操作')
|
||||
self.more_button.setToolTip('诊断、轮次证据、布局与异常操作')
|
||||
self.more_button.setToolTip('诊断、资源清理、轮次证据与布局')
|
||||
self.more_button.setIcon(icon('more'))
|
||||
self.more_button.setMenu(self.more_menu)
|
||||
self.more_button.setPopupMode(QToolButton.ToolButtonPopupMode.InstantPopup)
|
||||
@@ -65,7 +63,7 @@ class RunPanel(QWidget):
|
||||
heading.addWidget(self.more_button)
|
||||
buttons=QHBoxLayout()
|
||||
buttons.addWidget(self.operator_band,1)
|
||||
for button in (self.retry_button,self.recover_button,self.new_round_button,self.stop_queue_button,self.quick_run_button):
|
||||
for button in (self.retry_button,self.recover_button,self.new_round_button,self.stop_queue_button,self.force_stop_button,self.quick_run_button):
|
||||
buttons.addWidget(button)
|
||||
layout = QVBoxLayout(self)
|
||||
layout.setContentsMargins(12,8,12,9)
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
"""Frosted window chrome and opaque, readable engineering data surfaces."""
|
||||
from .theme import WINDOW_BACKGROUND
|
||||
|
||||
APP_STYLESHEET = """
|
||||
QWidget { background: transparent; color: #344359; font-family: "Segoe UI", "Microsoft YaHei UI"; font-size: 13px; }
|
||||
QMainWindow { background: #edf1f5; }
|
||||
QMainWindow { background: @WINDOW_BACKGROUND@; }
|
||||
QMainWindow[acrylicEnabled="true"] { background: transparent; }
|
||||
QDialog, QMessageBox, QMenu { background: #f8fafc; }
|
||||
QToolTip { background: #ffffff; color: #344359; border: 1px solid #ccd6e2; padding: 5px; }
|
||||
@@ -108,4 +109,4 @@ QTableView { outline: none; }
|
||||
QTableView::item:selected { background: #e6eef8; color: #294969; }
|
||||
QTableView::item:focus { border: 1px solid #9bb3d0; }
|
||||
QToolButton[appearance="quiet"]:checked { background: rgba(255,255,255,155); border-color: rgba(255,255,255,220); color: #3f638e; }
|
||||
"""
|
||||
""".replace('@WINDOW_BACKGROUND@', WINDOW_BACKGROUND)
|
||||
@@ -7,7 +7,7 @@ import re
|
||||
from typing import Iterable
|
||||
|
||||
from PySide6.QtCore import Qt, QSignalBlocker, Signal, QSize, QRect
|
||||
from PySide6.QtGui import QColor,QFont,QIcon
|
||||
from PySide6.QtGui import QColor,QFont,QIcon,QPalette
|
||||
from PySide6.QtWidgets import (QComboBox,QHBoxLayout,QLabel,QLineEdit,QListWidget,
|
||||
QListWidgetItem,QPushButton,QVBoxLayout,QWidget,QToolButton,QMenu,
|
||||
QStyledItemDelegate,QStyleOptionViewItem,QStyle,QApplication)
|
||||
@@ -34,19 +34,23 @@ class TaskItemDelegate(QStyledItemDelegate):
|
||||
style=option.widget.style()if option.widget else QApplication.style()
|
||||
style.drawControl(QStyle.ControlElement.CE_ItemViewItem,opt,painter,option.widget)
|
||||
painter.save()
|
||||
high_contrast=bool(option.widget and option.widget.window().property('highContrastFallback'))
|
||||
system_text=opt.palette.color(QPalette.ColorRole.HighlightedText
|
||||
if option.state&QStyle.StateFlag.State_Selected else QPalette.ColorRole.Text)
|
||||
rect=option.rect.adjusted(12,11,-12,-10)
|
||||
picture.paint(painter,QRect(rect.left(),rect.top()+7,20,20))
|
||||
left=rect.left()+31;available=rect.right()-left-(24 if order else 0)
|
||||
font=QFont(option.font);font.setWeight(QFont.Weight.DemiBold);painter.setFont(font)
|
||||
painter.setPen(QColor('#35577d')if option.state&QStyle.StateFlag.State_Selected else QColor('#526983'))
|
||||
painter.setPen(system_text if high_contrast else
|
||||
QColor('#35577d')if option.state&QStyle.StateFlag.State_Selected else QColor('#526983'))
|
||||
label=painter.fontMetrics().elidedText(name,Qt.TextElideMode.ElideRight,available)
|
||||
painter.drawText(QRect(left,rect.top(),available,23),Qt.AlignmentFlag.AlignVCenter,label)
|
||||
font.setWeight(QFont.Weight.Normal);font.setPointSizeF(max(8,option.font.pointSizeF()-1));painter.setFont(font)
|
||||
colors={'执行中':'#8a744d','失败':'#a15f59','已完成':'#638775','待执行':'#6b8ba8'}
|
||||
painter.setPen(QColor(colors.get(status,'#8999ac')))
|
||||
painter.setPen(system_text if high_contrast else QColor(colors.get(status,'#8999ac')))
|
||||
painter.drawText(QRect(left,rect.top()+27,available,19),Qt.AlignmentFlag.AlignVCenter,status)
|
||||
if order:
|
||||
painter.setPen(QColor('#94a4b8'))
|
||||
painter.setPen(system_text if high_contrast else QColor('#94a4b8'))
|
||||
painter.drawText(QRect(rect.right()-20,rect.top()+2,20,19),Qt.AlignmentFlag.AlignRight,order)
|
||||
painter.restore()
|
||||
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
"""Shared colors for Qt styling and native-window fallback painting."""
|
||||
|
||||
WINDOW_BACKGROUND = '#edf1f5'
|
||||
Reference in new issue
Block a user