feat: follow connected DX minimize and restore state
This commit is contained in:
1 parent
b51bcb0b3e
commit
f3b027b494
10 files changed
+475
-2
No files matched your search
@@ -0,0 +1,153 @@
|
||||
import json
|
||||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
from PySide6.QtCore import QTimer
|
||||
from PySide6.QtWidgets import QLineEdit, QWidget
|
||||
|
||||
from dx_productivity.ui.main_window import MainWindow
|
||||
|
||||
|
||||
@pytest.mark.parametrize('expanded', (False, True))
|
||||
def test_host_minimize_hides_both_windows_and_restores_previous_panel(qtbot, tmp_path, expanded):
|
||||
window = MainWindow(layout_path=tmp_path / 'layout.json')
|
||||
qtbot.addWidget(window)
|
||||
page = QLineEdit('unfinished input')
|
||||
window.set_page(1, page, '属性批改')
|
||||
window.show_panel(1) if expanded else window.show_toolbar()
|
||||
ticks = []
|
||||
timer = QTimer(window)
|
||||
timer.timeout.connect(lambda: ticks.append(1))
|
||||
timer.start(10)
|
||||
|
||||
window.set_host_minimized(True)
|
||||
assert not window.toolbar.isVisible() and not window.isVisible()
|
||||
qtbot.waitUntil(lambda: len(ticks) >= 2)
|
||||
window.set_host_minimized(True)
|
||||
window.set_host_minimized(False)
|
||||
assert window.toolbar.isVisible()
|
||||
assert window.isVisible() is expanded
|
||||
assert page.text() == 'unfinished input'
|
||||
if expanded:
|
||||
assert window.pages.currentIndex() == 1
|
||||
|
||||
|
||||
def test_initial_minimized_host_defers_requested_page_until_restore(qtbot, tmp_path):
|
||||
window = MainWindow(layout_path=tmp_path / 'layout.json')
|
||||
qtbot.addWidget(window)
|
||||
window.set_host_minimized(True)
|
||||
window.show_panel(7)
|
||||
window.show_toolbar()
|
||||
assert not window.isVisible() and not window.toolbar.isVisible()
|
||||
window.set_host_minimized(False)
|
||||
assert window.isVisible() and window.toolbar.isVisible()
|
||||
assert window.pages.currentIndex() == 7
|
||||
|
||||
|
||||
def test_collapse_during_host_minimize_remains_collapsed_after_restore(qtbot, tmp_path):
|
||||
window = MainWindow(layout_path=tmp_path / 'layout.json')
|
||||
qtbot.addWidget(window)
|
||||
window.show_panel(0)
|
||||
window.set_host_minimized(True)
|
||||
window.hide_panel()
|
||||
assert not window.toolbar.isVisible()
|
||||
window.set_host_minimized(False)
|
||||
assert window.toolbar.isVisible() and not window.isVisible()
|
||||
|
||||
|
||||
def test_host_restore_does_not_activate_feature_panel(qtbot, qapp, tmp_path):
|
||||
if qapp.platformName() == 'offscreen':
|
||||
pytest.skip('Offscreen activates every shown window; focus requires the native window backend')
|
||||
window = MainWindow(layout_path=tmp_path / 'layout.json')
|
||||
qtbot.addWidget(window)
|
||||
window.show_panel(0)
|
||||
window.set_host_minimized(True)
|
||||
host = QWidget()
|
||||
qtbot.addWidget(host)
|
||||
host.show()
|
||||
host.activateWindow()
|
||||
qapp.processEvents()
|
||||
active = qapp.activeWindow()
|
||||
window.set_host_minimized(False)
|
||||
qapp.processEvents()
|
||||
assert window.isVisible() and qapp.activeWindow() is active
|
||||
|
||||
|
||||
def test_explicit_exit_while_host_minimized_cannot_restore_windows(qtbot, tmp_path):
|
||||
window = MainWindow(layout_path=tmp_path / 'layout.json')
|
||||
qtbot.addWidget(window)
|
||||
window.show_panel(0)
|
||||
window.set_host_minimized(True)
|
||||
window.request_exit()
|
||||
window.set_host_minimized(False)
|
||||
assert not window.isVisible() and not window.toolbar.isVisible()
|
||||
|
||||
|
||||
def test_host_minimize_closes_more_popup(qtbot, qapp, tmp_path):
|
||||
window = MainWindow(layout_path=tmp_path / 'layout.json')
|
||||
qtbot.addWidget(window)
|
||||
window.show_toolbar()
|
||||
window.toolbar.more_menu.popup(window.toolbar.more_button.mapToGlobal(window.toolbar.more_button.rect().bottomLeft()))
|
||||
qapp.processEvents()
|
||||
assert window.toolbar.more_menu.isVisible()
|
||||
window.set_host_minimized(True)
|
||||
assert not window.toolbar.more_menu.isVisible()
|
||||
assert not window.toolbar.isVisible()
|
||||
|
||||
|
||||
class FakeHostWindows:
|
||||
def __init__(self):
|
||||
self.minimized = {100: False, 200: False}
|
||||
|
||||
def resolve(self, view_handle):
|
||||
return view_handle if view_handle in self.minimized else None
|
||||
|
||||
def is_minimized(self, handle):
|
||||
return self.minimized.get(handle)
|
||||
|
||||
|
||||
def test_watcher_follows_exact_bridge_host_even_during_transaction(qtbot, tmp_path):
|
||||
from dx_productivity.ui.host_window_watcher import HostWindowWatcher
|
||||
|
||||
window = MainWindow(layout_path=tmp_path / 'layout.json')
|
||||
qtbot.addWidget(window)
|
||||
window.refdes_controller = SimpleNamespace(snapshot=SimpleNamespace(run_id='run-1', design_path='C:/demo.prj'), _apply_in_flight=True)
|
||||
request = tmp_path / 'request.json'
|
||||
request.write_text(json.dumps({'run_id': 'run-1', 'design_path': 'C:/demo.prj', 'host_view_handle': 100}), encoding='utf-8')
|
||||
backend = FakeHostWindows()
|
||||
watcher = HostWindowWatcher(window, request, backend=backend)
|
||||
window.show_panel(0)
|
||||
|
||||
backend.minimized[200] = True
|
||||
watcher._check()
|
||||
assert window.toolbar.isVisible() and window.isVisible()
|
||||
backend.minimized[100] = True
|
||||
watcher._check()
|
||||
assert not window.toolbar.isVisible() and not window.isVisible()
|
||||
backend.minimized[100] = False
|
||||
watcher._check()
|
||||
assert window.toolbar.isVisible() and window.isVisible()
|
||||
window.request_exit()
|
||||
assert not watcher.timer.isActive()
|
||||
|
||||
|
||||
def test_watcher_can_bind_later_from_selection_without_using_foreign_run(qtbot, tmp_path):
|
||||
from dx_productivity.ui.host_window_watcher import HostWindowWatcher
|
||||
|
||||
window = MainWindow(layout_path=tmp_path / 'layout.json')
|
||||
qtbot.addWidget(window)
|
||||
window.refdes_controller = SimpleNamespace(snapshot=SimpleNamespace(run_id='run-1', design_path='C:/demo.prj'))
|
||||
request = tmp_path / 'request.json'
|
||||
request.write_text(json.dumps({'run_id': 'run-1', 'design_path': 'C:/demo.prj', 'host_view_handle': 0}), encoding='utf-8')
|
||||
backend = FakeHostWindows()
|
||||
backend.minimized[100] = True
|
||||
watcher = HostWindowWatcher(window, request, backend=backend)
|
||||
window.show_toolbar()
|
||||
selection = tmp_path / 'selection.json'
|
||||
for run_id, design_path in (('other-run', 'C:/demo.prj'), ('run-1', 'C:/other.prj')):
|
||||
selection.write_text(json.dumps({'run_id': run_id, 'design_path': design_path, 'host_view_handle': 100}), encoding='utf-8')
|
||||
watcher._check()
|
||||
assert window.toolbar.isVisible()
|
||||
selection.write_text(json.dumps({'run_id': 'run-1', 'design_path': 'C:/demo.prj', 'host_view_handle': 100}), encoding='utf-8')
|
||||
watcher._check()
|
||||
assert not window.toolbar.isVisible()
|
||||
Reference in new issue
Block a user