19 changed files with 789 additions and 12 deletions

No files matched your search

@@ -0,0 +1,42 @@
# 关闭 DX 自动退出工具验收(2026-10-13)
## 问题与修复
此前宿主监听器在所属 DX 窗口失效时仅忽略本次检查,工具继续运行。本次在已绑定的宿主窗口失效后调用统一退出入口,关闭工具栏和面板、停止定时器及各控制器,并结束 Qt 事件循环。DX 最小化仍只隐藏工具,恢复时还原此前的页面状态。
绑定沿用桥接 run ID、工程路径和原生视图的顶层 HWND/PID,不按前台窗口或进程名称选择宿主。Start 菜单注册进行中时,统一退出入口暂缓关闭;监听器继续运行,注册结束后重试退出。未绑定 DX 的独立工具维持手动退出方式。
## 自动检查
| 检查 | 结果 | 证据 |
|---|---|---|
| 修改前所属宿主消失 | 1 failed,工具未进入退出状态 | `build/test-evidence/host-close-red.xml` |
| 初次修复后宿主监听 | 9 passed,1 skipped | `build/test-evidence/host-close-green.xml` |
| 最终窗口回归 | 24 passed,1 skipped | `build/test-evidence/host-close-ui-final.xml` |
| 最终便携包 | 16 passed | `build/test-evidence/host-close-packaged-final.xml` |
窗口回归覆盖面板展开、收起、DX 最小化的四种组合,以及关闭另一宿主不退出、注册结束后重试。offscreen 跳过的是原生焦点保留用例;此前 Windows 后端结果见 `host-visibility-acceptance-20261012.md`。最终包检查包含九页入口、中文空格路径和 ZIP 校验。
更新发布说明后的一次便携包复查在复制中文路径用例时遇到 C 盘 `WinError 112`(磁盘空间不足),结果为 15 passed、1 failed;记录保留在 `build/test-evidence/host-close-packaged-disk-full.xml`。最终复查通过 `--basetemp` 使用 F 盘的独立目录,未修改产品实现。
## 实机关闭
使用独立副本 `%LOCALAPPDATA%/DxProductivity/acceptance/native-20261010/1GPHY_RTL8211F/1GPHY_RTL8211F.prj`,进入 `GE_PHY_8211` 原理图页,由持久化菜单打开最终包。
- DX PID:28712,主窗口 HWND:6628030。
- 工具 PID:67600,工具栏 HWND:1838946,面板 HWND:1249096。
- DX 最初已最小化,两处工具窗口均隐藏。恢复 DX 后工具栏显示,随后展开面板。
- 验收程序核对 DX 主窗口 PID 和工程路径后,仅向该主窗口发送 `WM_CLOSE`,未向工具发送退出指令。
- 3.047 秒内 DX 和工具进程均退出,工具栏与面板窗口均销毁。
- 工程 `.prj` 和 `sch` 目录文件的 SHA-256 在操作前后一致。
原始记录:`%LOCALAPPDATA%/DxProductivity/acceptance/host-close-20261013/before-close.json` 和 `host-close.json`。本轮实机覆盖面板展开状态;收起、隐藏和其他宿主隔离由自动回归覆盖。
## 发布包
- 目录:`release/一叶知秋_重构版_横向工具栏版`。
- ZIP:`release/一叶知秋_重构版_横向工具栏版_Win11_x64.zip`。
- ZIP SHA-256:`76a3990b4dc0d341cd502fd2c6915afb847df3f50176cdc12073b000a8a01361`。
- EXE SHA-256:`0adaeea27bd2e7a23c7840e47b76b210d12f6e3e1decb54695e00e03f4e6e352`。
此记录仅说明宿主关闭联动及相关窗口行为,不代替业务模块验收。
@@ -0,0 +1,45 @@
# 跟随 DX 最小化验收(2026-10-12)
工具现在跟随所连接的 DxDesigner 窗口。DX 最小化时隐藏工具栏、面板和打开的更多菜单;DX 恢复时还原此前的展开或收起状态,保留页面与表单输入。隐藏只改变可见性,后台定时器及桥接会话继续运行。
## 实现与范围
原生快照和轻量选择状态增加可选的 `host_view_handle`。UI 验证其桥接 run ID 和工程路径,通过 Win32 GA_ROOTOWNER 找到所属 DX 顶层窗口,并保存 HWND/PID。独立 150 ms 监听器读取 IsIconic,不依赖选择变化或事务完成。切页后原视图关闭也不影响已缓存的顶层绑定;句柄或 PID 失效时不读取其他窗口。
初始 DX 已最小化时,工具延后显示。若此时还没有创建原生窗口句柄,也按隐藏处理。恢复采用 WA_ShowWithoutActivating,不走显式用户点击入口的激活路径;退出时停止监听器。无桥接的独立启动或没有宿主标识的旧桥接文件维持独立工具栏行为,后续匹配的选择状态可补全宿主绑定。
## 自动检查
| 检查 | 结果 | 记录 |
|---|---|---|
| 新行为修改前 | 8 项因行为或监听器缺失而失败 | `build/test-evidence/host-visibility-red.xml` |
| 最小化与恢复、初始隐藏、输入保留、后台定时器、退出、弹出菜单、所属宿主和延后绑定 | 8 passed;1 项焦点检查在 offscreen 跳过 | `build/test-evidence/host-visibility-green.xml` |
| 相关窗口、更新退出、选择、协议及原生 VBS 回归 | 68 passed;同一 offscreen 焦点检查跳过 | `build/test-evidence/host-visibility-targeted.xml` |
| 原生 Windows 焦点检查 | 1 passed,恢复后另一测试窗口保持活动 | `build/test-evidence/host-native-focus.xml` |
| VBScript 请求与选择的宿主标识 | cscript 断言通过,含标识不可用时的零值 | `tests/vbs/test_refdes_export.vbs` |
| 最终便携包 | 16 passed,包含九页入口、中文路径、运行库和 ZIP 校验 | `build/test-evidence/host-visibility-packaged.xml` |
| 独立代码审查 | 无剩余可操作 P1/P2 | `build/test-evidence/host-visibility-review.md` |
offscreen 平台会激活每个显示的窗口,不能用于验证原生焦点,因此该项单独在 Windows 后端执行。上表的检查集有重叠,不将数量相加。
## 最终包实机
独立工程为 `%LOCALAPPDATA%/DxProductivity/acceptance/native-20261010/1GPHY_RTL8211F/1GPHY_RTL8211F.prj`,DX PID 57584、主 HWND 9051710。由更新后的原生菜单打开最终 EXE PID 86508,其视图 HWND 593196 正确解析为该主窗口。
- DX 初始已最小化,启动后工具保持隐藏;恢复 DX 后工具栏和自动位号面板显示,桥接已连接。
- 面板展开时两轮最小化/恢复,工具栏与面板同步隐藏,恢复仍展开。
- 面板收起时两轮最小化/恢复,工具栏隐藏,恢复仅显示工具栏。
- 每轮隐藏期间 `apply-progress.json` 时间继续更新,DX 没有被后台桥接还原;恢复后前台 PID 均未变为工具 PID。
- 最终恢复用户原本的 DX 最小化状态,工具随之隐藏;未写回器件。
证据:`%LOCALAPPDATA%/DxProductivity/acceptance/host-visibility-20261012/host-native.json`,同目录含恢复后的工具栏及面板截图。循环脚本为 `tools/acceptance/host_visibility.py`。
本轮实机使用一个 DX;第二宿主隔离由模拟窗口后端覆盖。尝试强制设置 DX 前台时,Windows 的前台限制拒绝了验收辅助程序,最终用例验证工具恢复后不占用前台;原生 Qt 焦点检查另验证活动窗口保留。
## 发布
- 包目录:`release/一叶知秋_重构版_横向工具栏版`。
- ZIP SHA-256:`5d9bb051690eba512bd1017fee4e2afa8a35f85cd817f709d433fb8990debb55`。
- EXE SHA-256:`d1af32fca413de8a9e857d093c5843414598ab779bcb6e2b805e67d795dae9d6`。
业务功能全量验收见 `toolbar-acceptance-20261011.md`。本次未解决 PON 全工程快照阻塞,亦未测量长会话原生集合保留的内存增长。
@@ -0,0 +1,25 @@
# “更多”按钮重叠修复验收(2026-10-12)
原按钮继承全局 QToolButton 的 30 像素内容宽度,实际外宽 32 像素;“更多”文字宽 26 像素,菜单指示器还占 12 像素,因此无法并排显示。此前仅修正展开/收起按钮,遗漏了此菜单按钮。
修复使用独立样式和 60 逻辑像素按钮,显式下箭头与文字由 Qt 并排布局,隐藏重复的自动菜单指示器。极窄屏进入箭头菜单模式,恢复可用宽度后重新显示“更多”。InstantPopup 及原有菜单动作保持原路由。
## 验证
- 回归断言在修改前失败:实际 32 像素小于文字、箭头及间距所需的 52 像素。记录:`build/test-evidence/more-button-red.xml`。
- 修复后工具栏、主窗口、窄屏溢出、位置恢复等 33 项通过。记录:`build/test-evidence/more-button-green.xml`。
- 明暗主题在 100%/125%/150% Qt 缩放下渲染;图片:`build/test-evidence/more-button/scale-*.png`。
- 最终便携包 15 项入口/运行库检查通过,另 1 项 ZIP 校验通过。记录:`build/test-evidence/more-button-packaged.xml`、`more-button-manifest.xml`。
- 最终 EXE 在独立 1GPHY 验收工程中由原生菜单打开,桥接已连接。实际 125% DPI 下“更多”外宽 75 物理像素,真实鼠标打开菜单、设置路由及两次主题切换均通过;PrintWindow 截图确认文字和箭头没有重叠。
- 收起后工具栏持续运行,未写回器件。原生记录:`%LOCALAPPDATA%/DxProductivity/acceptance/more-button-20261012/more-native.json`;图片:同目录 `toolbar-final.png`、`toolbar-dark.png`、`more-popup.png`。
拖动和位置恢复的现有测试原先假设固定的 20 像素横坐标;增加菜单宽度后会触及离屏测试显示器的右边界。断言改为验证边界限制后的坐标和实际保存位置,边界处理逻辑未修改。
## 发布包
- 目录:`release/一叶知秋_重构版_横向工具栏版`。
- ZIP:`release/一叶知秋_重构版_横向工具栏版_Win11_x64.zip`。
- ZIP SHA-256:`a35f46113e6693d9b1129d64fb91955c02cdd853d6c1817d7c979a11e494c90c`。
- EXE SHA-256:`2ce88c0df54c2d28f8f7990aa7debbe85a4ab44d2c7d2efdf9c91a30b0a97a25`。
本记录仅验证菜单按钮修复及相关窗口行为;业务功能的完整实机记录见 `toolbar-acceptance-20261011.md`。PON 全工程快照阻塞和长会话集合内存增长未在本次解决。
@@ -0,0 +1,21 @@
# 无活动原理图页错误修复验收(2026-10-13)
## 根因
今天三次菜单启动均在 `snapshot.design` 后报 `131: 集合中找不到对象`。诊断到当时 DxDesigner 处于 `DxDesigner - [Start Page]`,工程路径为空,`ActiveViewHandle=0`。原生 `Application.DesignComponents` 在没有活动原理图页时返回该错误。
## 修复
原生快照在读取器件集合前检查 `ActiveView`;菜单动作在启动桥接前也执行同样检查。无活动视图时显示“请先打开工程并进入原理图页后再使用工具”,并停止当前动作,不创建半成品工具会话。正常工程页仍写出 `host_view_handle` 并连接工具。
## 验证
- 修复前 VBS 回归按预期失败:`DxBridgeHasActiveView` 不存在。记录:`build/test-evidence/no-active-view-red.xml`(由首次 cscript 失败复现)。
- 修复后 VBS 快照/选择回归 5 项通过:`build/test-evidence/no-active-view-vbs.xml`。
- 最终便携包 16 项通过:`build/test-evidence/no-active-view-packaged.xml`。
- 独立 1GPHY 工程页实机启动最终 EXE,桥接已连接、自动位号面板正常:`%LOCALAPPDATA%/DxProductivity/acceptance/no-active-view-20261013`。
- 原生运行时已同步到正式包;更新后的 `MenuAdd.vbs` 已重新生成菜单动作。
- 当前 ZIP SHA-256:`02b06a57415f943797fea33f85ec8682b4c53ab45386251381f6616aebb88dd1`。
- 当前 EXE SHA-256:`cbc6ba0e1ac3abb1459b46d195d2fdd805053283615c43e9f35363a7a717e2ec`。
用户使用时先在 DxDesigner 打开工程并进入任一原理图页,再点击工具菜单。Start Page 场景现在有明确提示,不会再显示 131。
+4 -2
View File
@@ -4,10 +4,12 @@
横向工具栏、九个功能面板及本轮实机验收已完成。正式包已通过真实 Start 注册到 DxDesigner 持久启动菜单,普通重启后自动加载。用户当前宿主 PID 44008 保留,已从其原生菜单打开最终工具并确认桥接已连接;面板收起,仅保留一排工具栏。该宿主的工程没有写回或关闭。
2026-10-12 界面修订:尾部切换入口改为明确的“展开 ▾ / 收起 ▴”文字箭头按钮;展开页改为无标题栏、置顶的紧凑工具卡片。独立验收副本实际打开最终包验证通过,记录见 `%LOCALAPPDATA%/DxProductivity/acceptance/toolbar-20261012-ui-polish`。
- 正式包:`release/一叶知秋_重构版_横向工具栏版`。
- 发布 ZIP:`release/一叶知秋_重构版_横向工具栏版_Win11_x64.zip`。
- ZIP SHA-256:`5ced1cc2a57888898c02eacb9c486a8e14463ddda59ccddc5c7d13f29ea87cd6`。
- EXE SHA-256:`ceb06314529ae805bf03c4409cc741a92e3ee5a40aac56e345031c4cd8af04aa`。
- ZIP SHA-256:`26275747dc28e2937c3dcae0dcd6525e9691d4868c729a5ba92ccbbd3b65adb8`。
- EXE SHA-256:`fbd86ddc9184ca598c1f113886d4d5842bf0d6e7471ca7277ebc0d89b7f9351f`。
- 原生证据根目录:`%LOCALAPPDATA%/DxProductivity/acceptance/toolbar-20261011`。下表原生记录均相对此目录。
写回验收在独立工程副本 `1GPHY_toolbar/1GPHY_RTL8211F.prj` 中进行,全部 114 个器件的值、位置和可见性恢复。初始验收宿主 PID 83848 已正常关闭;普通重启后的验收宿主为 PID 81148。
@@ -4,6 +4,11 @@
- 工具以一排置顶工具栏常驻,提供 Start、位号、属性、显示、检查、网络、BOM 和 PDF;历史、设置、刷新、主题及退出放在“更多”中。
- 点击功能展开对应面板,再点同一功能或“收起面板”收起。面板关闭和最小化也会收起;退出整个工具使用“更多 → 退出工具”。
- 工具栏末尾使用明确的“展开 ▾ / 收起 ▴”按钮;展开内容以无标题栏卡片贴在工具栏下方,不再显示独立应用窗口的标题框。
- 修复“更多”的文字与菜单箭头重叠;正常宽度下两者并排,极窄屏自动保留箭头菜单入口,屏幕恢复后显示文字。
- 工具跟随所属 DxDesigner 窗口:DX 最小化时隐藏工具栏和面板,DX 恢复时还原此前的展开或收起状态,并保留表单输入。隐藏期间选择监听和导出继续运行;恢复工具不会抢走 DX 焦点。
- 关闭所属 DxDesigner 时,工具自动退出,同时关闭工具栏、面板和后台监听;展开、收起或随 DX 隐藏时均生效。关闭其他 DX 窗口不会退出当前工具。
- 如果 DxDesigner 还停在 Start Page、没有打开工程和活动原理图页,菜单动作会直接提示“请先打开工程并进入原理图页后再使用工具”,不再显示原生 131 集合错误。
- 收起后工具栏继续显示选择与任务状态;悬停可查看完整位号、工程、图页和状态信息。拖动左侧手柄移动,位置与各页面大小会保存。
- 页面移除固定左导航、重复标题与说明,操作按钮移到对应页面。低频设置折叠为高级选项,并显示当前有效参数摘要。
- PDF 保留三种范围、输出目录、打开目录和保存后自动导出;配色、文字处理与引擎设置可在高级选项中调整。
@@ -36,9 +36,34 @@ Sub DxToolsRunDesignBridge(featureKey)
Exit Sub
End If
On Error GoTo 0
If Not DxToolsHasActiveView() Then
MsgBox DxToolsNoActiveViewMessage(), vbExclamation
Exit Sub
End If
Call DxToolsDesignBridgeStart(CStr(featureKey))
End Sub
Function DxToolsHasActiveView()
Dim view
DxToolsHasActiveView = False
On Error Resume Next
Set view = ActiveView
If Err.Number = 0 And Not view Is Nothing Then
DxToolsHasActiveView = True
End If
Err.Clear
On Error GoTo 0
End Function
Function DxToolsNoActiveViewMessage()
DxToolsNoActiveViewMessage = ChrW(&H8BF7) & ChrW(&H5148) & _
ChrW(&H6253) & ChrW(&H5F00) & ChrW(&H5DE5) & ChrW(&H7A0B) & _
ChrW(&H5E76) & ChrW(&H8FDB) & ChrW(&H5165) & ChrW(&H539F) & _
ChrW(&H7406) & ChrW(&H56FE) & ChrW(&H9875) & ChrW(&H540E) & _
ChrW(&H518D) & ChrW(&H4F7F) & ChrW(&H7528) & ChrW(&H5DE5) & _
ChrW(&H5177)
End Function
Function DxToolsPathErrorMessage()
DxToolsPathErrorMessage = ChrW(&H65E0) & ChrW(&H6CD5) & _
ChrW(&H786E) & ChrW(&H5B9A) & ChrW(&H5DE5) & ChrW(&H5177) & _
+5 -2
View File
@@ -126,7 +126,9 @@ Sub DxBridgePublishSelection(runRoot, runId, snapshotId, _
ByRef lastSelection, ByRef pageContext, ByRef pageKeys)
Dim designPath, blockName, sheetName, currentContext, selectedKeys
Dim text, numberJson, ready, newPageKeys
Dim hostViewHandleJson
On Error Resume Next
hostViewHandleJson = DxBridgeHostViewHandleJson()
designPath = DxBridgeDesignPath()
blockName = DxBridgeCurrentBlockName()
sheetName = DxBridgeCurrentSheetName()
@@ -151,12 +153,13 @@ Sub DxBridgePublishSelection(runRoot, runId, snapshotId, _
text = "{""state"":""unavailable"",""run_id"":""" & _
DxToolsJson(runId) & """,""snapshot_id"":""" & _
DxToolsJson(snapshotId) & """,""design_path"":""" & _
DxToolsJson(designPath) & """}"
DxToolsJson(designPath) & """,""host_view_handle"":" & hostViewHandleJson & "}"
If ready Then
text = "{""state"":""ready"",""run_id"":""" & _
DxToolsJson(runId) & """,""snapshot_id"":""" & _
DxToolsJson(snapshotId) & """,""design_path"":""" & _
DxToolsJson(designPath) & """,""active_block_name"":""" & _
DxToolsJson(designPath) & """,""host_view_handle"":" & hostViewHandleJson & _
",""active_block_name"":""" & _
DxToolsJson(blockName) & """,""current_sheet_name"":""" & _
DxToolsJson(sheetName) & """,""current_sheet_number"":" & _
numberJson & ",""selected_keys"":" & selectedKeys & _
@@ -51,6 +51,10 @@ Function DxRefreshSnapshot(runRoot, runId, objectMap, originalMap, _
Dim currentSheetNumberJson
DxRefreshSnapshot = False
If Not DxBridgeHasActiveView() Then
Call DxBridgeExportFailed(DxBridgeNoActiveViewMessage())
Exit Function
End If
Set selectedKeys = CreateObject("Scripting.Dictionary")
On Error Resume Next
For Each selected In ActiveView.Query(VDM_COMP, VD_SELECTED)
@@ -154,6 +158,7 @@ Function DxRefreshSnapshot(runRoot, runId, objectMap, originalMap, _
" ""snapshot_id"": """ & DxToolsJson(snapshotId) & """," & vbCrLf & _
" ""design_id"": """ & DxToolsJson(designId) & """," & vbCrLf & _
" ""design_path"": """ & DxToolsJson(designPath) & """," & vbCrLf & _
" ""host_view_handle"": " & DxBridgeHostViewHandleJson() & "," & vbCrLf & _
" ""active_block_name"": """ & _
DxToolsJson(activeBlockName) & """," & vbCrLf & _
" ""current_sheet_number"": " & currentSheetNumberJson & "," & vbCrLf & _
@@ -168,6 +173,29 @@ Function DxRefreshSnapshot(runRoot, runId, objectMap, originalMap, _
DxRefreshSnapshot = True
End Function
Function DxBridgeHostViewHandleJson()
Dim handle
handle = 0
On Error Resume Next
handle = CLng(Application.ActiveViewHandle)
If Err.Number <> 0 Then handle = 0
Err.Clear
On Error GoTo 0
DxBridgeHostViewHandleJson = CStr(handle)
End Function
Function DxBridgeHasActiveView()
Dim view
DxBridgeHasActiveView = False
On Error Resume Next
Set view = ActiveView
If Err.Number = 0 And Not view Is Nothing Then
DxBridgeHasActiveView = True
End If
Err.Clear
On Error GoTo 0
End Function
Function DxBridgeExportAttributes(component)
Dim attribute
Dim text
@@ -575,6 +603,15 @@ Function DxBridgeProjectUnavailableMessage()
ChrW(&H5DE5) & ChrW(&H7A0B)
End Function
Function DxBridgeNoActiveViewMessage()
DxBridgeNoActiveViewMessage = ChrW(&H8BF7) & ChrW(&H5148) & _
ChrW(&H6253) & ChrW(&H5F00) & ChrW(&H5DE5) & ChrW(&H7A0B) & _
ChrW(&H5E76) & ChrW(&H8FDB) & ChrW(&H5165) & ChrW(&H539F) & _
ChrW(&H7406) & ChrW(&H56FE) & ChrW(&H9875) & ChrW(&H540E) & _
ChrW(&H518D) & ChrW(&H4F7F) & ChrW(&H7528) & ChrW(&H5DE5) & _
ChrW(&H5177)
End Function
Function DxBridgeIdentityUnavailableMessage()
DxBridgeIdentityUnavailableMessage = ChrW(&H67D0) & ChrW(&H5668) & _
ChrW(&H4EF6) & ChrW(&H8EAB) & ChrW(&H4EFD) & ChrW(&H4E0D) & _
+2
View File
@@ -24,6 +24,7 @@ from dx_productivity.ui.bom_controller import BomController
from dx_productivity.ui.bom_page import BomPage
from dx_productivity.ui.main_window import MainWindow
from dx_productivity.ui.selection_watcher import SelectionWatcher
from dx_productivity.ui.host_window_watcher import HostWindowWatcher
from dx_productivity.ui.startup_controller import StartupController
from dx_productivity.ui.property_change_controller import PropertyChangeController
from dx_productivity.ui.property_change_page import PropertyChangePage
@@ -321,6 +322,7 @@ def create_main_window(request_path: Path | None = None) -> MainWindow:
if watcher is not None:
watcher.snapshot_reloaded.connect(pdf_export_controller.load_snapshot)
window.selection_watcher = SelectionWatcher(window, request_path)
window.host_window_watcher = HostWindowWatcher(window, request_path)
window.set_active_page(0)
startup_controller = StartupController(_tool_root(), window)
window.startup_controller = startup_controller
+13 -4
View File
@@ -94,7 +94,10 @@ class FloatingToolbar(QWidget):
self.status_label.setAccessibleName('当前桥接、选择与任务状态')
layout.addWidget(self.status_label)
self.more_button = QToolButton()
self.more_button.setObjectName('toolbarMore')
self.more_button.setText('更多')
self.more_button.setToolButtonStyle(Qt.ToolButtonStyle.ToolButtonTextBesideIcon)
self.more_button.setArrowType(Qt.ArrowType.DownArrow)
self.more_button.setAccessibleName('更多')
self.more_button.setToolTip('更多功能与应用操作')
self.more_button.setPopupMode(QToolButton.ToolButtonPopupMode.InstantPopup)
@@ -124,8 +127,10 @@ class FloatingToolbar(QWidget):
action.triggered.connect(signal)
setattr(self, attribute, action)
layout.addWidget(self.more_button)
self.toggle_button = QPushButton()
self.toggle_button.setFixedWidth(32)
self.toggle_button = QToolButton()
self.toggle_button.setObjectName('panelToggle')
self.toggle_button.setToolButtonStyle(Qt.ToolButtonStyle.ToolButtonTextBesideIcon)
self.toggle_button.setFixedWidth(66)
self.toggle_button.clicked.connect(self.toggle_panel_requested)
layout.addWidget(self.toggle_button)
self.set_panel_state(0, False)
@@ -136,8 +141,9 @@ class FloatingToolbar(QWidget):
button.setChecked(i == index and visible)
for i, action in self.page_actions.items():
action.setChecked(i == index and visible)
self.toggle_button.setIcon(themed_icon('fa6s.chevron-up' if visible else 'fa6s.chevron-down', self._theme))
name = '收起面板' if visible else '展开面板'
self.toggle_button.setText('收起' if visible else '展开')
self.toggle_button.setArrowType(Qt.ArrowType.UpArrow if visible else Qt.ArrowType.DownArrow)
self.toggle_button.setAccessibleName(name)
self.toggle_button.setToolTip(name)
self.toggle_action.setText(name)
@@ -159,6 +165,8 @@ class FloatingToolbar(QWidget):
layout = self.layout()
layout.setContentsMargins(5, 4, 5, 4)
layout.setSpacing(4)
self.more_button.setText('更多')
self.more_button.setFixedWidth(60)
self.drag_handle.show()
self.drag_handle.setFixedWidth(20)
self.start_button.show()
@@ -189,6 +197,8 @@ class FloatingToolbar(QWidget):
# in priority order. Start and PDF stay direct until the last stage.
layout.setContentsMargins(2, 4, 2, 4)
layout.setSpacing(2)
self.more_button.setText('')
self.more_button.setFixedWidth(28)
self.drag_handle.setFixedWidth(12)
self.start_button.setText('')
self.start_button.setFixedWidth(28)
@@ -238,7 +248,6 @@ class FloatingToolbar(QWidget):
def refresh_theme(self, theme):
self._theme = theme
self.drag_handle.setPixmap(themed_icon('fa6s.grip-vertical', theme).pixmap(14, 20))
self.toggle_button.setIcon(themed_icon('fa6s.chevron-up' if self.toggle_button.accessibleName() == '收起面板' else 'fa6s.chevron-down', theme))
self.start_button.setIcon(themed_icon('fa6s.play', theme))
for index, button in self.page_buttons.items():
button.setIcon(themed_icon(NAVIGATION[index][1], theme))
@@ -0,0 +1,95 @@
"""Follow only the native DxDesigner window that owns this bridge session."""
from __future__ import annotations
from dataclasses import dataclass
import json
import os
from pathlib import Path
from PySide6.QtCore import QObject, QTimer
@dataclass(frozen=True)
class HostWindow:
handle: int
pid: int
class WindowsHostWindows:
def resolve(self, view_handle: int) -> HostWindow | None:
if os.name != 'nt':
return None
import win32gui
import win32process
try:
# The 32-bit host can publish a signed HWND value.
view_handle &= 0xFFFFFFFF
if not win32gui.IsWindow(view_handle):
return None
handle = win32gui.GetAncestor(view_handle, 3) # GA_ROOTOWNER
if not handle or not win32gui.GetWindowText(handle).startswith('DxDesigner'):
return None
return HostWindow(handle, win32process.GetWindowThreadProcessId(handle)[1])
except win32gui.error:
return None
def is_minimized(self, host: HostWindow) -> bool | None:
import win32gui
import win32process
try:
if (not win32gui.IsWindow(host.handle)
or win32process.GetWindowThreadProcessId(host.handle)[1] != host.pid
or not win32gui.GetWindowText(host.handle).startswith('DxDesigner')):
return None
return bool(win32gui.IsIconic(host.handle))
except win32gui.error:
return None
class HostWindowWatcher(QObject):
def __init__(self, window, request_path: Path, *, backend=None) -> None:
super().__init__(window)
self.window = window
self.backend = backend if backend is not None else WindowsHostWindows()
self.selection_path = request_path.with_name('selection.json')
self.host = self._read_host(request_path)
self.timer = QTimer(self)
self.timer.setInterval(150)
self.timer.timeout.connect(self._check)
self.timer.start()
self._check()
def _read_host(self, path: Path):
try:
data = json.loads(path.read_text(encoding='utf-8-sig'))
except (OSError, ValueError):
return None
snapshot = self.window.refdes_controller.snapshot
if (snapshot is None or not isinstance(data, dict)
or data.get('run_id') != snapshot.run_id
or not isinstance(data.get('design_path'), str)
or os.path.normcase(os.path.normpath(data['design_path']))
!= os.path.normcase(os.path.normpath(snapshot.design_path))):
return None
handle = data.get('host_view_handle')
if type(handle) is not int or handle == 0:
return None
return self.backend.resolve(handle)
def _check(self) -> None:
if self.window._closing:
self.timer.stop()
return
if self.host is None:
self.host = self._read_host(self.selection_path)
if self.host is not None:
minimized = self.backend.is_minimized(self.host)
if minimized is None:
# The exact owning DX window disappeared. Close the tool via
# the normal shutdown path so controllers and listeners stop.
if self.window.request_exit():
self.timer.stop()
return
self.window.set_host_minimized(minimized)
+50 -1
View File
@@ -1,7 +1,7 @@
"""Shared compact feature panel coordinated with a persistent toolbar."""
from __future__ import annotations
from PySide6.QtCore import QEvent, QPoint, QSize, QTimer, Signal
from PySide6.QtCore import QEvent, QPoint, QSize, QTimer, Qt, Signal
from PySide6.QtWidgets import QApplication, QFrame, QHBoxLayout, QLabel, QMainWindow, QPushButton, QSizePolicy, QStackedWidget, QVBoxLayout, QWidget
from dx_productivity.ui.floating_toolbar import FloatingToolbar, NAVIGATION
@@ -19,7 +19,19 @@ class MainWindow(QMainWindow):
def __init__(self, *, theme: Theme = Theme.LIGHT, layout_path=None) -> None:
super().__init__()
# The expanded view is an attached tool card below the toolbar. Keep
# the shared page window out of the taskbar and remove the native app
# title bar so it reads as one floating tool surface.
self.setWindowFlags(
Qt.WindowType.Tool
| Qt.WindowType.FramelessWindowHint
| Qt.WindowType.WindowStaysOnTopHint
)
self.setAttribute(Qt.WidgetAttribute.WA_TranslucentBackground)
self._closing = False
self._host_minimized = False
self._host_restore_toolbar = False
self._host_restore_panel = False
self._placing = False
self._effective_page_size = None
self._active_page = 0
@@ -84,6 +96,9 @@ class MainWindow(QMainWindow):
def show_toolbar(self) -> None:
if self._closing:
return
if self._host_minimized:
self._host_restore_toolbar = True
return
if not self._toolbar_positioned:
screen = self.toolbar.screen() or QApplication.primaryScreen()
position = self.layout_preferences.position
@@ -99,6 +114,11 @@ class MainWindow(QMainWindow):
def show_panel(self, index: int | None = None) -> None:
if self._closing:
return
if self._host_minimized:
self.set_active_page(self._active_page if index is None else index)
self._host_restore_toolbar = True
self._host_restore_panel = True
return
self.show_toolbar()
self.set_active_page(self._active_page if index is None else index)
self._anchor_panel()
@@ -111,11 +131,40 @@ class MainWindow(QMainWindow):
def hide_panel(self) -> None:
if self._closing:
return
if self._host_minimized:
self._host_restore_panel = False
return
self._remember_size()
self.hide()
self.show_toolbar()
self.toolbar.set_panel_state(self._active_page, False)
def set_host_minimized(self, minimized: bool) -> None:
"""Temporarily hide tool surfaces without changing their working state."""
if self._closing or self._host_minimized == minimized:
return
self._host_minimized = minimized
if minimized:
self._host_restore_toolbar = self.toolbar.isVisible()
self._host_restore_panel = self.isVisible()
self._remember_size()
self.toolbar.more_menu.close()
self.hide()
self.toolbar.hide()
return
if self._host_restore_toolbar:
self.show_toolbar()
if self._host_restore_panel:
# Restore passively; explicit user clicks still use show_panel().
passive = self.testAttribute(Qt.WidgetAttribute.WA_ShowWithoutActivating)
self.setAttribute(Qt.WidgetAttribute.WA_ShowWithoutActivating, True)
self._anchor_panel()
self.showNormal()
self._anchor_panel()
self.setAttribute(Qt.WidgetAttribute.WA_ShowWithoutActivating, passive)
self._host_restore_toolbar = False
self._host_restore_panel = False
collapse_to_floating = hide_panel
restore_from_floating = show_panel
+23 -1
View File
@@ -124,9 +124,15 @@ def _stylesheet(tokens: ThemeTokens) -> str:
font-size: 10pt;
letter-spacing: 0px;
}}
QMainWindow, QWidget#appRoot {{
QMainWindow {{
background: transparent;
border: none;
}}
QWidget#appRoot {{
background: {tokens.canvas};
color: {tokens.text_primary};
border: 1px solid {tokens.border};
border-radius: 10px;
}}
QWidget#floatingToolbar {{
background: {tokens.surface};
@@ -307,6 +313,22 @@ def _stylesheet(tokens: ThemeTokens) -> str:
max-width: 30px;
padding: 0;
}}
QToolButton#panelToggle {{
min-width: 66px;
max-width: 66px;
padding: 0 7px;
text-align: center;
}}
QToolButton#toolbarMore {{
min-width: 26px;
max-width: 16777000px;
padding: 0;
}}
QToolButton#toolbarMore::menu-indicator {{
image: none;
width: 0px;
height: 0px;
}}
QFrame#statusStrip {{
background: {tokens.surface};
border-top: 1px solid {tokens.border};
+5 -2
View File
@@ -71,7 +71,9 @@ def test_drag_only_handle_moves_toolbar_and_panel_without_switching(qtbot, monke
):
event = QMouseEvent(kind, local, global_pos, button, buttons, Qt.KeyboardModifier.NoModifier)
QCoreApplication.sendEvent(handle, event)
assert floating.pos() == QPoint(20, 60)
# A wider menu button can reach the edge of the offscreen test monitor.
bounds = floating.screen().availableGeometry()
assert floating.pos() == QPoint(min(20, bounds.right() - floating.width() + 1), 60)
assert window.pos().y() == panel_position.y() + 20
assert window.pages.currentIndex() == 0
@@ -112,6 +114,7 @@ def test_page_size_and_toolbar_position_restore_without_overwriting_settings(qtb
window.show_panel(0)
assert window.size().width() == 750 and window.size().height() == 470
window.toolbar.move_within_screen(QPoint(20, 50))
saved_position = window.toolbar.pos()
path = window.layout_preferences.path
window.request_exit()
from dx_productivity.ui.main_window import MainWindow
@@ -119,7 +122,7 @@ def test_page_size_and_toolbar_position_restore_without_overwriting_settings(qtb
qtbot.addWidget(restored)
restored.show_panel(7)
assert restored.size().width() == 700 and restored.size().height() == 410
assert restored.toolbar.pos() == QPoint(20, 50)
assert restored.toolbar.pos() == saved_position
def test_menu_registration_blocks_exit_but_not_panel_hide(qtbot, monkeypatch, tmp_path):
+59
View File
@@ -1,4 +1,5 @@
from PySide6.QtCore import Qt
from PySide6.QtWidgets import QToolButton
from dx_productivity.ui.main_window import MainWindow
@@ -48,6 +49,64 @@ def test_status_setters_update_hidden_toolbar_without_showing_panel(qtbot, tmp_p
assert not window.isVisible()
def test_panel_toggle_has_explicit_direction_and_text(qtbot):
window = MainWindow()
qtbot.addWidget(window)
toggle = window.toolbar.toggle_button
assert isinstance(toggle, QToolButton)
assert toggle.text() == '展开'
assert toggle.arrowType() == Qt.ArrowType.DownArrow
assert toggle.accessibleName() == '展开面板'
window.show_panel(0)
assert toggle.text() == '收起'
assert toggle.arrowType() == Qt.ArrowType.UpArrow
assert toggle.accessibleName() == '收起面板'
def test_expanded_panel_is_a_frameless_tool_card(qtbot):
window = MainWindow()
qtbot.addWidget(window)
flags = window.windowFlags()
assert flags & Qt.WindowType.FramelessWindowHint
assert flags & Qt.WindowType.Tool
assert window.centralWidget().objectName() == 'appRoot'
def test_more_button_reserves_room_for_text_and_arrow_in_both_themes(qtbot, qapp, tmp_path):
from PySide6.QtWidgets import QStyle
from dx_productivity.ui.app import create_application
from dx_productivity.ui.theme import Theme, apply_theme
create_application([])
window = MainWindow(layout_path=tmp_path / 'layout.json')
qtbot.addWidget(window)
window.show_toolbar()
toolbar = window.toolbar
button = toolbar.more_button
for theme in (Theme.LIGHT, Theme.DARK):
apply_theme(qapp, theme)
toolbar.refresh_theme(theme)
toolbar.fit_available_width(1100)
qapp.processEvents()
text_width = button.fontMetrics().horizontalAdvance('更多')
arrow_width = button.style().pixelMetric(QStyle.PixelMetric.PM_MenuButtonIndicator)
assert button.width() >= text_width + arrow_width + 14
assert button.text() == '更多'
assert toolbar.rect().contains(button.geometry())
toolbar.fit_available_width(96)
qapp.processEvents()
assert toolbar.rect().contains(button.geometry())
assert button.menu() is toolbar.more_menu
toolbar.fit_available_width(1100)
qapp.processEvents()
assert button.text() == '更多'
assert button.width() >= text_width + arrow_width + 14
def test_passive_status_keeps_host_focus_and_tracks_background_task(qtbot, qapp, tmp_path, monkeypatch):
from types import SimpleNamespace
from PySide6.QtWidgets import QWidget
+204
View File
@@ -0,0 +1,204 @@
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()
@pytest.mark.parametrize('expanded', (False, True))
@pytest.mark.parametrize('minimized', (False, True))
def test_watcher_exits_tool_when_owned_dx_window_disappears(qtbot, tmp_path, expanded, minimized):
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': 100}), encoding='utf-8')
backend = FakeHostWindows()
watcher = HostWindowWatcher(window, request, backend=backend)
window.show_panel(0) if expanded else window.show_toolbar()
backend.minimized.pop(200)
watcher._check()
assert not window._closing and watcher.timer.isActive()
assert window.toolbar.isVisible() and window.isVisible() is expanded
backend.minimized[100] = minimized
watcher._check()
backend.minimized.pop(100)
watcher._check()
assert window._closing
assert not window.toolbar.isVisible() and not window.isVisible()
assert not watcher.timer.isActive()
def test_watcher_retries_host_close_after_menu_registration_finishes(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': 100}), encoding='utf-8')
backend = FakeHostWindows()
watcher = HostWindowWatcher(window, request, backend=backend)
window.show_toolbar()
registering = [True]
window.startup_controller = SimpleNamespace(is_running=lambda: registering[0])
backend.minimized.pop(100)
watcher._check()
assert not window._closing and watcher.timer.isActive()
registering[0] = False
qtbot.waitUntil(lambda: window._closing)
assert not window.toolbar.isVisible() and 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()
+23
View File
@@ -3,6 +3,7 @@ Option Explicit
Const VDM_COMP = 128
Const VDM_NET = 32
Const VD_SELECTED = 1
Const VD_ALL = 0
Const SHORT_NAME = 3
Dim Fso
@@ -22,6 +23,10 @@ Dim RequestText
Dim InitialComponentReleased
Dim RefreshedMap
Dim FreshComponent
Dim LastSelection
Dim PageContext
Dim PageKeys
Dim SelectionText
Class FakeParentBlock
Public Name
@@ -79,6 +84,7 @@ End Class
Class FakeApplicationHost
Public TheComponent
Public ProjectPath
Public ActiveViewHandle
Public Function GetProjectData()
Set GetProjectData = New FakeProjectData
@@ -125,6 +131,8 @@ Call LoadGlobal(Fso.GetAbsolutePathName(Fso.BuildPath( _
ScriptRoot, "..\..\integration\dxdesigner795\BridgeCommon.vbs")))
Call LoadGlobal(Fso.GetAbsolutePathName(Fso.BuildPath( _
ScriptRoot, "..\..\integration\dxdesigner795\core\Snapshot.vbs")))
Call LoadGlobal(Fso.GetAbsolutePathName(Fso.BuildPath( _
ScriptRoot, "..\..\integration\dxdesigner795\core\Mailbox.vbs")))
TempRoot = Fso.BuildPath(Fso.GetSpecialFolder(2), _
"dx-tools-export-" & Replace(CStr(Timer), ".", "-"))
@@ -148,6 +156,9 @@ Component.ComponentName = "R1"
Set Application = New FakeApplicationHost
Set Application.TheComponent = Component
Application.ProjectPath = "C:\Projects\board.prj"
Application.ActiveViewHandle = 12345
Set ActiveView = Nothing
Call AssertEqual(DxBridgeHasActiveView(), False, "no active view is detected")
Set ActiveView = New FakeActiveView
Set ActiveView.TheComponent = Component
Set ActiveView.Block = New FakeBlock
@@ -171,11 +182,23 @@ Call AssertContains(RequestText, """selected"": true", "selected")
Call AssertContains(RequestText, """current_sheet"": true", "current sheet")
Call AssertContains(RequestText, """x"": ""12.5""", "x coordinate")
Call AssertContains(RequestText, """format_version"": 2", "format version")
Call AssertContains(RequestText, """host_view_handle"": 12345", "host view handle")
Call AssertContains(RequestText, """attributes"": []", "attributes field")
Call AssertContains(RequestText, """nets"": []", "nets field")
Call AssertContains(RequestText, """selected_nets"": []", "selected nets field")
Call AssertContains(RequestText, """locked"": false", "locked field")
LastSelection = ""
PageContext = ""
PageKeys = "[]"
Call DxBridgePublishSelection(RunRoot, RunId, SnapshotId, LastSelection, PageContext, PageKeys)
SelectionText = DxToolsReadUtf8(Fso.BuildPath(RunRoot, "selection.json"))
Call AssertContains(SelectionText, """state"":""ready""", "selection ready")
Call AssertContains(SelectionText, """host_view_handle"":12345", "selection host view handle")
Application.ActiveViewHandle = "unavailable"
Call AssertEqual(DxBridgeHostViewHandleJson(), "0", "unavailable host handle")
Application.ActiveViewHandle = 12345
' A new native enumeration can replace all bridge mappings. Keep the
' previous collection alive until the bridge exits: Dx releases the shared
' query context when an older collection is destroyed.
+106
View File
@@ -0,0 +1,106 @@
"""Check minimize/restore against one explicitly identified acceptance DX."""
from __future__ import annotations
import argparse
import json
from pathlib import Path
import shlex
import time
import win32con
import win32gui
import win32process
from dx_productivity.ui.host_window_watcher import WindowsHostWindows
from packaged_menu import tools_running, wait_for
from toolbar_ui import ToolbarUI, TOOLBAR_TITLE, PANEL_TITLE
def main():
parser = argparse.ArgumentParser()
parser.add_argument('executable', type=Path)
parser.add_argument('--host-pid', required=True, type=int)
parser.add_argument('--project', required=True, type=Path)
parser.add_argument('--evidence', required=True, type=Path)
options = parser.parse_args()
exe, project, base = options.executable.resolve(), options.project.resolve(), options.evidence.resolve()
assert 'acceptance' in project.parts
base.mkdir(parents=True, exist_ok=True)
def find_tool():
for process in tools_running():
if process.executable == 'None' or Path(process.executable).resolve() != exe or '--request' not in process.command_line:
continue
args = shlex.split(process.command_line, posix=False)
request = Path(args[args.index('--request') + 1].strip('"'))
data = json.loads(request.read_text(encoding='utf-8-sig'))
if Path(data['design_path']).resolve() == project:
return process, request, data
process, request, data = wait_for(find_tool, 30)
host = WindowsHostWindows().resolve(data['host_view_handle'])
assert host is not None and host.pid == options.host_pid
original_minimized = bool(win32gui.IsIconic(host.handle))
def windows():
result = {}
win32gui.EnumWindows(lambda handle, _: result.update({win32gui.GetWindowText(handle): handle})
if win32process.GetWindowThreadProcessId(handle)[1] == process.pid
and win32gui.GetWindowText(handle) in (TOOLBAR_TITLE, PANEL_TITLE) else None, None)
return result
cases = []
try:
if original_minimized:
# A correctly suppressed initial launch need not create native
# window handles until the first show. Absence also means hidden.
assert all(not win32gui.IsWindowVisible(handle) for handle in windows().values())
cases.append({'case': 'startup-while-minimized', 'tool_hidden': True})
win32gui.ShowWindow(host.handle, win32con.SW_RESTORE)
handles = wait_for(lambda: windows() if len(windows()) == 2 else None, 20)
bar, panel = handles[TOOLBAR_TITLE], handles[PANEL_TITLE]
wait_for(lambda: win32gui.IsWindowVisible(bar) and win32gui.IsWindowVisible(panel), 10)
ui = ToolbarUI(process.pid)
assert '桥接已连接' in ui.texts(ui.panel)
ui.capture(ui.toolbar).save(base / 'restored-toolbar.png')
ui.capture(ui.panel).save(base / 'restored-panel.png')
cases.append({'case': 'initial-restore', 'toolbar_visible': True, 'panel_visible': True})
for expanded in (True, False):
if not expanded:
ui.collapse()
for repeat in range(2):
progress = request.with_name('apply-progress.json')
prior = progress.stat().st_mtime
win32gui.ShowWindow(host.handle, win32con.SW_MINIMIZE)
wait_for(lambda: win32gui.IsIconic(host.handle)
and not win32gui.IsWindowVisible(bar) and not win32gui.IsWindowVisible(panel), 10)
wait_for(lambda: progress.stat().st_mtime > prior, 10)
assert win32gui.IsIconic(host.handle)
win32gui.ShowWindow(host.handle, win32con.SW_RESTORE)
wait_for(lambda: win32gui.IsWindowVisible(bar)
and bool(win32gui.IsWindowVisible(panel)) == expanded, 10)
time.sleep(.4)
foreground = win32gui.GetForegroundWindow()
foreground_pid = win32process.GetWindowThreadProcessId(foreground)[1] if foreground else None
assert foreground_pid != process.pid, 'Tool took foreground focus on host restore'
cases.append({'case': 'cycle', 'expanded': expanded, 'repeat': repeat + 1,
'hidden_during_minimize': True, 'previous_panel_state_restored': True,
'heartbeat_continued': True, 'tool_did_not_take_focus': True,
'foreground_pid_after_restore': foreground_pid})
finally:
if original_minimized:
win32gui.ShowWindow(host.handle, win32con.SW_MINIMIZE)
wait_for(lambda: all(not win32gui.IsWindowVisible(handle) for handle in windows().values()), 10)
result = {'host_pid': host.pid, 'host_hwnd': host.handle, 'tool_pid': process.pid,
'host_view_handle': data['host_view_handle'], 'request': str(request), 'executable': str(exe),
'cases': cases, 'final_dx_minimized': bool(win32gui.IsIconic(host.handle)),
'final_tool_hidden': all(not win32gui.IsWindowVisible(handle) for handle in windows().values()),
'design_values_written': False}
(base / 'host-native.json').write_text(json.dumps(result, ensure_ascii=False, indent=2), encoding='utf-8')
print(json.dumps(result, ensure_ascii=False, indent=2), flush=True)
if __name__ == '__main__':
main()