Repository navigation
Add RenderWindow class and use it for main.py's window and render loop - #10
Conversation
RenderWindow class to manage Pygame initialization
dmccoystephenson
left a comment
There was a problem hiding this comment.
@copilot The new class does not appear to be used anywhere
Added usage examples in |
|
Self-review rubric (dev-loop adoption of this draft PR):
No functional changes were made to the copilot-authored implementation — the branch was rebased onto current One blocker for merge: this PR is still marked Draft. drafted by Claude on behalf of Daniel Stephenson |
|
A status update is provided on the two outstanding blockers for this PR. The The PR also remains marked as a Draft. No code changes were made in this pass; prior test coverage and self-review (see above) are believed to still hold, since no new commits landed on this PR since they were posted. This PR comment was drafted during a Gardener session (https://github.com/Stephenson-Software/gardener). |
There was a problem hiding this comment.
Pull request overview
This pull request introduces a new RenderWindow utility to centralize Pygame initialization, window/surface management, event processing, and frame-rate control, with supporting documentation and examples to encourage composition-based usage across the codebase (and downstream projects like Apex).
Changes:
- Added
RenderWindowimplementation with an event-handler registration API and internal QUIT handling. - Added unit tests validating window setup, tick delegation, and event dispatch behavior.
- Added documentation and an examples script demonstrating basic usage and integration patterns.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
render_window.py |
Implements the new RenderWindow class and its event loop/handler dispatch. |
tests/test_render_window.py |
Adds unit tests for initialization, ticking, and event/QUIT behavior. |
render_window_example.py |
Provides runnable examples showing basic usage, handler registration, and integration with Graphik. |
README.md |
Documents RenderWindow features and basic usage. |
.gitignore |
Ignores __pycache__/ directories. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
|
||
| self.assertFalse(result) | ||
|
|
||
| def test_register_event_handler_not_called_for_quit(self): |
| for event in pygame.event.get(): | ||
| if event.type == pygame.QUIT: | ||
| self._running = False | ||
| else: | ||
| # Call all registered event handlers | ||
| for handler in self._event_handlers: | ||
| handler(event) | ||
|
|
||
| return self._running |
Co-authored-by: dmccoystephenson <21204351+dmccoystephenson@users.noreply.github.com>
Co-authored-by: dmccoystephenson <21204351+dmccoystephenson@users.noreply.github.com>
Co-authored-by: dmccoystephenson <21204351+dmccoystephenson@users.noreply.github.com>
Introduces this repo's first tests/ directory. Covers init, tick, event dispatch, and QUIT handling for the RenderWindow class added in this PR, without opening a real display. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Co-authored-by: dmccoystephenson <21204351+dmccoystephenson@users.noreply.github.com>
c445df2 to
fc79844
Compare
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Review of PR #10 (rebased and re-validated)This PR was adopted from a previous cycle. It was What was done in this pass
Validation performed
Rubric
Findings
Outstanding blocker: the
|
…r protocol RenderWindow called pygame.init() in its constructor but exposed no matching teardown, so every caller had to reach past the class and call pygame.quit() itself. close() now performs that teardown and marks the window as no longer running, and __enter__/__exit__ let a with-statement guarantee it even when the loop body raises. should_continue() short-circuits on a closed window rather than polling pygame.event.get(), which would otherwise raise once the video system has been shut down. Closes #16 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The blocking review on this branch observed that RenderWindow was not used anywhere. main.py now constructs one instead of calling pygame.init(), pygame.display.set_mode() and pygame.display.set_caption() directly, hands get_surface() to Graphik, drives the render loop with should_continue(), and tears down with close() on every exit path. The loop no longer calls the builtin quit() on a QUIT event, so closing the window unwinds main() normally instead of raising SystemExit. render_window_example.py is removed: main.py is now the in-tree integration example it described hypothetically, and README carries the standalone API snippet. Closes #15 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Self-review — dev-loop cycle that folded #15 and #16 into this branchTwo commits were added on top of Rubric
Substitute validation that was performedA headless harness was run under
This exercises the refactored code paths but is not a substitute for the live anchor, Findings folded in from the diff
Outstanding blocker from a previous reviewThe Deferred this cycle
This review was drafted during a Gardener session (https://github.com/Stephenson-Software/gardener). drafted by Claude on behalf of Daniel Stephenson |
Cycle status — re-verification of this PR, no new commitsNo implementation work was added to this branch during this cycle. What follows records what Re-poll for review (no change)No reviewer activity has occurred since the self-review of 2026-08-26. The Mergeability (unchanged, still clean)The branch reports Live anchor (still cannot be run — re-confirmed, not assumed)The live anchor for this repository is
Since this PR changes rendering and service-call code, the anchor is required by the loop's The substitute evidence described in the 2026-08-26 self-review (a headless harness under Backlog handled this cycleThree previously untracked defects were found during triage, verified against source, and
Deferred, with reasons
This comment was drafted during a Gardener session (https://github.com/Stephenson-Software/gardener). drafted by Claude on behalf of Daniel Stephenson |
Overview
A
RenderWindowclass is added to encapsulate Pygame initialization, window andsurface management, event dispatch, frame-rate control and teardown.
main.pyisrefactored to use it, so the class is exercised by the repository's own entry point
rather than only by a standalone demo.
This branch was originally opened by the Copilot coding agent for issue #6 and has
since been adopted by the dev loop; the two follow-up gaps found while reviewing it
(#15 and #16) are now folded in, which is what the blocking review on this branch
asked for.
What changed
render_window.pyRenderWindow(title, width, height)performspygame.init(), creates the displaysurface and sets the caption.
get_surface(),tick(fps),should_continue()andregister_event_handler(handler)are exposed.QUITis handled internally and isnot forwarded to registered handlers.
close()tears the window down and marks it as no longer running;__enter__/__exit__make the same teardown available through awith-statement, withoutsuppressing exceptions.
should_continue()short-circuits on a closed window instead of pollingpygame.event.get(), which raises once the video system has been shut down.main.pypygame.init(),pygame.display.set_mode(...)andpygame.display.set_caption(...)are replaced by a single
RenderWindowconstruction, whoseget_surface()is handedto
Graphik.while window.should_continue():rather than ahand-rolled
for event in pygame.event.get()/pygame.QUITblock.window.close()in place of a directpygame.quit(). Closingthe window now unwinds
main()normally instead of raisingSystemExitthrough thebuiltin
quit().Documentation and tests
README.mddocumentsclose()and the context-manager form, and points atmain.pyas the in-tree integration example.
render_window_example.pyis removed. Itsintegration_exampledocstring describedthe
main.pyrefactor as hypothetical, which this PR makes real; the standalone APIsnippet it carried now lives in
README.md.tests/test_render_window.pyis this repository's first test suite. Pygame is fullymocked, so neither a display nor a running Viron server is required.
.gitignoreexcludes__pycache__/.Test plan
python3 -m py_compile main.py graphik.py __init__.py render_window.py— clean.python -m unittest discover -s tests— 9 tests, all passing.test_should_continue_false_after_close_without_polling_eventsfails; with itrestored, it passes.
main.pyunderSDL_VIDEODRIVER=dummy,with the Viron services stubbed: the create-and-exit path, the cached-environment
load path and the interactive render loop were each exercised. Three frames were
rendered before a synthetic
QUITevent, after which the loop terminated andpygame.get_init()reportedFalse, andenvironments.jsonwas written with theexpected
1x10key.python main.py 10 --exit-after-createagainst areal Viron server on
http://localhost:9999was not exercised, because Docker isunavailable in the environment this branch was worked in and the vendored Viron
Python sources require Python 3.9+ (the interpreter available was 3.8). This PR
changes rendering and service-call code, so that anchor is UNVERIFIED and a
human with a working Viron instance is asked to confirm it before merge.
Deferred this cycle
.github/workflows/andbecause a second PR could not be opened while this one is in flight.
unrelated to the window-management subsystem this PR touches.
Closes #6
Closes #15
Closes #16
This PR description was drafted during a Gardener session (https://github.com/Stephenson-Software/gardener).