mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-11-27 15:49:52 -05:00
Outside the Design tab an agent had 175 commands, 50 of them in the tool list. There are now 118, named by what they act on (`object_`, `plate_`, `preset_`, `filament_`, `plugin_` and so on), and 115 are listed. Each takes its target and values in the call, acts on the selection when it names no target and says what it acted on; an old name is refused. Printers and system filaments install and uninstall, preferences read and write, plugins enable, reload, uninstall and refresh, and objects reorder, with no dialog to drive. The Speed Dial keeps its 129 tiles under the same ids. Eight defects in the rows these commands share with the menus are fixed. For a person: an object row that cannot run says why instead of "Select an object first.", rows that failed no longer claim success, Duplicate Plate can be undone, and Refresh Plugins picked while a refresh runs now runs after it instead of beside it.
120 lines
5.3 KiB
Python
Executable File
120 lines
5.3 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Checks where webview_run_javascript runs while a modal dialog is open, where a script cannot look.
|
|
|
|
tools/mcp/orca_mcp.py launch
|
|
tools/mcp/test_webview_modal.py
|
|
|
|
Scripts run in the web view of the topmost modal dialog, whichever dialog it is (the preset bundle
|
|
dialog, by default and by locator, the export bundle dialog above it, the Flushing volumes dialog);
|
|
the Home tab's web view behind a modal is refused, so is the bundle dialog's own web view once the
|
|
export bundle dialog is above it. A page that closes its dialog replies closed at once, not after the
|
|
timeout. Without a modal, the Home tab's web view still takes scripts. Exits 0 when every check passes.
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
import time
|
|
|
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
import orca_mcp # noqa: E402
|
|
|
|
|
|
def main():
|
|
client, _session = orca_mcp.session_client()
|
|
checks = []
|
|
|
|
def check(name, ok, detail=""):
|
|
checks.append((name, bool(ok), detail))
|
|
|
|
def refusal(**args):
|
|
try:
|
|
client.call("webview_run_javascript", **args)
|
|
return ""
|
|
except orca_mcp.McpError as e:
|
|
return str(e)
|
|
|
|
def dialogs():
|
|
return [d["title"] for d in client.call("app_state")["dialogs"]]
|
|
|
|
def wait_dialogs(count):
|
|
for _ in range(100):
|
|
if len(dialogs()) == count:
|
|
return True
|
|
time.sleep(0.1)
|
|
return False
|
|
|
|
def home_webview():
|
|
snap, texts = client.call_with_text("widget_list", target="main", query="webview")
|
|
for line in (texts[0] if texts else "").splitlines():
|
|
if "webview" in line and "[" in line:
|
|
return line.split("[", 1)[1].split("]", 1)[0]
|
|
return None
|
|
|
|
client.call("project_new", discard_changes=True)
|
|
|
|
# ---- The Home tab's web view, without and with a modal open ----
|
|
client.call("view_set", tab="home")
|
|
home = home_webview()
|
|
check("the Home tab shows a web view", home is not None)
|
|
try:
|
|
value = client.call("webview_run_javascript", code="1 + 1")["result"]
|
|
except orca_mcp.McpError as e:
|
|
value = str(e)
|
|
check("without a modal, the only web view takes a script", value == 2, value)
|
|
bundle = client.call("action_run", id="orca_command:preset_bundle:orca")
|
|
check("the bundle dialog opens", wait_dialogs(1), dialogs())
|
|
message = refusal(code="1", target=home)
|
|
check("a web view behind the modal is refused", "modal dialog is open" in message, message)
|
|
check("the bundle dialog's page takes a script", client.call("webview_run_javascript", code="document.title")["result"] == "Preset Bundle")
|
|
found = client.call("webview_run_javascript", code="!!document.getElementById('close_btn')",
|
|
target={"class": "webview", "within": "Preset Bundle"})["result"]
|
|
check("and takes one by locator", found is True, found)
|
|
|
|
# ---- A bundle dialog under the export bundle dialog ----
|
|
client.call("webview_run_javascript", code="SendWXMessage(JSON.stringify({command: 'export_page'}))")
|
|
check("the export bundle dialog opens above it", wait_dialogs(2), dialogs())
|
|
# Its web view shows about:blank until its first navigation starts.
|
|
for _ in range(50):
|
|
if "ExportPresetDialog" in client.call_with_text("widget_list", target="dialog", query="webview")[1][0]:
|
|
break
|
|
time.sleep(0.1)
|
|
message = refusal(code="1", target={"class": "webview", "within": "Preset Bundle"})
|
|
check("the dialog under the topmost is refused", "is under" in message, message)
|
|
url = client.call("webview_run_javascript", code="1")["url"]
|
|
check("without a target the topmost dialog's page is used", "ExportPresetDialog" in url, url)
|
|
client.call("dialog_answer", button="close")
|
|
check("the export dialog closes", wait_dialogs(1), dialogs())
|
|
|
|
# ---- A page that closes its dialog replies at once ----
|
|
start = time.time()
|
|
reply = client.call("webview_run_javascript", code="document.getElementById('close_btn').click()")
|
|
elapsed = time.time() - start
|
|
check("closing the dialog from its page replies closed", reply.get("closed") is True, reply)
|
|
check("and does so within a second", elapsed < 1.0, f"{elapsed:.2f} s")
|
|
client.await_job(bundle)
|
|
check("no dialog is left", wait_dialogs(0), dialogs())
|
|
|
|
# ---- The Flushing volumes dialog takes scripts as any topmost dialog does ----
|
|
client.call("view_set", tab="prepare")
|
|
client.call("widget_click", target={"label": "Add one filament"})
|
|
flush = client.call("widget_click", target={"label": "Flushing volumes"})
|
|
check("the Flushing volumes dialog opens", wait_dialogs(1), dialogs())
|
|
try:
|
|
title = client.call("webview_run_javascript", code="typeof document.title")["result"]
|
|
except orca_mcp.McpError as e:
|
|
title = str(e)
|
|
check("its page takes a script", title == "string", title)
|
|
client.call("dialog_answer", button="close")
|
|
client.await_job(flush)
|
|
check("no dialog is left at the end", wait_dialogs(0), dialogs())
|
|
|
|
failed = [c for c in checks if not c[1]]
|
|
for name, ok, detail in checks:
|
|
print(("PASS " if ok else "FAIL ") + name + ("" if ok or detail == "" else f": {detail}"))
|
|
print(f"{len(checks) - len(failed)}/{len(checks)} checks passed")
|
|
return 1 if failed else 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|