Add on-canvas page counter with luminance-based color - #53
Conversation
Render a current/total fraction in the bottom-right of the canvas. The counter text auto-flips between black and white based on a luminance sample of the displayed page so it stays legible against both light and dark art. Hidden on text/info-overlay pages, single-page sources, and when no source is loaded. Covered by 17 new tests in tests/test_page_counter.py. Coverage remains at the pre-change 95.79% baseline.
|
Warning Review limit reached
Next review available in: 42 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. 📝 WalkthroughWalkthroughChangesThe viewer adds a bottom-right current/total page counter for multi-page image content. It selects black or white text from page luminance, updates the counter across image rendering paths, clears it for text and info pages, documents the feature, and adds comprehensive tests. Page counter overlay
Sequence Diagram(s)sequenceDiagram
participant ComicViewer
participant PageSource
participant Canvas
ComicViewer->>PageSource: read current page and total page count
ComicViewer->>Canvas: render current image
ComicViewer->>Canvas: create or replace page counter
ComicViewer->>Canvas: clear counter for text or info-overlay pages
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@cdisplayagain.py`:
- Around line 1272-1305: Update _update_page_counter to call _clear_page_counter
at the start instead of duplicating the page-counter deletion and
exception-handling logic. Preserve the existing behavior of resetting
_page_counter_id before rendering or returning when no text is available.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 5fbb6e37-a216-4662-98e5-3b51fe162bf8
📒 Files selected for processing (3)
cdisplayagain.pydocs/PARITY.mdtests/test_page_counter.py
Summary
Adds an on-canvas page counter that renders a
current/totalfraction in the bottom-right of the canvas. Text color auto-flips between black and white based on the mean luminance of the displayed page so it stays legible against both light and dark art.Behavior
N/T(e.g.1/32on the first page,32/32on the last).canvas.delete("all")paths reset the counter id.Implementation
self._page_counter_idstate alongside the existing canvas image id._page_counter_text()returns the fraction orNoneto hide._page_counter_color()downscales the current PIL image to 32x32 grayscale and usesPIL.ImageStat.Statfor the mean luminance._update_page_counter()creates/replaces acanvas.create_textitem at the bottom-right anchor._clear_page_counter()removes the item safely (swallowsTclError)._display_cached_image,_display_image_fast, plus no-source/info-overlay branches in_render_current,_render_current_sync, and_render_info_with_image.Testing
tests/test_page_counter.py(17 tests): counter renders, updates acrossnext_page, hides on text/info pages, color flips correctly on dark vs light pages, defaults to white without PIL, suppresses on single-page sources, handles stale ids, and clears on no-source render paths.make lint): clean.Docs
docs/PARITY.mdunder the "Completed Parity" → "Navigation" section, treated as CDisplay parity per design decision.Summary by CodeRabbit
New Features
Documentation
Tests