Files
OrcaSlicer/tools/automation/example_slice.py
SoftFever 892b33bac5 refactor(automation): drop screenshot.viewport3d, keep only screenshot.window
The on-screen window capture is composited from the desktop framebuffer, so it
already includes the GL 3D viewport as currently shown (model in the editor,
toolpaths in Preview). The offscreen render_thumbnail path only ever drew the
model GLVolumeCollection — never the gcode toolpaths — and produced a blank image
after slicing because the app switches to the Preview panel. Rather than maintain a
second, more limited capture method, remove it entirely.

Removes the JSON-RPC method, IUiBackend/WxUiBackend implementation, dispatcher
route + capability entry, the now-dead opt_int/thumbnail_to_wximage helpers and
ThumbnailData include, the mock override + unit test, and the Python
screenshot_3d client method. Docs updated accordingly.
2026-06-03 18:05:23 +08:00

76 lines
2.4 KiB
Python

"""End-to-end smoke test: launch OrcaSlicer with the automation server, load a
model, slice it, wait for completion, and save a window PNG.
Run:
python example_slice.py --orca /path/to/OrcaSlicer --model /path/to/cube.stl
On Linux CI, wrap with a virtual display, e.g.:
xvfb-run -a python example_slice.py --orca ./OrcaSlicer --model cube.stl
"""
from __future__ import annotations
import argparse
import subprocess
import sys
import time
from orca_automation import OrcaClient, OrcaError
def main() -> int:
ap = argparse.ArgumentParser()
ap.add_argument("--orca", required=True, help="path to the OrcaSlicer executable")
ap.add_argument("--model", required=True, help="path to an STL/3MF to load")
ap.add_argument("--port", type=int, default=13619)
args = ap.parse_args()
proc = subprocess.Popen([
args.orca,
"--automation-server",
f"--automation-server-port={args.port}",
args.model,
])
try:
orca = OrcaClient(port=args.port)
# Wait for the server to come up.
for _ in range(60):
try:
print("connected:", orca.version())
break
except OSError:
time.sleep(0.5)
else:
print("ERROR: automation server did not start", file=sys.stderr)
return 1
# Wait until the project (model) is loaded.
deadline = time.time() + 30
while time.time() < deadline:
if orca.app_state().get("project_loaded"):
break
time.sleep(0.5)
# Click Slice and wait for the Export button to become enabled
# (slicing complete) — wait_for replaces fragile fixed sleeps.
orca.click({"id": "btn_slice"})
orca.wait_for({"id": "btn_export"}, state="enabled", timeout_ms=180000,
poll_ms=500)
# The window screenshot is captured from the on-screen composited
# framebuffer, so it already includes the 3D viewport (model in the
# editor, or toolpaths in Preview after slicing).
with open("window.png", "wb") as f:
f.write(orca.screenshot())
print("wrote window.png")
return 0
finally:
proc.terminate()
try:
proc.wait(timeout=10)
except subprocess.TimeoutExpired:
proc.kill()
if __name__ == "__main__":
raise SystemExit(main())