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
@@ -93,6 +93,19 @@ def test_repeated_refresh_does_not_reconfigure_composition(qtbot):
|
||||
assert len(backend.calls)==1
|
||||
|
||||
|
||||
def test_deferred_material_refresh_never_uses_a_destroyed_window(qtbot,qapp):
|
||||
from PySide6.QtCore import QCoreApplication,QEvent
|
||||
window=QWidget() # This test owns destruction rather than pytest-qt teardown.
|
||||
backend=Backend()
|
||||
controller=AcrylicController(window,backend=backend)
|
||||
controller.eventFilter(window,QEvent(QEvent.Type.WindowActivate))
|
||||
window.deleteLater()
|
||||
QCoreApplication.sendPostedEvents(None,QEvent.Type.DeferredDelete)
|
||||
controller.refresh()
|
||||
qapp.processEvents()
|
||||
assert not backend.calls
|
||||
|
||||
|
||||
def test_backend_exception_uses_solid_surface(qtbot):
|
||||
window=QWidget();qtbot.addWidget(window)
|
||||
class Broken(Backend):
|
||||
@@ -158,3 +171,72 @@ def test_real_window_has_svg_controls_and_persistent_material_preference(ui):
|
||||
image=window.plan_panel.table.viewport().grab().toImage()
|
||||
color=image.pixelColor(image.width()-8,image.height()-8)
|
||||
assert color.alpha()==255 and min(color.red(),color.green(),color.blue())>=245
|
||||
|
||||
|
||||
@pytest.mark.parametrize('reduced',[False,True])
|
||||
def test_high_contrast_fallback_uses_window_palette_and_tracks_policy_change(qtbot,qapp,request,reduced):
|
||||
from PySide6.QtGui import QColor,QPalette
|
||||
from PySide6.QtWidgets import QLabel,QLineEdit
|
||||
from dx_productivity.trial_task_center.ui.material import MaterialMainWindow
|
||||
from dx_productivity.trial_task_center.ui.styles import APP_STYLESHEET
|
||||
original_palette=qapp.palette()
|
||||
request.addfinalizer(lambda:qapp.setPalette(original_palette))
|
||||
palette=QPalette(original_palette)
|
||||
palette.setColor(QPalette.ColorRole.Window,QColor('#181818'))
|
||||
palette.setColor(QPalette.ColorRole.WindowText,QColor('#fafafa'))
|
||||
palette.setColor(QPalette.ColorRole.Base,QColor('#181818'))
|
||||
palette.setColor(QPalette.ColorRole.Text,QColor('#fafafa'))
|
||||
qapp.setPalette(palette)
|
||||
window=MaterialMainWindow();qtbot.addWidget(window)
|
||||
window.setStyleSheet(APP_STYLESHEET)
|
||||
search=QLineEdit('Readable query',window,objectName='taskSearch')
|
||||
search.setGeometry(30,30,180,30)
|
||||
title=QLabel('Project name',window,objectName='projectTitle')
|
||||
class ContrastBackend(Backend):
|
||||
contrast=True
|
||||
def high_contrast(self):return self.contrast
|
||||
def available(self):return not self.contrast
|
||||
backend=ContrastBackend()
|
||||
controller=AcrylicController(window,backend=backend)
|
||||
controller.set_reduced_transparency(reduced)
|
||||
controller.refresh()
|
||||
window.resize(240,160);window.show()
|
||||
assert window.property('highContrastFallback')
|
||||
assert not window.property('acrylicEnabled')
|
||||
color=window.grab().toImage().pixelColor(10,10)
|
||||
assert color==QColor('#181818')
|
||||
search.setFocus()
|
||||
assert search.palette().color(QPalette.ColorRole.Base)==QColor('#181818')
|
||||
assert search.palette().color(QPalette.ColorRole.Text)==QColor('#fafafa')
|
||||
assert title.palette().color(QPalette.ColorRole.WindowText)==QColor('#fafafa')
|
||||
backend.contrast=False
|
||||
controller.refresh()
|
||||
assert not window.property('highContrastFallback')
|
||||
assert window.property('acrylicEnabled') is not reduced
|
||||
assert window.styleSheet()==APP_STYLESHEET
|
||||
|
||||
|
||||
@pytest.mark.parametrize('selected',[False,True])
|
||||
def test_high_contrast_task_titles_render_with_system_text_colors(qtbot,selected):
|
||||
from PySide6.QtCore import QRect,Qt
|
||||
from PySide6.QtGui import QColor,QImage,QPainter,QPalette,QStandardItem,QStandardItemModel
|
||||
from PySide6.QtWidgets import QListWidget,QStyle,QStyleOptionViewItem
|
||||
from dx_productivity.trial_task_center.ui.task_list import TaskItemDelegate
|
||||
window=QWidget();qtbot.addWidget(window)
|
||||
window.setProperty('highContrastFallback',True)
|
||||
listing=QListWidget(window)
|
||||
model=QStandardItemModel();model.appendRow(QStandardItem('01. Board Name\nReady'))
|
||||
option=QStyleOptionViewItem();option.widget=listing
|
||||
option.rect=QRect(0,0,220,76);option.font=listing.font()
|
||||
option.state=QStyle.StateFlag.State_Enabled
|
||||
palette=QPalette(listing.palette())
|
||||
palette.setColor(QPalette.ColorRole.Text,QColor('#ffff00'))
|
||||
palette.setColor(QPalette.ColorRole.HighlightedText,QColor('#00ff00'))
|
||||
option.palette=palette
|
||||
if selected:option.state|=QStyle.StateFlag.State_Selected
|
||||
picture=QImage(220,76,QImage.Format.Format_ARGB32);picture.fill(QColor('#000000'))
|
||||
painter=QPainter(picture)
|
||||
TaskItemDelegate(listing).paint(painter,option,model.index(0,0));painter.end()
|
||||
expected=QColor('#00ff00'if selected else'#ffff00')
|
||||
# Check actual painted title glyphs, not only the widget's palette property.
|
||||
assert sum(picture.pixelColor(x,y)==expected for x in range(43,190)for y in range(11,34))>5
|
||||
Reference in new issue
Block a user