smartlab-studio-ctrl 0.2.9__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- smartlab_studio_ctrl-0.2.9/LICENSE +201 -0
- smartlab_studio_ctrl-0.2.9/PKG-INFO +12 -0
- smartlab_studio_ctrl-0.2.9/README.md +358 -0
- smartlab_studio_ctrl-0.2.9/pyproject.toml +19 -0
- smartlab_studio_ctrl-0.2.9/setup.cfg +4 -0
- smartlab_studio_ctrl-0.2.9/src/smartlab_studio_ctrl/__init__.py +11 -0
- smartlab_studio_ctrl-0.2.9/src/smartlab_studio_ctrl/config.py +37 -0
- smartlab_studio_ctrl-0.2.9/src/smartlab_studio_ctrl/desktop_capture.py +215 -0
- smartlab_studio_ctrl-0.2.9/src/smartlab_studio_ctrl/server_grpc/__init__.py +1 -0
- smartlab_studio_ctrl-0.2.9/src/smartlab_studio_ctrl/server_grpc/client.py +230 -0
- smartlab_studio_ctrl-0.2.9/src/smartlab_studio_ctrl/server_grpc/server.py +282 -0
- smartlab_studio_ctrl-0.2.9/src/smartlab_studio_ctrl/smartlab_config.py +231 -0
- smartlab_studio_ctrl-0.2.9/src/smartlab_studio_ctrl/smartlab_ctrl.py +329 -0
- smartlab_studio_ctrl-0.2.9/src/smartlab_studio_ctrl/smartlab_uia.py +1239 -0
- smartlab_studio_ctrl-0.2.9/src/smartlab_studio_ctrl/snipping_config.py +59 -0
- smartlab_studio_ctrl-0.2.9/src/smartlab_studio_ctrl/snipping_uia.py +325 -0
- smartlab_studio_ctrl-0.2.9/src/smartlab_studio_ctrl.egg-info/PKG-INFO +12 -0
- smartlab_studio_ctrl-0.2.9/src/smartlab_studio_ctrl.egg-info/SOURCES.txt +19 -0
- smartlab_studio_ctrl-0.2.9/src/smartlab_studio_ctrl.egg-info/dependency_links.txt +1 -0
- smartlab_studio_ctrl-0.2.9/src/smartlab_studio_ctrl.egg-info/requires.txt +7 -0
- smartlab_studio_ctrl-0.2.9/src/smartlab_studio_ctrl.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: smartlab-studio-ctrl
|
|
3
|
+
Version: 0.2.9
|
|
4
|
+
Summary: SmartLab Studio II device control using Windows UI Automation
|
|
5
|
+
Requires-Python: >=3.9
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Requires-Dist: pywinauto
|
|
8
|
+
Requires-Dist: comtypes
|
|
9
|
+
Requires-Dist: grpc-frame>=0.5.20
|
|
10
|
+
Requires-Dist: Pillow>=6.2
|
|
11
|
+
Requires-Dist: windows-capture<3,>=2.0.1; sys_platform == "win32" and platform_machine == "AMD64"
|
|
12
|
+
Dynamic: license-file
|
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
# smartlab_studio_ctrl
|
|
2
|
+
|
|
3
|
+
[](README.md) [](README.ja.md)
|
|
4
|
+
[](https://github.com/ohara-lab-su/smartlab_studio_ctrl/) [](https://ohara-lab-su.github.io/smartlab_studio_ctrl/en/index.html) [](https://ohara-lab-su.github.io/index.en.html)
|
|
5
|
+
|
|
6
|
+
Windows UI Automation (UIA) control of Rigaku SmartLab Studio II. Version **0.2.9**. This package controls the existing GUI; it does not communicate directly with the diffractometer.
|
|
7
|
+
|
|
8
|
+
## v0.2.9 Desktop capture with Windows Graphics Capture
|
|
9
|
+
|
|
10
|
+
On Windows x64, `SmartLabCtrl.capture_screenshot()` delegates to `DesktopCapture`, which calls Windows Graphics Capture (WGC) through Python's `windows_capture` binding. It takes the first frame from each monitor, composites the frames using their physical positions, and encodes the result as PNG in memory. The previous Snipping Tool calls remain as comments in the controller. On other platforms, `DesktopCapture` retains the original Pillow capture path.
|
|
11
|
+
|
|
12
|
+
```python
|
|
13
|
+
from smartlab_studio_ctrl import SmartLabCtrl
|
|
14
|
+
|
|
15
|
+
ctrl = SmartLabCtrl()
|
|
16
|
+
png = ctrl.capture_screenshot(output_directory=".")
|
|
17
|
+
print(ctrl.get_screenshot_state())
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Pass an existing directory to write `screenshot_local.png`. The method replaces the previous file after writing the complete PNG and returns the PNG bytes. Omit the directory to receive only the bytes. Capture states are `READY` (idle), `STARTING` (preparing), `CAPTURING` (capture and PNG encoding), and `SAVING` (writing the file). The legacy `snipping_config` argument remains accepted for call compatibility. The existing gRPC stream sends the PNG from the same capture method.
|
|
21
|
+
|
|
22
|
+
### Session diagnostics and live results
|
|
23
|
+
|
|
24
|
+
Display the target account's desktop on the Windows console or over RDP, then run Python as that account in the target session. For direct SSH/PsExec runs, connect as the same account and check the account and session ID reported by the launched Python process. The successful live test started the launcher as the signed-in `hpc` user through a temporary task.
|
|
25
|
+
|
|
26
|
+
```powershell
|
|
27
|
+
python .\run_interactive.py --session 2 --session-info .\example\uia_local\capture_screenshot.py
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
`get_windows_sessions()` returns session IDs, station names, connection states, and signed-in account names. `get_current_session_id()` and `get_current_windows_user()` identify the running Python process. `--session-info` logs the launcher and target process and reports a missing or disconnected target session.
|
|
31
|
+
|
|
32
|
+
| Test host state | WGC result |
|
|
33
|
+
| --- | --- |
|
|
34
|
+
| `hpc` was active and Python ran as `hpc` | Three in-memory captures and one file save succeeded through the launcher |
|
|
35
|
+
| `hpc` was active, and SSH as `nakada` targeted session 2 | Python ran as `nakada`; WGC failed to create its capture target |
|
|
36
|
+
| SSH as `nakada` targeted disconnected `hpc` session 2 | WGC failed to create its capture target |
|
|
37
|
+
| Both RDP clients disconnected; each account ran its own Python process | Both sessions and both Python launches remained available; both captures failed |
|
|
38
|
+
|
|
39
|
+
On this Windows Pro host, disconnecting RDP kept the users signed in, while signing out ends the user's session. `ACTIVE` reports the connection state. A locked desktop or insufficient access can still prevent capture. [Session diagnostics](docs/en/quickstart.md) · [Capture over gRPC](docs/en/server_grpc.md)
|
|
40
|
+
|
|
41
|
+
## v0.2.8 Windows interactive-session launcher
|
|
42
|
+
|
|
43
|
+
`run_interactive.py` runs the selected script with `pythonw.exe` from the same Python environment and uses the script’s directory as the working directory. It forwards stdout and stderr and collects the script’s exit code through a temporary file. Existing PyCharm interpreter options use the same syntax. Review any relative input and output paths when upgrading. [Setup and shutdown](docs/en/quickstart.md#windows-interactive-session-via-pycharm-or-ssh)
|
|
44
|
+
|
|
45
|
+
Use `--session-info` to record Windows connection states and the account and session of the Python process that runs the capture. [Diagnostics and live results](docs/en/quickstart.md#diagnose-windows-sessions-and-capture)
|
|
46
|
+
|
|
47
|
+
## v0.2.7 Export timing and retries
|
|
48
|
+
|
|
49
|
+
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.
|
|
50
|
+
|
|
51
|
+
v0.2.6 sent one right click and waited up to 15 seconds for the menu. If that input did not open the menu, the call timed out. v0.2.7 waits for a visible menu after each right click and proceeds as soon as it appears. The submenu and Save dialog have their own waits later in the sequence.
|
|
52
|
+
|
|
53
|
+
### Current operation sequence
|
|
54
|
+
|
|
55
|
+
1. **Select the graph through UIA.** Use `SelectionItemPattern.Select()` for `graph="2theta"` (the default) or `graph="2theta/theta"`. Resolve the visible `chartControl` using `SmartLabConfig.EXPORT_DATA_GRAPH_PATHS` and compute its center from `CurrentBoundingRectangle`.
|
|
56
|
+
2. **Right-click the graph.** Use `pywinauto.mouse.click(button="right", coords=...)`. After the input, wait **150 ms** and look up `mainShellWindow → Popup → contextMenu → contextMenuItem_Export` through 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.
|
|
57
|
+
3. **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.
|
|
58
|
+
4. **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 with `pywinauto.mouse.click(button="left", coords=...)`. Wait **150 ms** before looking for `exportDataWindow` in the same process.
|
|
59
|
+
5. **Save through UIA.** Keep the dialog's default data selection. Use `InvokePattern.Invoke()` on `exportBtn` and resolve the Windows Save dialog by its known child path. Use `ValuePattern.SetValue()` when `filename` is supplied, and invoke Save when `save=True`. The existing `overwrite` option controls overwrite confirmation. The local UIA API returns `True` after completing the save operation and `False` for a no-save operation or overwrite refusal.
|
|
60
|
+
|
|
61
|
+
The implementation calls UIA patterns through `pywinauto` and `comtypes`. In pywinauto 0.6.9 on the test host, the mouse click uses `SetCursorPos` to place the cursor and `mouse_event` to send the button press and release. 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.
|
|
62
|
+
|
|
63
|
+
### Verification
|
|
64
|
+
|
|
65
|
+
On SMARTLAB, the logged-in Windows user exported the existing **2θ** data three times consecutively and twice with a two-second pause. All five copies were 115,366 bytes and had the same SHA-256. Every attempt opened the menu on the first right click, so recovery by retry remains unverified on the instrument. The retry order and early exit were verified with simulated display timing. The repeat test left measurement and its settings untouched. See [data export](docs/en/export.md) for usage and investigation details.
|
|
66
|
+
|
|
67
|
+
## v0.2.6 Desktop capture over gRPC
|
|
68
|
+
|
|
69
|
+
Start `example/server.py` in the interactive Windows session, then run [`example/capture_screenshot.py`](example/capture_screenshot.py) on the client. The server calls the existing `SmartLabCtrl.capture_screenshot()` once and sends the resulting PNG bytes in chunks through `grpc_frame` server streaming. `client.capture_screenshot(output_directory=".")` saves `screenshot_local.png` in the client's working directory after the transfer completes and returns the PNG bytes. Omit the directory to receive only the bytes.
|
|
70
|
+
|
|
71
|
+
v0.2.6 used Snipping Tool on the server. v0.2.9 uses direct capture and keeps the same stream for remote desktop checks and collecting screenshots after errors. [gRPC setup and run instructions](docs/en/server_grpc.md)
|
|
72
|
+
|
|
73
|
+
## Windows desktops and Remote Development
|
|
74
|
+
|
|
75
|
+
Python started through SSH or PyCharm Remote Development can run on the same Windows host as SmartLab Studio II while belonging to a different desktop. On the test host, direct SSH and IDE runs used non-interactive Session 0, while the signed-in instrument desktop was in Session 1. A process in Session 0 cannot use UIA to find or operate the other session's windows or capture that desktop. On Windows, run `(Get-Process -Id $PID).SessionId` to identify the current PowerShell session and `query user` to look up the target user's interactive session. The examples use Session 1 because that was the test desktop. [Microsoft documentation on interactive services](https://learn.microsoft.com/en-us/windows/win32/services/interactive-services)
|
|
76
|
+
|
|
77
|
+
## v0.2.5 Test launcher for Remote Development
|
|
78
|
+
|
|
79
|
+
[run_interactive.py](run_interactive.py) runs development scripts in an interactive Windows session. PyCharm's Run tool window shows the launch status, live output, exceptions, and exit code while the launcher keeps the Windows console window off the desktop.
|
|
80
|
+
|
|
81
|
+
## v0.2.4 Previous Windows desktop capture workflow
|
|
82
|
+
|
|
83
|
+
Versions v0.2.4 through v0.2.8 used this API with PNG auto-save enabled in Snipping Tool. The Snipping Tool settings and states below describe that historical workflow.
|
|
84
|
+
|
|
85
|
+
```python
|
|
86
|
+
from smartlab_studio_ctrl.smartlab_ctrl import SmartLabCtrl
|
|
87
|
+
|
|
88
|
+
ctrl = SmartLabCtrl()
|
|
89
|
+
png = ctrl.capture_screenshot(output_directory=r"C:\Users\User1\Pictures")
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Pass an existing folder as `output_directory`. The method writes `screenshot_local.png`, replaces any existing file of that name, and returns the PNG bytes after saving. Omit the argument to receive the PNG bytes. If Snipping Tool uses a custom auto-save folder, pass `SnippingConfig(auto_save_directory=...)` to `SmartLabCtrl(snipping_config=...)` with the same folder.
|
|
93
|
+
|
|
94
|
+
Use `get_screenshot_state()` to inspect the capture.
|
|
95
|
+
|
|
96
|
+
| State | Meaning |
|
|
97
|
+
| --- | --- |
|
|
98
|
+
| `CLOSED` | The Snipping Tool window is closed |
|
|
99
|
+
| `READY` | The window is open and idle |
|
|
100
|
+
| `STARTING` | Preparing the capture |
|
|
101
|
+
| `CAPTURING` | Capturing or waiting for Snipping Tool to auto-save the PNG |
|
|
102
|
+
| `CLOSING` | Waiting for the window to close |
|
|
103
|
+
| `SAVING` | Writing the PNG to the specified folder |
|
|
104
|
+
|
|
105
|
+
Capture is available in every instrument state. A second capture request in the same Python process raises `RuntimeError` while capture or saving is in progress. [Local capture example](example/uia_local/capture_screenshot.py)
|
|
106
|
+
|
|
107
|
+
### Starting Python in the interactive session in v0.2.4
|
|
108
|
+
|
|
109
|
+
In v0.2.4, PsExec ran the existing UIA and capture scripts on the Windows desktop selected by `-i <session-id>`. Connecting to Windows over SSH alone does not put the remote shell on the physical desktop. From both SSH and PyCharm, the test host could read its instrument windows through UIA and capture the desktop after Python was launched in Session 1.
|
|
110
|
+
|
|
111
|
+
**Exact v0.2.4 PyCharm setting.** This is the line used under **Interpreter options** in the Windows-side Python run configuration.
|
|
112
|
+
|
|
113
|
+
```text
|
|
114
|
+
-c "import os,subprocess,sys; sys.exit(subprocess.call([r'C:\Tools\PsExec64.exe','-i','1','-nobanner','-w',os.getcwd(),os.path.join(os.path.dirname(sys.executable),'pythonw.exe'),*sys.argv[1:]]))"
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
The outer `python.exe` evaluates `-c` in the IDE's session. PsExec's `-i 1` selects the interactive session and `-w` preserves the working directory. `sys.argv[1:]` passes the selected script and its arguments to `pythonw.exe` in the same Python environment.
|
|
118
|
+
|
|
119
|
+
**To reproduce it over SSH**, connect to Windows and run the following from the project root in Windows PowerShell. Use the full path to your selected Python environment.
|
|
120
|
+
|
|
121
|
+
```powershell
|
|
122
|
+
$pythonw = Join-Path $env:USERPROFILE '.pyenv\pyenv-win\versions\3.11.9\pythonw.exe'
|
|
123
|
+
& 'C:\Tools\PsExec64.exe' -i 1 -nobanner -w (Get-Location).Path $pythonw .\example\uia_local\capture_screenshot.py
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Running `python.exe` in the interactive session can open a black console window that appears in the screenshot. Direct `pythonw.exe` keeps that window hidden but can leave Python without stdout and stderr, so the IDE may show only an exit code.
|
|
127
|
+
|
|
128
|
+
## Using the v0.2.5 launcher from PyCharm or SSH
|
|
129
|
+
|
|
130
|
+
When v0.2.4 starts `example/server.py` through the `-c` setting, `pythonw.exe` keeps the console window off the desktop but does not return Python's stdout or stderr to PyCharm. The server's startup logs and exceptions can disappear, and an exit code alone cannot distinguish startup, readiness, and failure. **In v0.2.5, replace the entire old `-c ...` line in the same Interpreter options field with the `run_interactive.py` line below.** This launcher change leaves server and capture logger settings intact.
|
|
131
|
+
|
|
132
|
+
Capture and PNG saving take place on the Windows host. If a direct SSH or IDE run starts Python in Session 0, use the launcher to start Python in the target session and verify the resulting user and session ID.
|
|
133
|
+
|
|
134
|
+
1. Sign in as the Windows user whose desktop you want to capture and display that desktop.
|
|
135
|
+
2. Place Sysinternals `PsExec64.exe` on the Windows host. The example uses `C:\Tools\PsExec64.exe`. Adjust the path, ensure the account running it has the required permissions, and complete the first-run license prompt.
|
|
136
|
+
3. Run `query user` on Windows to identify the target interactive session. Replace `1` in `--session 1` with that session ID. Install this package in the selected Python environment and verify that `pythonw.exe` is alongside its `python.exe`. [Microsoft PsExec documentation](https://learn.microsoft.com/en-us/sysinternals/downloads/psexec)
|
|
137
|
+
4. In the **Remote Development window connected to Windows**, open **Run → Edit Configurations → Edit configuration templates…** at the lower left, then select **Python**. Open **Modify options → Interpreter options**, paste the following line, and click **OK**. Leave the template's script path and working directory blank. [PyCharm Python run configuration](https://www.jetbrains.com/help/pycharm/run-debug-configuration-python.html)
|
|
138
|
+
|
|
139
|
+
```text
|
|
140
|
+
"C:\Users\User1\PycharmProjects\smartlab_studio_ctrl\run_interactive.py" --session 1
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Place the [shared launcher](run_interactive.py) in the Windows project and adjust the path above. Set `--session` to the interactive session ID. If PsExec is installed elsewhere, pass its path with `--psexec`. The launcher runs the selected script through `pythonw.exe` with the script’s directory as its working directory. It keeps the console window off the desktop, forwards stdout, stderr, and tracebacks to the PyCharm Run tool window as they occur, and returns the exit code.
|
|
144
|
+
|
|
145
|
+
When you press **Stop** in PyCharm on the Mac, the Windows IDE backend stops the run. When the launcher receives a stop signal, it asks the interactive Python process to shut down and relays its final logs. If the launcher is terminated first, the child detects that exit and initiates shutdown. An unresponsive child exits forcibly after five seconds. This stops the development Python process. Use the existing instrument controls to stop a measurement.
|
|
146
|
+
|
|
147
|
+
Look for `SmartLab gRPC server listening: ...` on startup and `SmartLab gRPC server shutdown completed` after an orderly shutdown. A stop request handled by the launcher returns exit code `130` and skips the `[Interactive] Exit code:` line. If the IDE forcibly terminates the launcher and the final logs are missing, use `Get-NetTCPConnection -LocalPort 50100 -State Listen` on Windows to check for a remaining listener.
|
|
148
|
+
|
|
149
|
+
- **New run configurations** inherit the Python template automatically when you right-click a `.py` file and choose **Run**. To recreate a configuration that predates the template change, open **Run → Edit Configurations**, select the configuration in the left pane, click **−** at the upper left, then run the file again. Removing a configuration leaves the source file in place. [PyCharm configuration templates](https://www.jetbrains.com/help/pycharm/run-debug-configuration.html)
|
|
150
|
+
- **To keep an existing configuration**, replace its previous `-c ...` line under **Interpreter options** with the line above.
|
|
151
|
+
- **Verify the setup** with the [local capture example](example/uia_local/capture_screenshot.py). Check for `[Interactive] Running` in PyCharm's Run output and a fresh modification time on `screenshot_local.png` in the Windows working directory.
|
|
152
|
+
- **If the server fails to bind**, check that `SERVER_IP` in `example/config_smartlab.yaml` is assigned to the Windows host and that `SERVER_PORT` is available. On the test machine, binding to `10.170.175.213:50051` failed, while startup and a connection succeeded on port `50100` on the same address. When changing the port for a test, use the same value on the server and client.
|
|
153
|
+
|
|
154
|
+
After connecting to Windows over SSH, you can use the same launcher from the Windows project root. Output returns to the SSH client. The capture example writes its PNG to `example\uia_local` on Windows.
|
|
155
|
+
|
|
156
|
+
```powershell
|
|
157
|
+
python .\run_interactive.py --session 1 .\example\uia_local\capture_screenshot.py
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
**Migrating from v0.2.4** works for regular `.py` runs that rely on Python's `print()`, standard-stream logging, and exception output. The capture and UIA APIs are unchanged, so those scripts need no code changes. Interactive stdin, terminal-specific features, native subprocess console output, and PyCharm debugging have no equivalence guarantee.
|
|
161
|
+
|
|
162
|
+
## v0.2.3: Running state includes preparation and shutdown
|
|
163
|
+
|
|
164
|
+
`is_running()`, `running`, and `get_running()` indicate **device activity**, including scan preparation, measurement, and the post-STOP shutdown phase—not merely acquisition time. They return `True` if the measurement dialog is visible **or** the scan-settings group reports UIA `CurrentIsEnabled=False`. They return `False` only if the dialog is absent and the group is enabled. UIA lookup failures raise an exception rather than being treated as idle.
|
|
165
|
+
|
|
166
|
+
| Phase | Scan-settings group | Measurement dialog | `is_running()` |
|
|
167
|
+
|---|---|---|---|
|
|
168
|
+
| Idle | Enabled | Absent | `False` |
|
|
169
|
+
| Preparing | Disabled | Absent | `True` |
|
|
170
|
+
| Measuring | Disabled | Present | `True` |
|
|
171
|
+
| Post-STOP shutdown | Disabled | Absent | `True` |
|
|
172
|
+
| Ready again | Enabled | Absent | `False` |
|
|
173
|
+
|
|
174
|
+
**Investigation and reproduction:** The previous dialog-only test returned `False` between `scan()` invocation and dialog appearance. A temporary diagnostic loop sampled `CurrentIsEnabled` and `CurrentIsOffscreen` for both the Scan button and its containing group, plus dialog visibility, every 0.5 seconds. The Windows server log from 2026-11-20 showed both controls disabled and no dialog at **0.00 s** and **5.33 s**, followed by dialog visibility at **7.48 s**; `CurrentIsOffscreen` remained `False`. The GUI also remains greyed out briefly after STOP. The known group path is `SmartLabConfig.SCAN_GROUP_PATH` (ending in `Manual_LabelScanBar`). To repeat the investigation, log these three UIA states across invocation, preparation, measurement, STOP, and return to idle.
|
|
175
|
+
|
|
176
|
+
`scan()` still invokes the button once and returns `None`; the temporary 90-second diagnostic wait has been removed. Dialog appearance is no longer a prerequisite for interpreting device activity. `stop()` continues to use the measurement dialog's Stop button. This is a GUI-state assessment, not direct access to the instrument's acquisition timer or internal communication state.
|
|
177
|
+
|
|
178
|
+
## v0.2.2: Reliable GUI export and reproducible UIA investigation
|
|
179
|
+
|
|
180
|
+
### Export contract and ownership
|
|
181
|
+
|
|
182
|
+
`SmartLabUIA.export_data(filename=None, save=False, graph="2theta", overwrite=False) -> bool` owns the GUI sequence and overwrite confirmation. `SmartLabCtrl` delegates to UIA. The gRPC server subclass handles server-side file generation/readback and returns file bytes; the gRPC client saves those bytes locally. `server_overwrite` and `client_overwrite` are independent. The transport layer must not duplicate GUI confirmation or mouse operations.
|
|
183
|
+
|
|
184
|
+
- `save=False`: leave the Windows Save dialog open and return `False` (not an overwrite rejection).
|
|
185
|
+
- `save=True`, existing server file, `overwrite=False`: choose **No** in the Windows overwrite prompt, cancel the Windows Save dialog, close the SmartLab export window, and return `False`; do not transfer bytes.
|
|
186
|
+
- `save=True`, `overwrite=True`: choose **Yes** if the overwrite prompt appears. On completion the UIA method returns `True`; this does not itself validate file contents.
|
|
187
|
+
- Remote client: `server_filename` names the Windows destination; `filename` names the client destination. `server_overwrite` controls the former, `client_overwrite` the latter. A `False` server result skips client saving; a successful remote call returns the client-side path. With `server_filename=None`, the server uses a temporary directory.
|
|
188
|
+
|
|
189
|
+
```python
|
|
190
|
+
# Run on the client computer with a configured SmartLabGrpcClient instance.
|
|
191
|
+
result = client.export_data(
|
|
192
|
+
filename="measurement.dat", save=True,
|
|
193
|
+
server_filename=r"C:\Users\User1\test_data\measurement.dat",
|
|
194
|
+
graph="2theta", server_overwrite=True, client_overwrite=True,
|
|
195
|
+
)
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### Observed UIA hierarchy and operation
|
|
199
|
+
|
|
200
|
+
On SmartLab Studio II x64 v5.3.200.0, select the 2θ tab through `SelectionItemPattern`, resolve the graph using `EXPORT_DATA_GRAPH_PATHS`, then right-click the graph center. The **first** context menu is an element under the main window:
|
|
201
|
+
|
|
202
|
+
```text
|
|
203
|
+
mainShellWindow
|
|
204
|
+
Popup (ClassName)
|
|
205
|
+
contextMenu (AutomationId, ContextMenu)
|
|
206
|
+
contextMenuItem_Export (AutomationId, MenuItem, Name="エクスポート")
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
Resolve this fixed path from `SmartLabConfig.EXPORT_DATA_MENU_PATH` using the shared `_find_child()` routine, and call `ExpandCollapsePattern.Expand()` on `contextMenuItem_Export`. This was observed to work. The second-level `データをエクスポート...` item is then selected. Its **complete stable path was not established**; the current code checks the observed popup/child alternatives and clicks the located item. Do not claim that this second level has a confirmed fixed path.
|
|
210
|
+
|
|
211
|
+
The SmartLab export window has `AutomationId=exportDataWindow` (observed PID 4188 in one session), with `exportBtn` and `PART_CloseButton`. The native Windows Save dialog is a `#32770` child; overwrite confirmation is a nested `#32770`. Relevant `AutomationId`s: Save `1`, Cancel `2`, overwrite Yes `6`, No `7`, message `65535`. These paths are in `SmartLabConfig.EXPORT_DATA_DIALOG_PATHS`. PIDs and screen coordinates are session-specific, not configuration constants.
|
|
212
|
+
|
|
213
|
+
### How the failure was investigated and corrected
|
|
214
|
+
|
|
215
|
+
1. The original two-level menu sequence used a right-click, mouse hover over **Export**, and click on the submenu. The first menu could disappear before the submenu operation; a log line saying “clicked” only confirms an input attempt, **not** that the export dialog opened.
|
|
216
|
+
2. To inspect the actual UIA structure, a temporary diagnostic was inserted **inline in `SmartLabUIA.export_data()` immediately after the first right-click**, before any hover or second-level action. It read the main window's `Popup`, `contextMenu`, and descendants without moving the mouse. This captured `contextMenuItem_Export` and its `AutomationId` in the Windows server log. The temporary diagnostic was removed after the investigation.
|
|
217
|
+
3. The first-level menu selection was changed to `ExpandCollapsePattern.Expand()` using the confirmed UIA element, retaining mouse hover as a fallback. A server trace subsequently recorded `エクスポート項目をUIA ExpandCollapsePatternで展開`, then submenu click, `exportDataWindow` acquisition, Save, overwrite **No**, Save-dialog Cancel, export-window Close, and window disappearance. That trace completed in about five seconds.
|
|
218
|
+
4. Earlier traces included a 15-second `exportDataWindow` lookup failure and an `export_close` disappearance timeout. Those errors should not automatically be attributed to the export window itself: first verify that both menu levels actually opened. For closing, verify the **window's disappearance**, rather than relying solely on a potentially stale child-button UIA reference.
|
|
219
|
+
|
|
220
|
+
**Reproducing the investigation:** use the same interactive Windows session and target graph; insert temporary logging immediately after `mouse.click(button="right", coords=graph_xy)` in `export_data()`, resolve `Popup → contextMenu`, enumerate its immediate UIA children and record Name, AutomationId, ClassName, ControlType and PID. Do **not** move the mouse before capturing. Identify `contextMenuItem_Export`, inspect `ExpandCollapsePattern`, then restore the normal flow. Prefer the project's shared UIA lookup functions and configuration paths for production code; full-tree enumeration is a diagnostic technique only. Log on the Windows server; transfer diagnostic logs to the client only when explicitly needed for remote inspection, not as part of the production export API.
|
|
221
|
+
|
|
222
|
+
**Verification boundary:** repeated `server_overwrite=False` runs were reported stable, and the supplied server trace confirms the complete GUI cancellation path and gRPC `False` response. The `server_overwrite=True`/client overwrite path is a separate test case; do not infer its successful file replacement solely from the cancellation trace. Compare file bytes or hashes before/after when validating overwrite.
|
|
223
|
+
|
|
224
|
+
## v0.2.1: Device control and gRPC
|
|
225
|
+
|
|
226
|
+
`SmartLabCtrl` is the primary public device API; `SmartLabUIA` remains available for direct GUI control. The server uses `grpc_frame` COM execution support and the client uses its dynamically bound remote methods. Remote `client.export_data(filename="measurement.txt", save=True)` writes the exported file to the client PC. See [gRPC documentation](docs/en/server_grpc.md).
|
|
227
|
+
|
|
228
|
+
## Features
|
|
229
|
+
|
|
230
|
+
- Read and set scan, move, and slit parameters on the **Z-axis / Basic** screen.
|
|
231
|
+
- Start scans, request cancellation, monitor the *装置制御中* dialog and read remaining time.
|
|
232
|
+
- Export data from the **2θ** or **2θ/θ** graph through the GUI export dialog and Windows Save dialog.
|
|
233
|
+
- Share a single `IUIA` instance per `SmartLabUIA` object; UI paths and identifiers reside in the `SmartLabConfig` dataclass.
|
|
234
|
+
- Accept an injected logger (e.g. XLogger), with a standard `logging` fallback.
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
## v0.1.0: Post-measurement data export
|
|
238
|
+
|
|
239
|
+
`export_data(filename=None, save=False, graph="2theta", overwrite=False)` uses the selected graph's context menu to open `データをエクスポート...`, invokes `exportBtn`, and reaches the Windows Save dialog. It leaves the export dialog's data selection unchanged (observed default: all data).
|
|
240
|
+
|
|
241
|
+
```python
|
|
242
|
+
from smartlab_studio_ctrl import SmartLabUIA
|
|
243
|
+
|
|
244
|
+
smartlab = SmartLabUIA()
|
|
245
|
+
result = smartlab.export_data(filename=None, save=False)
|
|
246
|
+
# smartlab.export_data(filename="measurement.txt", save=True)
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
`filename=None` preserves the GUI's default filename. `save=False` leaves the Save dialog open; `save=True` invokes the Save button. In v0.2.2 the return value is `bool`: `True` after the save sequence, `False` when not saving or declining overwrite. This does not validate file contents. Measurement completion is outside this method's scope.
|
|
250
|
+
|
|
251
|
+
[Export sequence, observed UIA object structure, and investigation evidence](docs/en/export.md)
|
|
252
|
+
|
|
253
|
+
## Requirements
|
|
254
|
+
|
|
255
|
+
Windows with SmartLab Studio II x64 v5.3.200.0 (the inspected version); Python 3.9+ (dataclasses are used), `pywinauto` and `comtypes`. The relevant GUI screen must be open. The software uses UIA and mouse input, so an interactive Windows desktop is required for export.
|
|
256
|
+
|
|
257
|
+
## Quick start
|
|
258
|
+
|
|
259
|
+
Install the package and its dependencies using the project's `pyproject.toml` (`pip install .`), then:
|
|
260
|
+
|
|
261
|
+
```python
|
|
262
|
+
from smartlab_studio_ctrl import SmartLabUIA
|
|
263
|
+
|
|
264
|
+
smartlab = SmartLabUIA()
|
|
265
|
+
print(smartlab.get_start())
|
|
266
|
+
print(smartlab.is_running())
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
**Measurement (moves the instrument):**
|
|
270
|
+
|
|
271
|
+
```python
|
|
272
|
+
smartlab.scan() # requests a scan; does not wait
|
|
273
|
+
print(smartlab.get_remaining_time())
|
|
274
|
+
# smartlab.stop() # requests cancellation
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
**Export (operates the GUI):**
|
|
278
|
+
|
|
279
|
+
```python
|
|
280
|
+
result = smartlab.export_data(filename=None, save=False)
|
|
281
|
+
print(result) # Save dialog remains open when save=False
|
|
282
|
+
# smartlab.export_data(filename="measurement.txt", save=True)
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
`is_running() == False` means `IDLE` (no measurement dialog, scan settings enabled, and no active export); it does **not** prove successful measurement completion. `set_xxx()` success does not verify instrument acceptance. Export uses the current selection in the export dialog; `save=True` clicks Save, but does not verify file contents.
|
|
286
|
+
|
|
287
|
+
## Public API
|
|
288
|
+
|
|
289
|
+
| Group | Methods |
|
|
290
|
+
| --- | --- |
|
|
291
|
+
| Measurement | `scan`, `stop`, `is_running`, `get_running`, `get_remaining_time`, `get_estimated_end_time` |
|
|
292
|
+
| Parameters | `get_` / `set_` + `absolute_scan`, `relative_scan`, `scan_mode`, `start`, `stop_position`, `step`, `speed`, `move_to`, `move_step`, `slit`, `slit_list`, `slit_width` |
|
|
293
|
+
| Export | `export_data(filename=None, save=False, graph="2theta", overwrite=False)` |
|
|
294
|
+
| Desktop capture | `capture_screenshot(output_directory=None)`, `get_screenshot_state()` |
|
|
295
|
+
| Properties | `running`, `remaining_time`, `estimated_end_time`, and 12 parameter properties |
|
|
296
|
+
|
|
297
|
+
## Examples and documentation
|
|
298
|
+
|
|
299
|
+
Examples: `example/get.py`, `set.py`, `scan.py`, `stop.py`, `test_seq1.py`, `test_seq2.py`, `export_data.py`.
|
|
300
|
+
|
|
301
|
+
| File | Role |
|
|
302
|
+
| --- | --- |
|
|
303
|
+
| [`run_interactive.py`](run_interactive.py) | Start development scripts in the interactive Windows session and relay logs |
|
|
304
|
+
| [`DesktopCapture`](src/smartlab_studio_ctrl/desktop_capture.py) | Windows x64 WGC capture, PNG encoding and saving, and capture state |
|
|
305
|
+
| [`src/smartlab_studio_ctrl/snipping_uia.py`](src/smartlab_studio_ctrl/snipping_uia.py) and [`snipping_config.py`](src/smartlab_studio_ctrl/snipping_config.py) | Legacy Snipping Tool capture, capture state, and UIA path configuration |
|
|
306
|
+
| [`src/smartlab_studio_ctrl/server_grpc/`](src/smartlab_studio_ctrl/server_grpc/) | `server.py` streams the existing capture result and `client.py` reassembles and saves it |
|
|
307
|
+
| [`example/uia_local/capture_screenshot.py`](example/uia_local/capture_screenshot.py) | Verify UIA and capture on Windows |
|
|
308
|
+
| [`example/capture_screenshot.py`](example/capture_screenshot.py) | Verify the full path from server-side capture to client-side saving |
|
|
309
|
+
|
|
310
|
+
[GitHub Pages documentation](https://ohara-lab-su.github.io/smartlab_studio_ctrl/en/index.html) · [Architecture](docs/en/architecture.md) · [UIA study](docs/en/uia_study.md) · [GUI object tree](docs/en/gui_tree.md) · [API guide](docs/en/api_guide.md) · [Changelog](CHANGELOG.md).
|
|
311
|
+
|
|
312
|
+
Documentation is built with Sphinx and MyST using `docs/build.sh`; **no MkDocs**. The package includes `SmartLabCtrl` and the gRPC transport in separate modules; `SmartLabUIA` remains responsible for GUI operations.
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
## gRPC server (v0.2.1)
|
|
316
|
+
|
|
317
|
+
The launcher `example/server.py` loads the adjacent `config_smartlab.yaml` and passes it to the server, which binds to `SERVER_IP:SERVER_PORT`. `SERVER_IP` must be assigned to the server PC. Start it with `python example/server.py`; `SERVER_HOST` and `--host` / `--port` are not supported.
|
|
318
|
+
|
|
319
|
+
[gRPC server documentation](docs/en/server_grpc.md). The public device API is `SmartLabCtrl`; `SmartLabUIA` remains available for direct control.
|
|
320
|
+
|
|
321
|
+
The gRPC-only `SmartLabGrpcCtrl` subclasses `SmartLabCtrl`.
|
|
322
|
+
|
|
323
|
+
### v0.2.3: State management and operation interlocks (in progress)
|
|
324
|
+
|
|
325
|
+
`get_state()` / `state` report `IDLE`, `SCAN_STARTING`, `SCANNING`, `SCAN_STOPPING`, or `EXPORTING`. `is_running()` / `get_running()` / `running` return true for any non-idle state; `is_ready()` returns true only for `IDLE`. The scan dialog and the scan settings group's `CurrentIsEnabled` property are inspected through UIA. Because UIA alone cannot distinguish scan startup from shutdown, the last `scan()` / `stop()` operation provides supplementary phase information. Export activity is detected through the visible `exportDataWindow` and an in-call flag.
|
|
326
|
+
|
|
327
|
+
`scan()`, `export_data()`, and ordinary parameter `get_*` / `set_*` operations are restricted to `IDLE`; `stop()` is allowed only during `SCANNING`. State and measurement-time queries remain available. When `save=False` leaves the export dialog open, the state remains `EXPORTING` until that window closes. UIA lookup failures raise errors rather than reporting idle.
|
|
328
|
+
|
|
329
|
+
### API operation permission matrix
|
|
330
|
+
|
|
331
|
+
| API / operation | `IDLE` | `SCAN_STARTING` | `SCANNING` | `SCAN_STOPPING` | `EXPORTING` |
|
|
332
|
+
| --- | :---: | :---: | :---: | :---: | :---: |
|
|
333
|
+
| `scan()` | Yes | No | No | No | No |
|
|
334
|
+
| `stop()` | No | No | Yes | No | No |
|
|
335
|
+
| `export_data()` | Yes | No | No | No | No |
|
|
336
|
+
| Ordinary parameter `get_*()` | Yes | No | No | No | No |
|
|
337
|
+
| Ordinary parameter `set_*()` | Yes | No | No | No | No |
|
|
338
|
+
| `get_state()` / `state` | Yes | Yes | Yes | Yes | Yes |
|
|
339
|
+
| `is_running()` / `get_running()` / `running` | Yes | Yes | Yes | Yes | Yes |
|
|
340
|
+
| `is_ready()` | Yes | Yes | Yes | Yes | Yes |
|
|
341
|
+
| `get_remaining_time()` / `get_estimated_end_time()` | Yes | Yes | Yes | Yes | Yes |
|
|
342
|
+
| `capture_screenshot()` (v0.2.4, local) | Yes | Yes | Yes | Yes | Yes |
|
|
343
|
+
|
|
344
|
+
Yes means the API call is permitted, not that the instrument will accept it or that a time value is available. No means the state interlock rejects the operation with `RuntimeError`. State and measurement-time queries are not treated as ordinary parameter getters.
|
|
345
|
+
|
|
346
|
+
| `state` | `is_running()` | `is_ready()` | Evidence / meaning |
|
|
347
|
+
| --- | :---: | :---: | --- |
|
|
348
|
+
| `IDLE` | `False` | `True` | No measurement dialog, scan settings enabled, no export active |
|
|
349
|
+
| `SCAN_STARTING` | `True` | `False` | Scan settings disabled, dialog absent; startup phase inferred from operation history |
|
|
350
|
+
| `SCANNING` | `True` | `False` | Measurement dialog visible, except during the stopping phase |
|
|
351
|
+
| `SCAN_STOPPING` | `True` | `False` | Shutdown phase after `stop()`; operation history used |
|
|
352
|
+
| `EXPORTING` | `True` | `False` | Export API active or `exportDataWindow` visible |
|
|
353
|
+
|
|
354
|
+
**Typical transitions:** `IDLE → SCAN_STARTING → SCANNING → SCAN_STOPPING → IDLE`; normal measurement completion may instead transition directly from `SCANNING` to `IDLE`. Export follows `IDLE → EXPORTING → IDLE`. The gray-out alone cannot distinguish startup from shutdown; the most recent `scan()` / `stop()` operation supplies phase information.
|
|
355
|
+
|
|
356
|
+
**Operational notes:** `stop()` is permitted only in `SCANNING`, never during preparation, stopping, or export. `export_data(save=False)` retains `EXPORTING` until the export window closes. UIA lookup failures raise exceptions rather than being treated as `IDLE`. These are the v0.2.3 implementation rules; end-to-end instrument verification of transitions and interlocks remains outstanding.
|
|
357
|
+
|
|
358
|
+
**Verification status:** UIA logs showed the scan group disabled without a dialog at 0.00 s and 5.33 s, with the dialog appearing at 7.48 s. Post-stop gray-out was observed in the GUI. End-to-end testing of transitions and interlocks is still required before declaring v0.2.3 complete. Cross-client exclusion also depends on the gRPC execution queue.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "smartlab-studio-ctrl"
|
|
7
|
+
version = "0.2.9"
|
|
8
|
+
description = "SmartLab Studio II device control using Windows UI Automation"
|
|
9
|
+
requires-python = ">=3.9"
|
|
10
|
+
dependencies = [
|
|
11
|
+
"pywinauto",
|
|
12
|
+
"comtypes",
|
|
13
|
+
"grpc-frame>=0.5.20",
|
|
14
|
+
"Pillow>=6.2",
|
|
15
|
+
"windows-capture>=2.0.1,<3; sys_platform == 'win32' and platform_machine == 'AMD64'",
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
[tool.setuptools.packages.find]
|
|
19
|
+
where = ["src"]
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"""SmartLab Studio II のデバイス制御。"""
|
|
2
|
+
|
|
3
|
+
import sys
|
|
4
|
+
|
|
5
|
+
from smartlab_studio_ctrl.desktop_capture import DesktopCapture
|
|
6
|
+
|
|
7
|
+
if sys.platform == "win32":
|
|
8
|
+
from smartlab_studio_ctrl.smartlab_ctrl import SmartLabCtrl
|
|
9
|
+
from smartlab_studio_ctrl.smartlab_uia import SmartLabUIA
|
|
10
|
+
|
|
11
|
+
from smartlab_studio_ctrl.smartlab_config import SmartLabConfig
|