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
|
||||
@@ -59,3 +59,41 @@ def test_redesign_small_window_keeps_save_and_execute_visible(ui,qtbot):
|
||||
for button in [window.plan_panel.save_button,window.run_panel.quick_run_button,window.task_list.new_button]:
|
||||
rect=button.rect();point=button.mapTo(window,rect.bottomRight())
|
||||
assert point.x()<window.width()and point.y()<window.height()
|
||||
|
||||
|
||||
def test_menu_keeps_command_hidden_before_registration(qtbot):
|
||||
from dx_productivity.trial_task_center.ui.command_menu import CommandMenu
|
||||
owner=QWidget();qtbot.addWidget(owner)
|
||||
button=QPushButton('Hidden command',owner)
|
||||
button.hide()
|
||||
called=[];button.clicked.connect(lambda:called.append(True))
|
||||
menu=CommandMenu(owner)
|
||||
action=menu.add_button(button)
|
||||
assert button.isHidden()
|
||||
assert not action.isVisible()
|
||||
menu.sync();action.trigger()
|
||||
assert not called
|
||||
button.show();menu.sync();action.trigger()
|
||||
assert action.isVisible() and called==[True]
|
||||
|
||||
|
||||
def test_force_stop_is_directly_visible_during_execution_at_minimum_size(ui,qtbot):
|
||||
window=ui.window
|
||||
window._begin_run(ui.tasks[0].task_id)
|
||||
window._update_gates()
|
||||
try:
|
||||
window.resize(980,700);qtbot.wait(30)
|
||||
run=window.run_panel
|
||||
assert run.force_stop_button.parent() is run
|
||||
assert run.force_stop_button.isVisible()
|
||||
assert run.force_stop_button.isEnabled()
|
||||
assert run.stop_queue_button.isVisible()
|
||||
for button in (run.force_stop_button,run.stop_queue_button):
|
||||
point=button.mapTo(window,button.rect().bottomRight())
|
||||
assert 0<=point.x()<window.width() and 0<=point.y()<window.height()
|
||||
window._pause_queue()
|
||||
assert run.force_stop_button.isVisible() and run.force_stop_button.isEnabled()
|
||||
finally:
|
||||
window._finish_run()
|
||||
window._update_gates()
|
||||
assert not window.run_panel.force_stop_button.isVisible()
|
||||
Reference in new issue
Block a user