fix: single page keeps custom buttons instead of dropping the view (v0.1.2)

a single-page result (max_pages < 2) suppressed the navigation row by dropping the
whole view, which also discarded the consumer's custom per-page buttons. now: if the
page carries custom buttons, keep the view and rebuild with update_buttons(nav=False)
— nav items suppressed, custom buttons kept, and stop() NOT called so their callbacks
still fire. a page with no custom buttons keeps the original drop-the-view behavior.

verified by execution against real discord.py: single page + custom button -> start()
-> callback FIRES on click (view kept, stop() not called); negative control on the old
code drops the button entirely; the no-button single-page case is unregressed.

Signed-off-by: disqualifier <dev@disqualifier.me>
This commit is contained in:
disqualifier 2026-06-29 17:26:04 -04:00
parent bca6b874c6
commit 895ee3bb58
3 changed files with 31 additions and 18 deletions

View File

@ -9,13 +9,13 @@ buttons) behind previous / jump / next navigation, with an optional cache button
`requirements.txt`: `requirements.txt`:
``` ```
dpy_paginator @ git+ssh://git@git.rethinkstudios.io/rethink-public/dpy_paginator.git@v0.1.1 dpy_paginator @ git+ssh://git@git.rethinkstudios.io/rethink-public/dpy_paginator.git@v0.1.2
``` ```
Direct: Direct:
```bash ```bash
pip install "dpy_paginator @ git+ssh://git@git.rethinkstudios.io/rethink-public/dpy_paginator.git@v0.1.1" pip install "dpy_paginator @ git+ssh://git@git.rethinkstudios.io/rethink-public/dpy_paginator.git@v0.1.2"
``` ```
Requires `discord.py` (pulled transitively). Requires `discord.py` (pulled transitively).

View File

@ -4,7 +4,7 @@ build-backend = "hatchling.build"
[project] [project]
name = "dpy_paginator" name = "dpy_paginator"
version = "0.1.1" version = "0.1.2"
description = "Button-navigated paginator for discord.py — config-free, injectable emojis, installable." description = "Button-navigated paginator for discord.py — config-free, injectable emojis, installable."
requires-python = ">=3.10" requires-python = ">=3.10"
dependencies = [ dependencies = [

View File

@ -280,10 +280,16 @@ class ButtonPaginator(Generic[PageT_co], discord.ui.View):
return self._page_kwargs return self._page_kwargs
def update_buttons(self) -> None: def update_buttons(self, nav: bool = True) -> None:
"""rebuild the action row for the current page state""" """rebuild the action row for the current page state
nav=False rebuilds with only the page's custom buttons and no navigation
items (prev/jump/cache/next) a single-page result that still carries
custom buttons keeps them (and their live callbacks) without a nav row.
"""
self.clear_items() self.clear_items()
if nav:
self.previous_page.emoji = self.emojis["previous"] self.previous_page.emoji = self.emojis["previous"]
self.previous_page.disabled = self.current_page <= 0 self.previous_page.disabled = self.current_page <= 0
self.add_item(self.previous_page) self.add_item(self.previous_page)
@ -294,6 +300,7 @@ class ButtonPaginator(Generic[PageT_co], discord.ui.View):
for button in self.current_page_buttons: for button in self.current_page_buttons:
self.add_item(button) self.add_item(button)
if nav:
if self.cache: if self.cache:
self.cache_button.emoji = self.emojis["cache"] self.cache_button.emoji = self.emojis["cache"]
self.add_item(self.cache_button) self.add_item(self.cache_button)
@ -370,6 +377,12 @@ class ButtonPaginator(Generic[PageT_co], discord.ui.View):
self.update_buttons() self.update_buttons()
if self.max_pages < 2: if self.max_pages < 2:
if self.current_page_buttons:
# single page WITH custom buttons: keep the view live so the
# buttons' callbacks still fire; strip only the navigation row
self.update_buttons(nav=False)
else:
# single page, no custom buttons: no interactive row at all
self.stop() self.stop()
kwargs.pop("view", None) kwargs.pop("view", None)