From d8d08717296fd217b6648ac722f1453ca23fca38 Mon Sep 17 00:00:00 2001 From: Isaiah Odhner Date: Mon, 1 May 2023 16:56:43 -0400 Subject: [PATCH] Catch any errors getting the clipboard data I haven't run into this, but since we've got a nice localized string for it... --- src/textual_paint/paint.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/textual_paint/paint.py b/src/textual_paint/paint.py index 2a98b6f..08a3179 100755 --- a/src/textual_paint/paint.py +++ b/src/textual_paint/paint.py @@ -2131,8 +2131,12 @@ class PaintApp(App[None]): def action_paste(self) -> None: """Paste the clipboard as a selection.""" - import pyperclip - text: str = pyperclip.paste() + try: + import pyperclip + text: str = pyperclip.paste() + except Exception as e: + self.warning_message_box(_("Paint"), _("Error getting the Clipboard Data!") + "\n\n" + repr(e), "ok") + return if not text: return if self.image.selection and self.image.selection.textbox_mode: