From 20ea4f9291ebc8de7d610e85378cccf2177354d3 Mon Sep 17 00:00:00 2001 From: disqualifier Date: Mon, 29 Jun 2026 17:26:04 -0400 Subject: [PATCH] fix: single page keeps custom buttons instead of dropping the view (v0.1.2) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- README.md | 4 +-- pyproject.toml | 2 +- src/dpy_paginator/dpy_paginator.py | 43 +++++++++++++++++++----------- 3 files changed, 31 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index c3320ca..5fbcfac 100644 --- a/README.md +++ b/README.md @@ -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). diff --git a/pyproject.toml b/pyproject.toml index b6222a4..5d83596 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 = [ diff --git a/src/dpy_paginator/dpy_paginator.py b/src/dpy_paginator/dpy_paginator.py index cbe238a..ef12075 100644 --- a/src/dpy_paginator/dpy_paginator.py +++ b/src/dpy_paginator/dpy_paginator.py @@ -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)