From ccbe88d3bfecd33bb86f1335043ad8dc33d2ef82 Mon Sep 17 00:00:00 2001 From: Jasmine Moore Date: Wed, 17 Dec 2025 12:26:36 -0500 Subject: [PATCH 1/2] fix: Fixed clipboard issues on Wayland, using pyclip instead of wx --- gui/copySelectDialog.py | 1 + gui/utils/clipboard.py | 64 ++++++----------------------------------- requirements.txt | 1 + 3 files changed, 10 insertions(+), 56 deletions(-) diff --git a/gui/copySelectDialog.py b/gui/copySelectDialog.py index 349d45b05e..3f3b998cf9 100644 --- a/gui/copySelectDialog.py +++ b/gui/copySelectDialog.py @@ -151,6 +151,7 @@ def Validate(self): def cb(text): if self.waitDialog: del self.waitDialog + print("cb called. Text: {}", text) # TODO REMOVE DEBUG toClipboard(text) self.EndModal(wx.ID_OK) diff --git a/gui/utils/clipboard.py b/gui/utils/clipboard.py index a8db13ca72..d4b7bf33f5 100644 --- a/gui/utils/clipboard.py +++ b/gui/utils/clipboard.py @@ -1,68 +1,20 @@ # noinspection PyPackageRequirements -import wx +import pyclip from logbook import Logger logger = Logger(__name__) def toClipboard(text): - """ - Copy text to clipboard. Explicitly uses CLIPBOARD selection, not PRIMARY. - - On X11 systems, wxPython can confuse between PRIMARY and CLIPBOARD selections, - causing "already open" errors. This function ensures we always use CLIPBOARD. - - See: https://discuss.wxpython.org/t/wx-theclipboard-pasting-different-content-on-every-second-paste/35361 - """ - clipboard = wx.TheClipboard - try: - # Explicitly use CLIPBOARD selection, not PRIMARY selection - # This prevents X11 confusion between the two clipboard types - clipboard.UsePrimarySelection(False) - - if clipboard.Open(): - try: - data = wx.TextDataObject(text) - clipboard.SetData(data) - return True - finally: - clipboard.Close() - else: - logger.debug("Failed to open clipboard for writing") - return False - except Exception as e: - logger.warning("Error writing to clipboard: {}", e) - return False + pyclip.copy(text) def fromClipboard(): """ - Read text from clipboard. Explicitly uses CLIPBOARD selection, not PRIMARY. - - On X11 systems, wxPython can confuse between PRIMARY and CLIPBOARD selections, - causing "already open" errors. This function ensures we always use CLIPBOARD. - - See: https://discuss.wxpython.org/t/wx-theclipboard-pasting-different-content-on-every-second-paste/35361 + Read text from clipboard. Uses pyclip to grab in a cross-platform, reliable manner. """ - clipboard = wx.TheClipboard - try: - # Explicitly use CLIPBOARD selection, not PRIMARY selection - # This prevents X11 confusion between the two clipboard types - clipboard.UsePrimarySelection(False) - - if clipboard.Open(): - try: - data = wx.TextDataObject() - if clipboard.GetData(data): - return data.GetText() - else: - logger.debug("Clipboard open but no CLIPBOARD data available") - return None - finally: - clipboard.Close() - else: - logger.debug("Failed to open clipboard for reading") - return None - except Exception as e: - logger.warning("Error reading from clipboard: {}", e) - return None + data = pyclip.paste(text=True) + if not isinstance(data, str): + data = data.decode('utf-8') + logger.debug("Pasted data: {}", data) + return data diff --git a/requirements.txt b/requirements.txt index 46ed9241b9..04964d842a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -13,3 +13,4 @@ beautifulsoup4==4.12.2 pyyaml==6.0.1 python-jose==3.3.0 requests-cache==1.1.1 +pyclip >= 0.7.0 From 84f532284e1e81b25eafa6529ad0c9bc8dd3ef4e Mon Sep 17 00:00:00 2001 From: Jasmine Moore Date: Wed, 17 Dec 2025 12:31:05 -0500 Subject: [PATCH 2/2] fix: remove debug statement --- gui/copySelectDialog.py | 1 - 1 file changed, 1 deletion(-) diff --git a/gui/copySelectDialog.py b/gui/copySelectDialog.py index 3f3b998cf9..349d45b05e 100644 --- a/gui/copySelectDialog.py +++ b/gui/copySelectDialog.py @@ -151,7 +151,6 @@ def Validate(self): def cb(text): if self.waitDialog: del self.waitDialog - print("cb called. Text: {}", text) # TODO REMOVE DEBUG toClipboard(text) self.EndModal(wx.ID_OK)