1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-13 07:47:14 +03:00

[1471] Add PIL to Improve Clipboard

This commit is contained in:
David Sangrey 2024-03-28 12:59:22 -04:00
parent ccda74c8f1
commit 572f724a71
No known key found for this signature in database
GPG Key ID: 3AEADBB0186884BC
4 changed files with 23 additions and 6 deletions

View File

@ -802,4 +802,7 @@
"Ships" = "Ships";
/* update.py: Update Available Text; In files: update.py:229; */
"{NEWVER} is available" = "{NEWVER} is available";
"{NEWVER} is available" = "{NEWVER} is available";
/* myNotebook.py: Can't Paste Images or Files in Text; */
"Cannot paste non-text content." = "Cannot paste non-text content.";

View File

@ -133,7 +133,6 @@ def build() -> None:
"distutils",
"_markerlib",
"optparse",
"PIL",
"simplejson",
"unittest",
"doctest",

View File

@ -14,7 +14,12 @@ from __future__ import annotations
import sys
import tkinter as tk
from tkinter import ttk
from tkinter import ttk, messagebox
from typing import TYPE_CHECKING
from PIL import ImageGrab
if TYPE_CHECKING:
def _(x: str) -> str: return x
# Can't do this with styles on OSX - http://www.tkdocs.com/tutorial/styles.html#whydifficult
if sys.platform == 'darwin':
@ -126,13 +131,22 @@ class EntryMenu(ttk.Entry):
def paste(self) -> None:
"""Paste the selected Entry text."""
if self.selection_present():
self.delete(tk.SEL_FIRST, tk.SEL_LAST)
try:
# Attempt to grab an image from the clipboard (apprently also works for files)
img = ImageGrab.grabclipboard()
if img:
# Hijack existing translation, yes it doesn't exactly match here.
# LANG: Generic error prefix - following text is from Frontier auth service;
messagebox.showwarning(_('Error'),
_('Cannot paste non-text content.')) # LANG: Can't Paste Images or Files in Text
return
text = self.clipboard_get()
if self.selection_present() and text:
self.delete(tk.SEL_FIRST, tk.SEL_LAST)
self.insert(tk.INSERT, text)
except tk.TclError:
pass # No text in clipboard or clipboard is not text
# No text in clipboard or clipboard is not text
pass
class Entry(sys.platform == 'darwin' and tk.Entry or EntryMenu or ttk.Entry): # type: ignore

View File

@ -1,5 +1,6 @@
certifi==2023.11.17
requests==2.31.0
pillow==10.2.0
# requests depends on this now ?
charset-normalizer==2.1.1