Skip to content

Add on-canvas page counter with luminance-based color - #53

Merged
JoshCLWren merged 2 commits into
mainfrom
feature/page-counter
Jul 27, 2026
Merged

Add on-canvas page counter with luminance-based color#53
JoshCLWren merged 2 commits into
mainfrom
feature/page-counter

Conversation

@JoshCLWren

@JoshCLWren JoshCLWren commented Jul 27, 2026

Copy link
Copy Markdown
Owner

Summary

Adds an on-canvas page counter that renders a current/total fraction 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

  • Format: N/T (e.g. 1/32 on the first page, 32/32 on the last).
  • Color: white text on dark pages (mean luminance < 128), black on light pages.
  • Hidden on text/info-overlay pages, single-page sources, and when no source is loaded.
  • Hidden on info pages rendered alongside a cover (matches the existing info-overlay hide pattern).
  • Re-renders on every page turn; canvas.delete("all") paths reset the counter id.

Implementation

  • self._page_counter_id state alongside the existing canvas image id.
  • _page_counter_text() returns the fraction or None to hide.
  • _page_counter_color() downscales the current PIL image to 32x32 grayscale and uses PIL.ImageStat.Stat for the mean luminance.
  • _update_page_counter() creates/replaces a canvas.create_text item at the bottom-right anchor.
  • _clear_page_counter() removes the item safely (swallows TclError).
  • All four wire-up points: _display_cached_image, _display_image_fast, plus no-source/info-overlay branches in _render_current, _render_current_sync, and _render_info_with_image.

Testing

  • New tests/test_page_counter.py (17 tests): counter renders, updates across next_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.
  • Full suite: 488 tests pass (up from 471); coverage stays at the 95.79% baseline (no regression).
  • Lint (make lint): clean.
  • Tested with .cbz archive (no UI smoke for .cbr needed — feature is rendering-only and uses the same code path as CBZ).

Docs

  • Added to docs/PARITY.md under the "Completed Parity" → "Navigation" section, treated as CDisplay parity per design decision.

Summary by CodeRabbit

  • New Features

    • Added a bottom-right page counter displaying the current page and total pages.
    • Counter automatically hides on text-only, single-page, and information-overlay views.
    • Counter color adjusts between black and white for readability against the page.
  • Documentation

    • Documented the page counter in the feature parity guide.
  • Tests

    • Added coverage for counter visibility, updates, readability, and rendering edge cases.

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.
@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@JoshCLWren, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 42 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 523bedc8-b7d5-4e79-b0f2-8f45508614b3

📥 Commits

Reviewing files that changed from the base of the PR and between b1f5b87 and 64ae07f.

📒 Files selected for processing (1)
  • cdisplayagain.py
📝 Walkthrough

Walkthrough

Changes

The 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

Layer / File(s) Summary
Counter state and appearance
cdisplayagain.py, docs/PARITY.md
ComicViewer tracks the counter canvas item, computes visibility and "{current}/{total}" text, selects luminance-based colors, and documents the overlay.
Rendering path integration
cdisplayagain.py
Cached and fast-preview image rendering updates the counter; text pages, missing sources, and information overlays clear it.
Counter behavior validation
tests/test_page_counter.py
Tests cover visibility, text updates, color fallback, stale canvas items, TclError handling, and rendering cleanup.Estimated code review effort: 3 (Moderate)

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
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 70.59% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding an on-canvas page counter with luminance-based color selection.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/page-counter

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9319449 and b1f5b87.

📒 Files selected for processing (3)
  • cdisplayagain.py
  • docs/PARITY.md
  • tests/test_page_counter.py

Comment thread cdisplayagain.py
@JoshCLWren
JoshCLWren merged commit a5bcda3 into main Jul 27, 2026
7 checks passed
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.

1 participant