screen.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. from __future__ import annotations
  2. from pathlib import Path
  3. from typing import Any
  4. from ... import windows_automation
  5. from ..context import WorkflowContext
  6. from ..registry import control_ports, field_def, register_node
  7. def screenshot_node(node: dict[str, Any], inputs: dict[str, Any], context: WorkflowContext) -> dict[str, Any]:
  8. save_path = inputs.get("save_path", node.get("params", {}).get("save_path"))
  9. result = windows_automation.take_screenshot(str(Path(save_path)) if save_path else None, include_base64=False)
  10. if result.get("path"):
  11. context.runtime["current_screenshot_path"] = result["path"]
  12. return result
  13. register_node(
  14. {
  15. "type": "screen.screenshot",
  16. "category": "screen",
  17. "label": "屏幕截图",
  18. "params": {"save_path": field_def("text", "保存路径")},
  19. "inputs": {"save_path": field_def("string", "保存路径")},
  20. "outputs": {
  21. "path": {"type": "string", "label": "图片路径"},
  22. "width": {"type": "number", "label": "宽度"},
  23. "height": {"type": "number", "label": "高度"},
  24. },
  25. "control_ports": control_ports(),
  26. },
  27. screenshot_node,
  28. )