|
| 1 | +# YourApp Starter Beginner Field Guide |
| 2 | + |
| 3 | +Welcome! This all-in-one tutorial is for beginning programmers who know a bit of Python and want to ship a polished desktop app without wading through advanced docs. Work through it front to back or hop around using the Table of Contents—each section is self-contained and links to the deeper references when you're ready. |
| 4 | + |
| 5 | +## Table of Contents {#table-of-contents} |
| 6 | +1. [Welcome to YourApp Starter](#welcome) |
| 7 | +2. [How to Use This Guide](#guide-map) |
| 8 | +3. [Template Highlights at a Glance](#template-highlights) |
| 9 | +4. [Set Up Your Local Environment](#setup) |
| 10 | +5. [Install the Packaged Build](#installer) |
| 11 | +6. [Launchers, Frontends, and Shortcuts](#frontends) |
| 12 | +7. [Architecture Walkthrough](#architecture) |
| 13 | +8. [Configuration & Theming](#configuration) |
| 14 | +9. [Customize the Template Step by Step](#customizing) |
| 15 | +10. [Automation & Headless Workflows](#automation) |
| 16 | +11. [Build, Package, and Distribute](#build-release) |
| 17 | +12. [Testing & Quality Gates](#testing) |
| 18 | +13. [CI/CD & Release Automation](#cicd) |
| 19 | +14. [Troubleshooting & FAQ](#troubleshooting) |
| 20 | +15. [Next Steps & Additional Resources](#next-steps) |
| 21 | + |
| 22 | +--- |
| 23 | + |
| 24 | +## 1. Welcome to YourApp Starter {#welcome} |
| 25 | +YourApp Starter is a CustomTkinter-based template that shows how to ship a Windows-friendly desktop app with multiple launchers, automated installers, and docs-first guidance. It still looks like Tic Tac Toe out of the box, but the real goal is giving you a neutral codebase where you can plug in your own business rules without guessing how things hang together. For quick context, skim the project overview in `README.md` (see [README – Project Goals](../README.md#-project-goals)). |
| 26 | + |
| 27 | +> _Screenshot placeholder: hero shot of the CustomTkinter window + CLI side by side so viewers can see both frontends._ |
| 28 | +
|
| 29 | +[Back to TOC](#table-of-contents) |
| 30 | + |
| 31 | +## 2. How to Use This Guide {#guide-map} |
| 32 | +- **Beginners first:** Every section explains why something exists before diving into file paths. |
| 33 | +- **Doc cross-links everywhere:** If you need a deeper dive, follow the inline links to `docs/*.md`. Advanced contributors can still stick with the original documentation set. |
| 34 | +- **Screenshot placeholders:** Drop visuals wherever you see "Screenshot placeholder" callouts when you're ready to capture your own screenshots. |
| 35 | +- **Return path:** Every section ends with a "Back to TOC" link so you can bounce around without losing your spot. |
| 36 | + |
| 37 | +[Back to TOC](#table-of-contents) |
| 38 | + |
| 39 | +## 3. Template Highlights at a Glance {#template-highlights} |
| 40 | +Why teams adopt this starter (see [README – Template Highlights](../README.md#-template-highlights)): |
| 41 | +- **One entry point, many frontends:** `python -m tictactoe` dispatches GUI, CLI, headless, or service modes from `src/tictactoe/__main__.py`. |
| 42 | +- **Typed configuration:** `src/tictactoe/config/gui.py` keeps fonts, colors, layout, and copy as immutable dataclasses. |
| 43 | +- **Installer + launcher duo:** `wheel-builder.bat` generates `installation.bat`, `tic-tac-toe-starter.vbs`, helper docs, and the signed wheel bundle under `dist/`. |
| 44 | +- **Headless-friendly testing:** `tictactoe.ui.gui.headless_view` mirrors the CustomTkinter widgets so GUI tests run inside CI (documented in `docs/TESTING.md`). |
| 45 | +- **Docs-first approach:** `docs/TEMPLATE-USAGE-GUIDE.md` and `docs/TEMPLATE-CHECKLIST.md` walk you through adopting the template in a specific order. |
| 46 | + |
| 47 | +> _Screenshot placeholder: collage of `dist/` folder, installer console, and desktop shortcut._ |
| 48 | +
|
| 49 | +[Back to TOC](#table-of-contents) |
| 50 | + |
| 51 | +## 4. Set Up Your Local Environment {#setup} |
| 52 | +Everything below is straight from `README.md` plus `docs/TEMPLATE-USAGE-GUIDE.md` Section 2. |
| 53 | + |
| 54 | +1. **Clone and open the repo** |
| 55 | + ```pwsh |
| 56 | + git clone <your-fork-url> |
| 57 | + cd python-gui-project-template |
| 58 | + ``` |
| 59 | +2. **Create a virtual environment** (mirrors what the installer does): |
| 60 | + ```pwsh |
| 61 | + python -m venv .venv |
| 62 | + .\.venv\Scripts\Activate.ps1 |
| 63 | + ``` |
| 64 | +3. **Install the editable package + dev tools** (requirements already end with `-e .`): |
| 65 | + ```pwsh |
| 66 | + pip install -r requirements.txt |
| 67 | + ``` |
| 68 | +4. **Launch the sample app**: |
| 69 | + ```pwsh |
| 70 | + python -m tictactoe |
| 71 | + ``` |
| 72 | +5. **List frontends** if you want to test the CLI or headless adapter: |
| 73 | + ```pwsh |
| 74 | + python -m tictactoe --list-frontends |
| 75 | + ``` |
| 76 | + |
| 77 | +Tip: keep `pwsh` terminals handy so PowerShell-specific scripts such as `wheel-builder.bat` and `scripts/run-ci.ps1` run without quoting gymnastics. |
| 78 | + |
| 79 | +> _Screenshot placeholder: terminal session showing the activation + pip install + first run output._ |
| 80 | +
|
| 81 | +[Back to TOC](#table-of-contents) |
| 82 | + |
| 83 | +## 5. Install the Packaged Build {#installer} |
| 84 | +Want to preview the real installer experience? Follow `docs/INSTALLATION-GUIDE.md`: |
| 85 | + |
| 86 | +1. **Build artifacts** (or download a release ZIP): |
| 87 | + ```pwsh |
| 88 | + .\wheel-builder.bat |
| 89 | + ``` |
| 90 | +2. **Extract `dist/`** somewhere safe and double-click `installation.bat`. |
| 91 | +3. The script will: |
| 92 | + - Delete previous installs (`%LOCALAPPDATA%\Programs\yourapp-starter-<version>`), |
| 93 | + - Create a private `.venv`, |
| 94 | + - Install the wheel, |
| 95 | + - Run `python -m tictactoe --ui service --script 0,4,8 --quiet`, |
| 96 | + - Drop `YourApp Starter.lnk` on the desktop via the VBScript launcher. |
| 97 | +4. Launch from the shortcut (uses `pythonw.exe` so no console window pops up). |
| 98 | + |
| 99 | +For an under-the-hood blow-by-blow, read `docs/INSTALLATION-TECHNICAL-DETAILS.md`—it covers everything from registry lookups for OneDrive desktops to how AppUserModelIDs keep icons tidy. |
| 100 | + |
| 101 | +> _Screenshot placeholder: SmartScreen prompt and installer console log._ |
| 102 | +
|
| 103 | +[Back to TOC](#table-of-contents) |
| 104 | + |
| 105 | +## 6. Launchers, Frontends, and Shortcuts {#frontends} |
| 106 | +`src/tictactoe/__main__.py` registers four `FrontendSpec` entries: |
| 107 | + |
| 108 | +| Name | Target | When to use | |
| 109 | +| --- | --- | --- | |
| 110 | +| `gui` | `tictactoe.ui.gui.main:main` | CustomTkinter desktop app (default). |
| 111 | +| `headless` | same target, but forces `TICTACTOE_HEADLESS=1` | GUI widgets rendered by the shim, perfect for CI. |
| 112 | +| `cli` | `tictactoe.ui.cli.main:main` | Automation-friendly terminal client with `--script`/`--script-file`. |
| 113 | +| `service` | `tictactoe.ui.service.main:main` | Headless/batch runner driven entirely by env vars. |
| 114 | + |
| 115 | +Launch options (defaults shown in `README.md#choose-a-frontend`): |
| 116 | +```pwsh |
| 117 | +python -m tictactoe --ui gui --theme dark # Named theme |
| 118 | +python -m tictactoe --ui headless # Same GUI, shim widgets |
| 119 | +python -m tictactoe --ui cli --script 0,4,8 # Scripted CLI run |
| 120 | +python -m tictactoe --ui service --quiet # Installer/CI style |
| 121 | +``` |
| 122 | +Environment fallbacks keep installers and CI simple: |
| 123 | +- `TICTACTOE_UI`, `TICTACTOE_HEADLESS`, `TICTACTOE_THEME*` |
| 124 | +- `TICTACTOE_SCRIPT`, `TICTACTOE_SCRIPT_FILE`, `TICTACTOE_AUTOMATION_*` |
| 125 | +- `TICTACTOE_LOGGING` (plus legacy `*_LOGGING`) enabling telemetry hooks defined in `src/tictactoe/controller/__init__.py`. |
| 126 | + |
| 127 | +> _Screenshot placeholder: `python -m tictactoe --list-frontends` output next to the desktop shortcut properties dialog._ |
| 128 | +
|
| 129 | +[Back to TOC](#table-of-contents) |
| 130 | + |
| 131 | +## 7. Architecture Walkthrough {#architecture} |
| 132 | +Use this section as your quick-reference script when explaining the template to teammates (full details live in `docs/ARCHITECTURE.md`). |
| 133 | + |
| 134 | +1. **Entry Points (`python -m tictactoe`)** select a frontend via CLI flags or env vars. |
| 135 | +2. **Frontends:** |
| 136 | + - GUI (`src/tictactoe/ui/gui/main.py`) instantiates `TicTacToeGUI`, loads CustomTkinter via `ui/gui/bootstrap.py`, and can swap to `HeadlessGameView` for tests. |
| 137 | + - CLI (`src/tictactoe/ui/cli/main.py`) renders placeholder automation summaries and supports JSON exports. |
| 138 | + - Service (`src/tictactoe/ui/service/main.py`) reuses the CLI automation helpers but reads env vars for scripts and labels. |
| 139 | +3. **Controller hooks** (`src/tictactoe/controller/__init__.py`) centralize telemetry/logging so every frontend can emit consistent events. |
| 140 | +4. **Domain layer** (`src/tictactoe/domain/logic.py`) ships as a stub with `ExampleState` snapshots and a `dispatch_action` method that you replace with real business logic. |
| 141 | +5. **Config layer** (`src/tictactoe/config/gui.py`) contains immutable dataclasses plus `NAMED_THEMES`, serialization helpers, and JSON loaders. |
| 142 | +6. **Assets & tools:** `src/tictactoe/assets/` for icons/themes and `src/tictactoe/tools/theme_codegen.py` for converting JSON themes into typed configs. |
| 143 | +7. **Installer pipeline:** `wheel-builder.bat` → `dist/installation.bat` + VBScript launcher + helper docs. |
| 144 | + |
| 145 | +> _Screenshot placeholder: architecture block diagram showing entry point → frontends → domain/config → installer._ |
| 146 | +
|
| 147 | +[Back to TOC](#table-of-contents) |
| 148 | + |
| 149 | +## 8. Configuration & Theming {#configuration} |
| 150 | +Everything visual lives in `src/tictactoe/config/gui.py` (see `docs/CONFIGURATION.md`). The important bits: |
| 151 | +- **`WindowConfig`** controls title, geometry, and resizability. |
| 152 | +- **`GameViewConfig`** bundles fonts, layout, strings, and colors via nested dataclasses. |
| 153 | +- **`NAMED_THEMES`** exposes `default`, `light`, `dark`, and `enterprise` presets plus helpers (`get_theme`, `list_themes`). |
| 154 | +- **JSON round-tripping:** `serialize_game_view_config()` + `deserialize_game_view_config()` let you edit JSON themes under `src/tictactoe/assets/themes/` and load them at runtime. |
| 155 | +- **CLI hooks:** `python -m tictactoe --theme dark` or `--theme-file path/to/theme.json` injects payloads through `TICTACTOE_THEME_PAYLOAD`. |
| 156 | +- **Dataclass generation:** convert JSON to Python with `python -m tictactoe.tools.theme_codegen src/tictactoe/assets/themes/dark.json --variable-prefix brand`. |
| 157 | + |
| 158 | +> _Screenshot placeholder: side-by-side view of light vs dark theme plus a snippet of the JSON payload._ |
| 159 | +
|
| 160 | +[Back to TOC](#table-of-contents) |
| 161 | + |
| 162 | +## 9. Customize the Template Step by Step {#customizing} |
| 163 | +Follow `docs/TEMPLATE-CHECKLIST.md` for a linear adoption flow: |
| 164 | + |
| 165 | +1. **Rename everything** |
| 166 | + - Update `[project]` metadata inside `pyproject.toml`. |
| 167 | + - Rename `src/tictactoe` to your package name and fix imports. |
| 168 | + - Refresh README hero copy and badges. |
| 169 | +2. **Adjust config + assets** |
| 170 | + - Edit `tictactoe.config.gui` or drop new JSON themes. |
| 171 | + - Swap icons or additional files in `src/tictactoe/assets/` (wheel-builder copies the entire folder). |
| 172 | +3. **Replace the domain placeholder** |
| 173 | + - Implement `TicTacToe.dispatch_action` (or rename the class) so the GUI/CLI keep receiving `ExampleState`-like snapshots. |
| 174 | + - Update tests in `tests/test_logic.py` to describe your real rules. |
| 175 | +4. **Retheme the frontends** |
| 176 | + - Update copy/layout in `tictactoe/ui/gui/view.py` and `tictactoe/ui/gui/main.py` while leaving `HeadlessGameView` intact. |
| 177 | + - Rewrite CLI prompts or automation metadata in `tictactoe/ui/cli/main.py`. |
| 178 | +5. **Keep quality gates green** |
| 179 | + - Re-run `pwsh scripts/run-ci.ps1` after every big change to mirror the CI workflow. |
| 180 | +6. **Regenerate installers + docs** |
| 181 | + - Rebuild via `wheel-builder.bat`. |
| 182 | + - Update `docs/INSTALLATION-GUIDE.md`, `docs/INSTALLER-CUSTOMIZATION.md`, and `docs/RELEASE.md` with your new product name and flows. |
| 183 | + |
| 184 | +> _Screenshot placeholder: checklist with checkmarks showing rename → config → UI → installer → docs._ |
| 185 | +
|
| 186 | +[Back to TOC](#table-of-contents) |
| 187 | + |
| 188 | +## 10. Automation & Headless Workflows {#automation} |
| 189 | +Need scripted runs or CI demos without a GUI? Lean on the CLI + service pair from `README.md#choose-a-frontend` and `docs/TEMPLATE-USAGE-GUIDE.md#5-leverage-the-multi-frontend-entry-point`. |
| 190 | + |
| 191 | +- **CLI mode (`tictactoe.ui.cli.main`)** |
| 192 | + ```pwsh |
| 193 | + python -m tictactoe.ui.cli.main --script 0,4,8 --output-json artifacts\automation.json --label nightly-demo |
| 194 | + ``` |
| 195 | + Produces a human-readable summary plus optional JSON file and emits controller telemetry if `TICTACTOE_CLI_LOGGING=1`. |
| 196 | +- **Service mode (`tictactoe.ui.service.main`)** consumes env vars: |
| 197 | + ```pwsh |
| 198 | + $env:TICTACTOE_SCRIPT = "0,4,8" |
| 199 | + $env:TICTACTOE_AUTOMATION_OUTPUT = "$PWD\artifacts\service.json" |
| 200 | + python -m tictactoe --ui service --quiet |
| 201 | + ``` |
| 202 | +- **Headless GUI** just works by launching `python -m tictactoe --ui headless` or setting `TICTACTOE_HEADLESS=1`; the shim lives in `tictactoe/ui/gui/headless_view.py`. |
| 203 | +- **Telemetry hooks** (see `tictactoe/controller/__init__.py`) let every frontend log events once you flip `TICTACTOE_LOGGING=1`—great for installers or automated smoke tests. |
| 204 | + |
| 205 | +> _Screenshot placeholder: log output from CLI automation plus a JSON summary snippet._ |
| 206 | +
|
| 207 | +[Back to TOC](#table-of-contents) |
| 208 | + |
| 209 | +## 11. Build, Package, and Distribute {#build-release} |
| 210 | +`docs/RELEASE.md` and `docs/INSTALLER-CUSTOMIZATION.md` cover the production-ready workflow. The short version: |
| 211 | + |
| 212 | +1. **Run local CI** first: |
| 213 | + ```pwsh |
| 214 | + pwsh scripts\run-ci.ps1 |
| 215 | + ``` |
| 216 | +2. **Build artifacts**: |
| 217 | + ```pwsh |
| 218 | + .\wheel-builder.bat --ci --no-pause # CI-style: installs into %TEMP% |
| 219 | + .\wheel-builder.bat # Interactive local build |
| 220 | + ``` |
| 221 | + Outputs `dist/` with: |
| 222 | + - `tictactoe-<version>-py3-none-any.whl` |
| 223 | + - `installation.bat` |
| 224 | + - `tic-tac-toe-starter.vbs` |
| 225 | + - `assets/`, `how-to-install-me.txt`, `license.txt`, `install-info.json` |
| 226 | +3. **Customize installers** by editing `wheel-builder.bat` (shortcut names, icons, install root, offline mode). Regenerate scripts after every change. |
| 227 | +4. **Smoke test** the generated installer on a clean Windows profile. |
| 228 | +5. **Zip and publish** `dist/` as the release payload (see `docs/RELEASE.md#6-publish-github-release`). |
| 229 | + |
| 230 | +> _Screenshot placeholder: PowerShell transcript from `wheel-builder.bat` plus the resulting `dist/` explorer window._ |
| 231 | +
|
| 232 | +[Back to TOC](#table-of-contents) |
| 233 | + |
| 234 | +## 12. Testing & Quality Gates {#testing} |
| 235 | +Everything you need lives in `docs/TESTING.md`, but here are the highlights: |
| 236 | + |
| 237 | +- **pytest markers** split GUI vs non-GUI tests (`tests/test_gui.py` is headless-ready): |
| 238 | + ```pwsh |
| 239 | + python -m pytest -m "not gui" |
| 240 | + python -m pytest -m gui |
| 241 | + ``` |
| 242 | +- **Quality stack** (Black, Ruff, Mypy) matches what `scripts/run-ci.ps1` runs. |
| 243 | +- **Sample suites:** |
| 244 | + - `tests/test_logic.py` documents the placeholder domain behavior. |
| 245 | + - `tests/test_cli.py` covers the multi-frontend dispatcher + CLI helpers. |
| 246 | + - `tests/test_config.py` guards exported symbols. |
| 247 | + - `tests/test_theme_codegen.py` keeps the JSON↔dataclass tooling solid. |
| 248 | +- **Headless GUI testing** uses `tictactoe.ui.gui.headless_view.HeadlessGameView` so CustomTkinter widgets can be "rendered" without Tk. |
| 249 | +- **Coverage** is optional but easy: `python -m pytest --cov=tictactoe --cov-report=term-missing`. |
| 250 | +- **Helper commands** (from `docs/TESTING.md#16-quick-reference-commands`) keep newcomers productive. |
| 251 | + |
| 252 | +> _Screenshot placeholder: VS Code test explorer or pytest output highlighting GUI vs non-GUI markers._ |
| 253 | +
|
| 254 | +[Back to TOC](#table-of-contents) |
| 255 | + |
| 256 | +## 13. CI/CD & Release Automation {#cicd} |
| 257 | +`docs/CI-CD.md` pairs with `scripts/run-ci.ps1` / `scripts/run-ci.sh` and the existing GitHub Actions workflow. |
| 258 | + |
| 259 | +- **Local rehearsal:** |
| 260 | + ```pwsh |
| 261 | + pwsh scripts\run-ci.ps1 -SkipRequirementsInstall |
| 262 | + ``` |
| 263 | +- **What the script runs:** editable install, Black, Ruff, Mypy, `pytest -m "not gui"`, GUI-only pytest, then installer smoke tests (Windows) or sandboxed wheel installs (POSIX). |
| 264 | +- **GitHub Actions:** `.github/workflows/ci.yml` mirrors the same steps (lint, type, pytest, build wheel). Use the sample matrix in `docs/CI-CD.md` if you want tox-driven jobs. |
| 265 | +- **Release workflow:** `docs/RELEASE.md` describes tagging, uploading `dist/`, and notifying users. When you need extra installer tweaks, capture them in `docs/INSTALLER-CUSTOMIZATION.md` for future maintainers. |
| 266 | + |
| 267 | +> _Screenshot placeholder: CI pipeline diagram or GitHub Actions run summary._ |
| 268 | +
|
| 269 | +[Back to TOC](#table-of-contents) |
| 270 | + |
| 271 | +## 14. Troubleshooting & FAQ {#troubleshooting} |
| 272 | +Common issues and quick fixes (see `docs/TROUBLESHOOTING.md` for the full FAQ): |
| 273 | +- **Virtual environment fails:** Install Python 3.8+ with "Add to PATH" and delete partially created `.venv/` directories before retrying. |
| 274 | +- **`pip install` blocked:** Pre-download wheels and add `--no-index --find-links`, covered in `docs/INSTALLER-CUSTOMIZATION.md`. |
| 275 | +- **CustomTkinter / Tcl errors:** Force headless mode with `TICTACTOE_HEADLESS=1` or install the Tk runtime. |
| 276 | +- **OneDrive desktop confusion:** The installer reads the registry path automatically; as a fallback, manually create a shortcut to `%LOCALAPPDATA%\Programs\yourapp-starter-<version>\tic-tac-toe-starter.vbs`. |
| 277 | +- **Shortcut still says Tic Tac Toe:** Regenerate installers after editing `wheel-builder.bat` so the VBScript + `.lnk` pick up the new names. |
| 278 | + |
| 279 | +> _Screenshot placeholder: snippet of `docs/TROUBLESHOOTING.md` or an error dialog with a fix overlay._ |
| 280 | +
|
| 281 | +[Back to TOC](#table-of-contents) |
| 282 | + |
| 283 | +## 15. Next Steps & Additional Resources {#next-steps} |
| 284 | +Here’s where to go once you finish this guide: |
| 285 | +- **Deep dives:** |
| 286 | + - Architecture: `docs/ARCHITECTURE.md` |
| 287 | + - Configuration & theming: `docs/CONFIGURATION.md` |
| 288 | + - Installer internals: `docs/INSTALLATION-TECHNICAL-DETAILS.md` |
| 289 | + - Template adoption story: `docs/TEMPLATE-USAGE-GUIDE.md` + `docs/TEMPLATE-CHECKLIST.md` |
| 290 | +- **Stretch goals:** `docs/IMPROVEMENTS.md` tracks future-ready enhancements (e.g., telemetry, new themes, release automation). |
| 291 | +- **Release playbook:** `docs/RELEASE.md` for tagging, smoke testing, and publishing zipped installers. |
| 292 | +- **Community help:** capture your own FAQs or gotchas inside `docs/TROUBLESHOOTING.md` so the next teammate has zero surprises. |
| 293 | + |
| 294 | +> _Screenshot placeholder: summary graphic highlighting the key links + "Happy Building!" message._ |
| 295 | +
|
| 296 | +[Back to TOC](#table-of-contents) |
0 commit comments