From 43a4e1e726921d70ef4acade96e8b03f72ff3a59 Mon Sep 17 00:00:00 2001 From: pax Date: Sun, 5 Apr 2026 14:24:02 -0500 Subject: [PATCH] =?UTF-8?q?Fix=20copy=20to=20clipboard=20=E2=80=94=20fallb?= =?UTF-8?q?ack=20to=20cached=20path,=20always=20show=20option?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Ctrl+C tries pixmap then cached file path as fallback - Preview right-click always shows "Copy Image to Clipboard" - Works for images and loads from disk for videos - Status bar shows result count with copy confirmation --- booru_viewer/gui/app.py | 18 +++++++++++++++--- booru_viewer/gui/preview.py | 13 +++++++++---- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/booru_viewer/gui/app.py b/booru_viewer/gui/app.py index 9069236..72de1c4 100644 --- a/booru_viewer/gui/app.py +++ b/booru_viewer/gui/app.py @@ -1898,9 +1898,21 @@ class BooruApp(QMainWindow): super().keyPressEvent(event) def _copy_preview_to_clipboard(self) -> None: - if self._preview._image_viewer._pixmap and not self._preview._image_viewer._pixmap.isNull(): - QApplication.clipboard().setPixmap(self._preview._image_viewer._pixmap) - self._status.showMessage("Image copied to clipboard") + # Try image viewer pixmap first + pix = self._preview._image_viewer._pixmap + if pix and not pix.isNull(): + QApplication.clipboard().setPixmap(pix) + self._status.showMessage(f"{len(self._posts)} results — Copied to clipboard") + return + # Try loading from cached path + path = self._preview._current_path + if path: + pix = QPixmap(path) + if not pix.isNull(): + QApplication.clipboard().setPixmap(pix) + self._status.showMessage(f"{len(self._posts)} results — Copied to clipboard") + return + self._status.showMessage(f"{len(self._posts)} results — Nothing to copy") # -- Bookmarks -- diff --git a/booru_viewer/gui/preview.py b/booru_viewer/gui/preview.py index f2247fe..345f2f2 100644 --- a/booru_viewer/gui/preview.py +++ b/booru_viewer/gui/preview.py @@ -681,9 +681,7 @@ class ImagePreview(QWidget): save_new = save_menu.addAction("+ New Folder...") menu.addSeparator() - copy_image = None - if self._stack.currentIndex() == 0 and self._image_viewer._pixmap: - copy_image = menu.addAction("Copy Image to Clipboard") + copy_image = menu.addAction("Copy Image to Clipboard") open_action = menu.addAction("Open in Default App") browser_action = menu.addAction("Open in Browser") @@ -715,7 +713,14 @@ class ImagePreview(QWidget): self.save_to_folder.emit(save_folder_actions[id(action)]) elif action == copy_image: from PySide6.QtWidgets import QApplication - QApplication.clipboard().setPixmap(self._image_viewer._pixmap) + from PySide6.QtGui import QPixmap as _QP + pix = self._image_viewer._pixmap + if pix and not pix.isNull(): + QApplication.clipboard().setPixmap(pix) + elif self._current_path: + pix = _QP(self._current_path) + if not pix.isNull(): + QApplication.clipboard().setPixmap(pix) elif action == open_action: self.open_in_default.emit() elif action == browser_action: