fix: preserve live selection validity and preferred panel geometry
This commit is contained in:
1 parent
9caf33df38
commit
d6df3f99fb
8 files changed
+268
-15
No files matched your search
@@ -143,3 +143,71 @@ def test_saved_offscreen_position_and_bottom_anchor_are_clamped(qtbot, monkeypat
|
||||
window.show_panel(0)
|
||||
assert bounds.contains(window.frameGeometry())
|
||||
assert window.frameGeometry().bottom() < window.toolbar.frameGeometry().top()
|
||||
|
||||
|
||||
def test_screen_clamp_preserves_preferred_sizes_through_hide_switch_and_restore(qtbot, monkeypatch, tmp_path):
|
||||
from types import SimpleNamespace
|
||||
from PySide6.QtCore import QRect, QSize
|
||||
from PySide6.QtWidgets import QApplication
|
||||
from dx_productivity.ui.main_window import MainWindow
|
||||
bounds = [QRect(0, 0, 1800, 1000)]
|
||||
screen = SimpleNamespace(availableGeometry=lambda: bounds[0], name=lambda: 'test-monitor')
|
||||
monkeypatch.setattr(QApplication, 'screenAt', lambda _point: screen)
|
||||
window = MainWindow(layout_path=tmp_path / 'ui-layout.json')
|
||||
qtbot.addWidget(window)
|
||||
window.show_panel(0)
|
||||
window.resize(1000, 700)
|
||||
assert window.layout_preferences.page_sizes[0] == QSize(1000, 700)
|
||||
bounds[0] = QRect(0, 0, 800, 600)
|
||||
window._screens_changed()
|
||||
assert window.width() < 1000 and window.height() < 700
|
||||
window.hide_panel()
|
||||
assert window.layout_preferences.page_sizes[0] == QSize(1000, 700)
|
||||
from dx_productivity.ui.layout_preferences import LayoutPreferences
|
||||
assert LayoutPreferences(window.layout_preferences.path).page_sizes[0] == QSize(1000, 700)
|
||||
window.show_panel(7)
|
||||
window.show_panel(0)
|
||||
assert window.layout_preferences.page_sizes[0] == QSize(1000, 700)
|
||||
bounds[0] = QRect(0, 0, 1800, 1000)
|
||||
window._screens_changed()
|
||||
assert window.size() == QSize(1000, 700)
|
||||
window.resize(900, 650)
|
||||
window.hide_panel()
|
||||
assert window.layout_preferences.page_sizes[0] == QSize(900, 650)
|
||||
|
||||
|
||||
def test_extremely_narrow_toolbar_keeps_children_in_bounds_and_routes_accessible(qtbot, monkeypatch, tmp_path):
|
||||
from dx_productivity.ui.main_window import MainWindow
|
||||
from PySide6.QtWidgets import QAbstractButton
|
||||
window = MainWindow(layout_path=tmp_path / 'ui-layout.json')
|
||||
qtbot.addWidget(window)
|
||||
window.show_toolbar()
|
||||
toolbar = window.toolbar
|
||||
for width in (340, 240, 180, 120, 96):
|
||||
toolbar.fit_available_width(width)
|
||||
toolbar.layout().activate()
|
||||
assert toolbar.width() <= width and toolbar.height() == 44
|
||||
for child in toolbar.findChildren(QAbstractButton):
|
||||
if child.isVisibleTo(toolbar):
|
||||
assert toolbar.rect().contains(child.geometry()), (width, child.accessibleName(), child.geometry())
|
||||
visible = [toolbar.layout().itemAt(i).widget() for i in range(toolbar.layout().count())
|
||||
if not toolbar.layout().itemAt(i).widget().isHidden()]
|
||||
for left, right in zip(visible, visible[1:]):
|
||||
assert left.geometry().right() < right.geometry().left(), (width, left.geometry(), right.geometry())
|
||||
assert toolbar.start_button.isVisible() and toolbar.page_buttons[7].isVisible()
|
||||
assert toolbar.more_button.isVisible()
|
||||
for index in range(window.pages.count()):
|
||||
assert index in toolbar.page_buttons and toolbar.page_buttons[index].isVisible() or toolbar.page_actions[index].isVisible()
|
||||
with qtbot.waitSignal(toolbar.page_requested) as received:
|
||||
toolbar.page_actions[0].trigger()
|
||||
assert received.args == [0]
|
||||
for width in (80, 48, 34):
|
||||
toolbar.fit_available_width(width)
|
||||
for child in toolbar.findChildren(QAbstractButton):
|
||||
if child.isVisibleTo(toolbar):
|
||||
assert toolbar.rect().contains(child.geometry())
|
||||
assert toolbar.more_button.isVisible()
|
||||
assert toolbar.start_action.isVisible() or toolbar.start_button.isVisible()
|
||||
assert toolbar.page_actions[7].isVisible() or toolbar.page_buttons[7].isVisible()
|
||||
with qtbot.waitSignal(toolbar.start_requested):
|
||||
toolbar.start_action.trigger()
|
||||
@@ -33,7 +33,15 @@ def test_status_setters_update_hidden_toolbar_without_showing_panel(qtbot, tmp_p
|
||||
window.set_bridge_status('桥接已连接')
|
||||
window.set_selection_status('已选 C18', '当前页:ROOT / 1\n选中器件:C18')
|
||||
assert 'C18' in window.toolbar.status_label.text()
|
||||
assert 'C18' in window.toolbar.status_label.accessibleName()
|
||||
assert 'ROOT / 1' in window.toolbar.status_label.toolTip()
|
||||
from PySide6.QtGui import QAccessible
|
||||
long_reference = 'C18_' + 'LONG_REFERENCE_' * 15
|
||||
window.set_selection_status('已选 ' + long_reference, '选中器件:' + long_reference)
|
||||
label = window.toolbar.status_label
|
||||
assert long_reference not in label.text()
|
||||
assert long_reference in QAccessible.queryAccessibleInterface(label).text(QAccessible.Text.Name)
|
||||
assert long_reference in label.accessibleDescription()
|
||||
window.set_operation_status('PDF 导出中')
|
||||
assert 'PDF 导出中' in window.toolbar.status_label.text()
|
||||
assert 'C18' in window.toolbar.status_label.toolTip()
|
||||
@@ -80,3 +88,49 @@ def test_toolbar_clamps_negative_monitor_coordinates(qtbot, tmp_path, monkeypatc
|
||||
window.toolbar.move_within_screen(QPoint(-1600, -300), screen)
|
||||
assert window.toolbar.pos() == bounds.topLeft()
|
||||
assert bounds.contains(window.toolbar.frameGeometry())
|
||||
|
||||
|
||||
def test_advanced_section_title_fits_natural_button_geometry(qtbot, qapp):
|
||||
from dx_productivity.ui.app import create_application
|
||||
from dx_productivity.ui.collapsible_section import CollapsibleSection
|
||||
from dx_productivity.ui.theme import apply_theme, Theme
|
||||
create_application([])
|
||||
section = CollapsibleSection('高级 PDF 导出与兼容选项')
|
||||
qtbot.addWidget(section)
|
||||
section.resize(350, 80)
|
||||
section.show()
|
||||
for theme in (Theme.LIGHT, Theme.DARK):
|
||||
apply_theme(qapp, theme)
|
||||
qapp.processEvents()
|
||||
button = section.toggle_button
|
||||
assert button.width() >= button.fontMetrics().horizontalAdvance(button.text()) + 14
|
||||
assert button.height() >= 28
|
||||
assert section.rect().contains(button.geometry())
|
||||
assert button.text() == '高级 PDF 导出与兼容选项'
|
||||
assert button.arrowType() == Qt.ArrowType.RightArrow
|
||||
section.set_expanded(True)
|
||||
assert button.arrowType() == Qt.ArrowType.DownArrow
|
||||
section.set_expanded(False)
|
||||
|
||||
|
||||
def test_compact_page_check_and_radio_hit_targets_fit(qtbot, qapp):
|
||||
from PySide6.QtWidgets import QCheckBox, QRadioButton, QAbstractButton
|
||||
from dx_productivity.ui.app import create_application
|
||||
from dx_productivity.ui.pdf_export_page import PdfExportPage
|
||||
from dx_productivity.ui.settings_page import SettingsPage
|
||||
from dx_productivity.ui.bom_page import BomPage
|
||||
from dx_productivity.ui.theme import apply_theme, Theme
|
||||
create_application([])
|
||||
apply_theme(qapp, Theme.LIGHT)
|
||||
for page, width, height in ((PdfExportPage(), 660, 390), (SettingsPage(current_version='0.1.0'), 660, 390), (BomPage(), 780, 480)):
|
||||
qtbot.addWidget(page)
|
||||
page.resize(width, height)
|
||||
page.show()
|
||||
qapp.processEvents()
|
||||
assert page.width() <= width and page.height() <= height
|
||||
targets = [child for child in page.findChildren(QAbstractButton)
|
||||
if isinstance(child, (QCheckBox, QRadioButton)) and child.isVisibleTo(page)]
|
||||
assert targets
|
||||
for child in targets:
|
||||
assert child.height() >= 28, (type(page).__name__, child.text(), child.geometry())
|
||||
assert page.rect().contains(child.mapTo(page, child.rect().bottomRight()))
|
||||
@@ -1,4 +1,5 @@
|
||||
import json
|
||||
import pytest
|
||||
from pathlib import Path
|
||||
|
||||
from dx_productivity.ui.app import create_main_window
|
||||
@@ -140,3 +141,32 @@ def test_repeated_panel_toggle_keeps_single_watcher_and_page_instances(qtbot, fi
|
||||
assert tuple(window.selection_watcher.findChildren(QTimer)) == timers
|
||||
assert len(window.findChildren(SelectionWatcher)) == 1
|
||||
assert window.property_change_controller.page.model.item(0, 0).text() == 'C1'
|
||||
|
||||
|
||||
@pytest.mark.parametrize('content', [None, '{malformed', '[]', '{"state":"ready"}'])
|
||||
def test_initial_unavailable_selection_waits_then_pauses_and_recovers(qtbot, fixture_path, tmp_path, monkeypatch, content):
|
||||
from dx_productivity.ui import selection_watcher as watcher_module
|
||||
now = [100.0]
|
||||
monkeypatch.setattr(watcher_module.time, 'monotonic', lambda: now[0])
|
||||
if content is not None:
|
||||
(tmp_path / 'selection.json').write_text(content, encoding='utf-8')
|
||||
window, data = setup_window(qtbot, fixture_path, tmp_path, monkeypatch)
|
||||
window.show_toolbar()
|
||||
original = window.refdes_controller.snapshot
|
||||
assert '等待' in window.selection_status.text()
|
||||
assert window.bridge_status.text() != '桥接已连接'
|
||||
assert '已选' not in window.toolbar.status_label.text()
|
||||
now[0] += 10
|
||||
window.selection_watcher._check()
|
||||
assert '暂停' in window.selection_status.text()
|
||||
assert window.refdes_controller.snapshot is original
|
||||
publish(tmp_path, data, ['uid:uid-c-a'])
|
||||
window.selection_watcher._check()
|
||||
assert window.bridge_status.text() == '桥接已连接'
|
||||
assert 'C1' in window.toolbar.status_label.text()
|
||||
payload = json.loads((tmp_path / 'selection.json').read_text(encoding='utf-8'))
|
||||
payload['selected_keys'] = 12
|
||||
(tmp_path / 'selection.json').write_text(json.dumps(payload), encoding='utf-8')
|
||||
window.selection_watcher._check()
|
||||
assert '暂停' in window.selection_status.text()
|
||||
assert 'C1' not in window.toolbar.status_label.text()
|
||||
Reference in new issue
Block a user