Measurement data export
SmartLab Studio II does not always render menus immediately after input. v0.2.7 adds short waits and visibility checks to the existing mouse/UIA sequence. It retries graph input only while the initial context menu remains unavailable.
Usage
This example saves the data already shown in the 2θ graph. It does not start a measurement. Run it when get_state() reports IDLE.
from smartlab_studio_ctrl import SmartLabUIA
smartlab = SmartLabUIA()
saved = smartlab.export_data(filename="measurement.txt", save=True, graph="2theta")
print(saved)
GUI operation sequence
Select the graph through UIA. Use
SelectionItemPattern.Select()forgraph="2theta"(the default) orgraph="2theta/theta". Resolve the visiblechartControlusingSmartLabConfig.EXPORT_DATA_GRAPH_PATHSand compute its center fromCurrentBoundingRectangle.Right-click the graph. Use
pywinauto.mouse.click(button="right", coords=...). After the input, wait 150 ms and look upmainShellWindow → Popup → contextMenu → contextMenuItem_Exportthrough fixed UIA child paths. After each right-click, poll for visibility for up to one second, about every 50 ms. Stop sending retry input once the item is visible.Retry only if the menu has not opened. Right-click again at the same point. If it is still absent, left-click the graph and then right-click. If the menu still does not open, use
pywinauto.mouse.move()to shift up to six pixels to the right within the graph and repeat the same sequence. The move and the graph’s left click also have a 150 ms settle time and a visibility check. Exhausting these attempts raises an error.Expand through UIA and select with the mouse. Call
ExpandCollapsePattern.Expand()on Export. If the pattern is unavailable or the call raises an exception, move the mouse to the item’s center. Wait 150 ms, find the visibleデータをエクスポート...item in the known candidate paths, and left-click its center withpywinauto.mouse.click(button="left", coords=...). Wait 150 ms before looking forexportDataWindowin the same process.Save through UIA. Keep the dialog’s default data selection. Use
InvokePattern.Invoke()onexportBtnand resolve the Windows Save dialog by its known child path. UseValuePattern.SetValue()whenfilenameis supplied, and invoke Save whensave=True. The existingoverwriteoption controls overwrite confirmation. The local UIA API returnsTrueafter completing the save operation andFalsefor a no-save operation or overwrite refusal.
The right click on the graph and the left click on the data-export item require mouse input on the logged-in Windows desktop. Matching the session ID alone does not grant mouse input rights. On the test host, an SSH/PsExec-launched process could read the UIA tree but received an access-denied error from SetCursorPos. Timing retries cannot resolve that error.
Arguments, results, and file verification
Use
graph="2theta"for 2θ orgraph="2theta/theta"for 2θ/θ. The v0.2.7 repeat test covered 2θ.filename=Nonepreserves the Save dialog’s default.save=Falseleaves the Save dialog open and returnsFalse.save=Truewaits for the Save dialog to close. Declining an overwrite cancels the save, closes the export window, and returnsFalse. Operation failures raise an exception.Truemeans the GUI save operation completed. The local API does not validate the file contents. The gRPC server waits for a newly created or updated file before returning its bytes. gRPC and client-side saving
Instrument verification
On SMARTLAB, the logged-in Windows user exported the existing 2θ data three times consecutively and twice with a two-second pause. All five menus opened on the first right click, and the 115,366-byte output files had identical SHA-256 checksums. The repeat test left measurement and its settings untouched. Simulated tests covered retry order and early exit. Recovery via retry on the instrument and live gRPC export using this update remain unverified.
Reproducing the investigation
Opening the context menu and operating it after it opens can be tested independently. See the UIA studies for the role and scope of each script.