Skip to content

feat: add remote Python TCP server for controlling the app, view, and operations#119

Open
trailcode wants to merge 3 commits into
mainfrom
feature/remote-python-server
Open

feat: add remote Python TCP server for controlling the app, view, and operations#119
trailcode wants to merge 3 commits into
mainfrom
feature/remote-python-server

Conversation

@trailcode

Copy link
Copy Markdown
Owner

Summary

This PR implements a remote server mode so EzyCad can run as both a desktop GUI application and a controllable server that listens for Python commands to drive the view, sketches, shapes, and operations.

It leverages the existing Python embedding (pybind11 + ezycad_native module with ezy, view, Shp objects, etc.) but exposes it over the network via a simple TCP REPL.

Key Changes

  • New src/python_remote_server.h/.cpp: PythonExecutionQueue (thread-safe task queue) + RemotePythonServer (TCP listener using plain sockets, length-prefixed protocol). Code is queued for safe execution on the main thread (OCCT/ImGui not thread-safe).
  • main.cpp: CLI support (--listen [host:]port, --headless parsed), early Python force-init when server enabled, integration of queue + server, process_pending() in the main loop.
  • python_console.cpp: Extended Python bindings (e.g. view.fit_all(), view.screenshot(), view.get_shape(), camera get/set) + updated help text mentioning remote use.
  • occt_view.*: Added fit_all() implementation.
  • scripts/remote_ezy_client.py: Reference client for sending Python code.
  • agents/dev.md: Added detailed usage, launch instructions (important: correct cwd for resources), testing steps, and verification.
  • Supporting fixes: socket type handling on Windows, debug prints with WSA error codes, Python init robustness, resource path / cwd handling.
  • Related doc/CI/IDE updates from the branch history.

Usage

# Launch GUI + server
EzyCad.exe --listen 127.0.0.1:8765

# In another terminal
python scripts/remote_ezy_client.py --host 127.0.0.1 --port 8765

# Then send code (blank line to execute)
view.fit_all()
ezy.msg("Hello from remote!")
print("Shapes:", view.shape_count())

The same bindings available in the in-app Python console work remotely. Execution is safe and queued.

Motivation

Enables automation, remote control, external scripting, integration with other tools/web UIs, batch processing, etc., while preserving the full interactive GUI experience.

Status / Testing

  • Listener starts successfully when launched with correct working directory (resources like icons) and after a full rebuild.
  • Client connects and can execute code affecting the live view/model.
  • Debug output helps diagnose socket issues (common on Windows).
  • Python early-init shows a benign "platform independent libraries" warning (harmless for the TCP listener; execution reuses the interpreter).
  • See agents/dev.md for detailed local testing instructions.

Closes #118

Next steps / future work

  • Full --headless mode (no GUI window).
  • More high-level API exposure / structured RPC option as alternative to raw code.
  • Security (auth, localhost default, sandboxing for remote code exec).
  • Offscreen rendering for remote screenshots / view streaming.
  • Better Python home / stdlib handling for embedded use.
  • CI tests for the server path.

Ready for review!

Trailcode Agent added 3 commits June 7, 2026 16:20
…ations

- New RemotePythonServer with PythonExecutionQueue for thread-safe execution on main thread (OCCT/GUI safety).
- TCP listener (port configurable via --listen [host:]port), accepts Python code snippets, executes in embedded interpreter with existing ezy/view/Shp bindings.
- CLI support in main: --listen, --headless (parsed).
- Early Python init when server enabled for remote use.
- Extended Python bindings (fit_all, screenshot, get_shape, get_camera, set_camera, etc.) and help text.
- Added fit_all() to Occt_view.
- Reference client script.
- Updated agents/dev.md with usage and testing instructions.
- Debug prints and error handling for socket issues.
- Fixes for build (socket types, const error, etc.).

This allows external Python scripts to control the running EzyCad instance (GUI or headless) for automation, remote control, etc.

Refs: conversation on dual app+server mode.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add remote Python TCP server for controlling the app, view, and operations

1 participant