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`:
```
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:
```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).

View File

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

View File

@ -280,27 +280,34 @@ class ButtonPaginator(Generic[PageT_co], discord.ui.View):
return self._page_kwargs
def update_buttons(self) -> None:
"""rebuild the action row for the current page state"""
def update_buttons(self, nav: bool = True) -> None:
"""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.previous_page.emoji = self.emojis["previous"]
self.previous_page.disabled = self.current_page <= 0
self.add_item(self.previous_page)
if nav:
self.previous_page.emoji = self.emojis["previous"]
self.previous_page.disabled = self.current_page <= 0
self.add_item(self.previous_page)
self.jump_button.label = self.page_text.format(self.current_page + 1, self.max_pages)
self.add_item(self.jump_button)
self.jump_button.label = self.page_text.format(self.current_page + 1, self.max_pages)
self.add_item(self.jump_button)
for button in self.current_page_buttons:
self.add_item(button)
if self.cache:
self.cache_button.emoji = self.emojis["cache"]
self.add_item(self.cache_button)
if nav:
if self.cache:
self.cache_button.emoji = self.emojis["cache"]
self.add_item(self.cache_button)
self.next_page.emoji = self.emojis["next"]
self.next_page.disabled = self.current_page >= self.max_pages - 1
self.add_item(self.next_page)
self.next_page.emoji = self.emojis["next"]
self.next_page.disabled = self.current_page >= self.max_pages - 1
self.add_item(self.next_page)
async def _build_render_kwargs(self) -> Dict[str, Any]:
"""build the edit-ready kwargs for the current page (buttons + attachments)"""
@ -370,8 +377,14 @@ class ButtonPaginator(Generic[PageT_co], discord.ui.View):
self.update_buttons()
if self.max_pages < 2:
self.stop()
kwargs.pop("view", None)
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()
kwargs.pop("view", None)
self.reset_files(kwargs)