feat(ui): refine acrylic task center workspace

This commit is contained in:
阿白叔 committed 2026-10-31 10:03:16 +08:00
1 parent be382a117d
commit 13e0d42472
133 files changed
+3578 -100

No files matched your search

+160
View File
@@ -0,0 +1,160 @@
"""Material policy and fallback must not leave a transparent, unreadable window."""
import sys
import pytest
from PySide6.QtWidgets import QWidget
from dx_productivity.trial_task_center.ui.material import AcrylicController
class Backend:
def __init__(self, allowed=True, succeeds=True):
self.allowed=allowed
self.succeeds=succeeds
self.calls=[]
def available(self):
return self.allowed
def enable(self, hwnd):
self.calls.append(('enable',hwnd))
return self.succeeds
def disable(self, hwnd):
self.calls.append(('disable',hwnd))
def test_disabled_system_policy_never_enables_native_blur(qtbot):
window=QWidget();qtbot.addWidget(window)
backend=Backend(allowed=False)
material=AcrylicController(window,backend=backend)
material.refresh()
assert not window.property('acrylicEnabled')
assert not backend.calls
def test_native_api_rejection_keeps_an_opaque_fallback(qtbot):
window=QWidget();qtbot.addWidget(window)
backend=Backend(succeeds=False)
material=AcrylicController(window,backend=backend)
material.refresh()
assert backend.calls[0][0]=='enable'
assert not window.property('acrylicEnabled')
def test_reducing_transparency_disables_native_composition_and_can_restore(qtbot):
window=QWidget();qtbot.addWidget(window)
backend=Backend()
material=AcrylicController(window,backend=backend)
material.refresh()
assert window.property('acrylicEnabled')
material.set_reduced_transparency(True)
assert not window.property('acrylicEnabled')
assert backend.calls[-1][0]=='disable'
material.set_reduced_transparency(False)
assert window.property('acrylicEnabled')
assert backend.calls[-1][0]=='enable'
def test_transparency_toggle_batches_native_transition_without_intermediate_repaint(qtbot):
window=QWidget();qtbot.addWidget(window)
observed=[]
class ObservingBackend(Backend):
def enable(self, hwnd):
observed.append(('enable',window.updatesEnabled()))
return super().enable(hwnd)
def disable(self, hwnd):
observed.append(('disable',window.updatesEnabled()))
return super().disable(hwnd)
backend=ObservingBackend()
material=AcrylicController(window,backend=backend)
material.refresh()
observed.clear()
material.set_reduced_transparency(True)
assert observed==[('disable',False)]
observed.clear()
material.set_reduced_transparency(False)
assert observed==[('enable',False)]
def test_live_system_policy_change_falls_back_without_touching_business_state(qtbot):
window=QWidget();qtbot.addWidget(window)
window.setProperty('selectedTask','task-a')
backend=Backend()
material=AcrylicController(window,backend=backend)
material.refresh()
backend.allowed=False
material.refresh()
assert not window.property('acrylicEnabled')
assert window.property('selectedTask')=='task-a'
assert backend.calls[-1][0]=='disable'
def test_repeated_refresh_does_not_reconfigure_composition(qtbot):
window=QWidget();qtbot.addWidget(window)
backend=Backend()
material=AcrylicController(window,backend=backend)
material.refresh();material.refresh()
assert len(backend.calls)==1
def test_backend_exception_uses_solid_surface(qtbot):
window=QWidget();qtbot.addWidget(window)
class Broken(Backend):
def enable(self, hwnd):
raise OSError('composition unavailable')
material=AcrylicController(window,backend=Broken())
material.refresh()
assert not window.property('acrylicEnabled')
def test_recreated_native_handle_releases_old_composition(qtbot,monkeypatch):
window=QWidget();qtbot.addWidget(window)
handle=[123]
monkeypatch.setattr(window,'winId',lambda:handle[0])
backend=Backend()
material=AcrylicController(window,backend=backend)
material.refresh()
handle[0]=456
material.refresh()
assert backend.calls==[('enable',123),('disable',123),('enable',456)]
@pytest.mark.skipif(sys.platform!='win32',reason='Windows policy API')
def test_windows_material_respects_transparency_high_contrast_and_remote(monkeypatch):
import winreg
from types import SimpleNamespace
from dx_productivity.trial_task_center.ui import material
class User:
high_contrast=False
remote=False
def SystemParametersInfoW(self,action,size,pointer,flags):
pointer._obj.flags=int(self.high_contrast)
return True
def GetSystemMetrics(self,index):
return int(self.remote)
user=User()
native=material.WindowsAcrylic.__new__(material.WindowsAcrylic)
native._user=user
monkeypatch.setattr(material.sys,'getwindowsversion',lambda:SimpleNamespace(build=26200))
monkeypatch.setattr(material.QGuiApplication,'platformName',lambda:'windows')
monkeypatch.setattr(winreg,'QueryValueEx',lambda *args:(1,winreg.REG_DWORD))
assert native.available()
user.high_contrast=True
assert not native.available()
user.high_contrast=False;user.remote=True
assert not native.available()
user.remote=False
monkeypatch.setattr(winreg,'QueryValueEx',lambda *args:(0,winreg.REG_DWORD))
assert not native.available()
def test_real_window_has_svg_controls_and_persistent_material_preference(ui):
window=ui.window
assert not window.run_panel.quick_run_button.icon().isNull()
assert not window.task_center_navigation.icon().isNull()
assert window.project_summary.parent() is not window.run_panel.parent()
window.reduced_transparency_button.setChecked(True)
assert not window.property('acrylicEnabled')
assert window._layout_settings.value('appearance/reduced_transparency',False,type=bool)
surface=window.grab().toImage().pixelColor(2,window.menuWidget().height()+2)
assert surface.alpha()==255 and surface.blue()>=235
window.mapping_tabs.setCurrentIndex(1)
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
+169
View File
@@ -0,0 +1,169 @@
"""Visible feedback and keyboard actions obey the existing plan gates."""
from PySide6.QtCore import Qt
from PySide6.QtWidgets import QLineEdit
from dx_productivity.trial_task_center.target_plan import ComponentTarget,TargetPlanRow
def seed_plan(ui):
task=ui.tasks[0]
project=ui.store.list_projects(task.task_id)[0].path
rows=tuple(TargetPlanRow(ComponentTarget(project,'MAIN','1',f'polish-{i}',ref,'OLD','100nF'),i==0,'NEW')
for i,ref in enumerate(('RV05','RV11','C103')))
ui.store.record_target_inventory(task.task_id,tuple(row.target for row in rows))
ui.service.replace_target_plan(task.task_id,rows)
ui.open(task);ui.settle()
ui.window.mapping_tabs.setCurrentIndex(1)
return ui.window.plan_panel
def test_search_feedback_and_no_match_state_are_visible(ui):
panel=seed_plan(ui)
panel.find_text.setText('RV');panel.find()
assert panel.find_result.isVisible()
assert '2 / 3'in panel.find_result.text()
assert panel.next_match_action.isEnabled()
panel.find_text.setText('NOT-PRESENT');panel.find()
assert not panel.next_match_action.isEnabled()
assert panel.table.empty_hint.isVisible()
assert '没有匹配'in panel.table.empty_hint.text()
panel.clear_find()
assert not panel.find_result.isVisible()
assert panel.table.rowCount()==3
assert not panel.table.empty_hint.isVisible()
def test_clean_plan_cannot_be_resaved_and_dirty_plan_can(ui):
panel=seed_plan(ui)
assert not panel.save_button.isEnabled()
assert '已保存'in panel.save_state.text()
panel.table.model().setData(panel.table.model().index(0,6),'NEW-EDIT')
assert panel.save_button.isEnabled()
assert '未保存'in panel.save_state.text()
panel.save_shortcut.trigger();ui.settle()
assert not panel.table.dirty
assert not panel.save_button.isEnabled()
assert any(row.new_part_number=='NEW-EDIT'for row in ui.service.target_plan(ui.tasks[0].task_id))
def test_bulk_edit_requires_selected_rows_and_nonempty_input(ui):
panel=seed_plan(ui)
panel.table.clearSelection();panel.bulk_part.setText('BULK')
assert not panel.bulk_apply.isEnabled()
panel.table.selectRow(1)
assert panel.bulk_apply.isEnabled()
assert '1'in panel.bulk_apply.text()
panel.bulk_part.clear()
assert not panel.bulk_apply.isEnabled()
assert all(row.new_part_number=='NEW'for row in panel.table.rows())
def test_keyboard_save_does_not_bypass_readonly_state(ui):
panel=seed_plan(ui)
panel.table.model().setData(panel.table.model().index(0,6),'UNSAVED')
panel.set_plan_editable(False)
panel.save_shortcut.trigger();ui.settle()
assert panel.table.dirty
assert all(row.new_part_number=='NEW'for row in ui.service.target_plan(ui.tasks[0].task_id))
panel.discard_all()
def test_find_shortcut_focuses_existing_search(ui,qtbot):
panel=seed_plan(ui)
panel.find_shortcut.trigger()
assert panel.find_text.hasFocus()
assert panel.find_shortcut.shortcut().toString()=='Ctrl+F'
def test_keyboard_save_commits_current_cell_editor_before_saving(ui,qtbot):
panel=seed_plan(ui)
index=panel.table.model().index(0,6)
panel.table.setCurrentIndex(index);panel.table.setFocus();panel.table.edit(index)
editor=panel.table.findChild(QLineEdit)
assert editor is not None
editor.setText('NEW-TYPED')
assert not panel.table.dirty
panel.save_shortcut.trigger();ui.settle()
assert any(row.new_part_number=='NEW-TYPED'for row in ui.service.target_plan(ui.tasks[0].task_id))
def test_active_cell_enables_save_but_escape_cancels_without_dirtying(ui,qtbot):
panel=seed_plan(ui)
index=panel.table.model().index(0,6)
panel.table.setCurrentIndex(index);panel.table.setFocus();panel.table.edit(index)
editor=panel.table.findChild(QLineEdit)
editor.setText('NOT-COMMITTED')
assert not panel.table.dirty
assert panel.save_button.isEnabled()
assert panel.has_unsaved_plans()
qtbot.keyClick(editor,Qt.Key.Key_Escape);qtbot.wait(20)
assert not panel.table.dirty
assert not panel.save_button.isEnabled()
def test_discard_closes_active_editor_without_committing_it(ui):
panel=seed_plan(ui)
index=panel.table.model().index(0,6)
panel.table.setCurrentIndex(index);panel.table.setFocus();panel.table.edit(index)
panel.table.findChild(QLineEdit).setText('DISCARD-ME')
panel.discard_all()
assert not panel.table.has_pending_editor()
assert not panel.has_unsaved_plans()
assert all(row.new_part_number=='NEW'for row in panel.table.rows())
def test_mouse_save_commits_active_cell_text(ui,qtbot):
panel=seed_plan(ui)
index=panel.table.model().index(0,6)
panel.table.setCurrentIndex(index);panel.table.setFocus();panel.table.edit(index)
panel.table.findChild(QLineEdit).setText('NEW-MOUSE')
qtbot.mouseClick(panel.save_button,Qt.MouseButton.LeftButton);ui.settle()
assert any(row.new_part_number=='NEW-MOUSE'for row in ui.service.target_plan(ui.tasks[0].task_id))
def test_full_project_title_remains_available_when_narrow(ui,qtbot):
title=ui.window.project_summary.name
value='Very long project name with a distinctive suffix '*8
title.setText(value)
ui.window.resize(980,700);qtbot.wait(30)
assert ui.window.width()==980
assert title.text()==value
assert title.toolTip()==value
def test_project_summary_status_does_not_repeat_current_project_scope(ui):
ui.open(ui.tasks[0]); ui.settle()
status=ui.window.project_summary.state.text()
assert not status.startswith('当前工程')
def test_target_table_header_stays_connected_and_supports_horizontal_layout(ui,qtbot):
panel=seed_plan(ui)
table=panel.table
header=table.horizontalHeader()
ui.window.resize(980,700); qtbot.wait(30)
assert header.sectionsMovable()
assert not header.stretchLastSection()
assert table.horizontalScrollMode()==table.ScrollMode.ScrollPerPixel
assert table.horizontalScrollBarPolicy()==Qt.ScrollBarPolicy.ScrollBarAsNeeded
assert table.horizontalScrollBar().maximum()>0
original=header.sectionSize(6)
header.resizeSection(6,original+40)
assert header.sectionSize(6)==original+40
header.moveSection(0,2)
assert header.visualIndex(0)==2
assert table.horizontalHeader().logicalIndex(2)==0
def test_rule_table_header_supports_the_same_horizontal_layout(ui,qtbot):
table=ui.window.mapping_table
ui.window.resize(980,700); qtbot.wait(30)
header=table.horizontalHeader()
assert header.sectionsMovable()
assert not header.stretchLastSection()
assert table.horizontalScrollMode()==table.ScrollMode.ScrollPerPixel
assert table.horizontalScrollBar().maximum()>0
original=header.sectionSize(0)
header.resizeSection(0,original+24)
assert header.sectionSize(0)==original+24
header.moveSection(0,1)
assert header.visualIndex(0)==1
+61
View File
@@ -0,0 +1,61 @@
"""The redesigned chrome keeps real command gates and data surfaces intact."""
from PySide6.QtCore import Qt
from PySide6.QtWidgets import QPushButton,QWidget
def test_menu_commands_follow_live_enabled_and_visible_state(qtbot):
from dx_productivity.trial_task_center.ui.command_menu import CommandMenu
owner=QWidget();qtbot.addWidget(owner)
button=QPushButton('诊断',owner)
called=[];button.clicked.connect(lambda:called.append(True))
menu=CommandMenu(owner)
action=menu.add_button(button)
menu.sync()
assert action.isEnabled()and action.isVisible()
action.trigger();assert called==[True]
button.setEnabled(False);menu.sync()
assert not action.isEnabled()
action.trigger();assert called==[True]
button.setEnabled(True);button.hide();menu.sync()
assert not action.isVisible()
action.trigger();assert called==[True]
def test_task_management_is_a_menu_and_new_task_is_at_the_top(ui):
panel=ui.window.task_list
assert panel.new_button.geometry().top()<panel.search.geometry().top()
assert not panel.edit_button.isVisible()
panel.manage_menu.sync()
assert any(action.text()==panel.edit_button.text()for action in panel.manage_menu.actions())
assert panel.queue_button.isVisible()
assert panel.list.itemDelegate().__class__.__name__=='TaskItemDelegate'
def test_plan_search_shares_toolbar_and_save_is_below_table(ui):
window=ui.window;window.mapping_tabs.setCurrentIndex(1)
plan=window.plan_panel
assert plan.find_text.parent().objectName()=='planToolbar'
assert plan.import_bom_button.parent()is plan.find_text.parent()
assert plan.save_button.geometry().top()>plan.table.geometry().bottom()
assert not plan.find_button.isVisible()
assert plan.find_text.isClearButtonEnabled()
def test_execution_maintenance_menu_keeps_diagnostics_available(ui):
run=ui.window.run_panel
assert run.more_button.isVisible()
assert not run.diagnostics_button.isVisible()
run.more_menu.sync()
diagnostic=next(a for a in run.more_menu.actions()if a.text()==run.diagnostics_button.text())
assert diagnostic.isVisible()and diagnostic.isEnabled()
assert run.quick_run_button.isVisible()
assert run.toggle_log_button.isVisible()
def test_redesign_small_window_keeps_save_and_execute_visible(ui,qtbot):
window=ui.window;window.mapping_tabs.setCurrentIndex(1);window.resize(980,700);qtbot.wait(40)
assert window.width()==980 and window.height()==700
assert window.plan_panel.table.viewport().height()>=100
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()