# HPGL Plotter Web UI Flask web interface for uploading HPGL files, previewing and transforming them (flip, rotate, scale, center), and sending to the plotter. Intended to run on a Raspberry Pi connected to the plotter via USB. ## Setup (Raspberry Pi / Linux Mint / Debian) From the **project root** (mimaki/), install dependencies. On Debian-based systems Python is externally managed (PEP 668), so use: ```bash pip install --break-system-packages -r webui/requirements.txt ``` Then copy `config.example.ini` to `config.ini` and set the plotter port etc. (optional). ```bash cp config.example.ini config.ini ``` Edit `config.ini` to set the plotter port (e.g. `/dev/ttyUSB0`) and optionally web UI port/host. ## Run From the **project root** (mimaki/): ```bash python webui/app.py ``` Then open http://localhost:5000 (or http://<raspi-ip>:5000 from another device). Host is `0.0.0.0`, port 5000 (see `config.ini`). For production with gunicorn: `pip install --break-system-packages gunicorn` then `gunicorn -w 1 -b 0.0.0.0:5000 "webui.app:app"`. ## Usage **File tab** 1. **Upload** – Choose an `.hpgl` or `.plt` file. It is validated and stored in `webui/uploads/`. 2. **Preview** – The drawing is converted to SVG and shown in the browser. 3. **Transform** – Flip, Rotate 90° / 180°, Scale + / −, Center, Scale to bounds. Each action updates the stored program and the preview. 4. **Print** – Sends the current (transformed) program to the plotter: scale to fit, center, then write HPGL to serial. **Text tab** 1. Type text, select a font (from `font/` or `.git/font/`, e.g. `Melange-Bold.otf`), set size (pt), then **Generate HPGL**. 2. The generated HPGL becomes the current program; use the same **Preview**, **Transform**, and **Print** as in the File tab. Fonts: put `.otf` or `.ttf` files in the project `font/` folder (or they are read from `.git/font/` if present). The Text tab requires **matplotlib** (`pip install matplotlib`). ## API - `POST /api/upload` – Upload HPGL file (form field `file`). - `GET /api/svg` – Get current program as SVG (query: `width`, `height`). - `POST /api/transform` – Body: `{"action": "flip"|"rotate"|"scale"|"centralize", "angle": 90, "factor": 1.25}`. - `POST /api/print` – Send current program to plotter. - `GET /api/status` – `has_file`, `filename`, `plotter_ready`. Session is used to keep the current file path; no database.