work around issues writing to Windows clipboard

https://anki.tenderapp.com/discussions/beta-testing/1014-cannot-copy-from-fields-in-anki-210beta36
This commit is contained in:
Damien Elmes 2018-03-01 15:53:25 +10:00
parent 53f0793b9e
commit 25c3f2cb24

View File

@ -21,7 +21,7 @@ from anki.hooks import runHook, runFilter
from aqt.sound import getAudio from aqt.sound import getAudio
from aqt.webview import AnkiWebView from aqt.webview import AnkiWebView
from aqt.utils import shortcut, showInfo, showWarning, getFile, \ from aqt.utils import shortcut, showInfo, showWarning, getFile, \
openHelp, tooltip, downArrow openHelp, tooltip, downArrow, showCritical
import aqt import aqt
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
import requests import requests
@ -903,6 +903,36 @@ class EditorWebView(AnkiWebView):
return return
html = mime.html() html = mime.html()
mime.setHtml("<!--anki-->" + html) mime.setHtml("<!--anki-->" + html)
if isWin:
self._windowsSetMimeData(clip, mime)
else:
clip.setMimeData(mime)
def _windowsSetMimeData(self, clip, mime):
import win32clipboard, time
from ctypes import windll
grabbed = False
for i in range(10):
try:
win32clipboard.OpenClipboard(self.editor.parentWindow.winId())
grabbed = True
break
except:
time.sleep(0.01)
continue
if not grabbed:
hwnd = win32clipboard.GetOpenClipboardWindow()
longpid = ctypes.c_ulong()
result = windll.user32.GetWindowThreadProcessId(hwnd, ctypes.byref(longpid))
pid = longpid.value
showCritical(_("Unable to access clipboard - locked by process %d" % pid))
return
win32clipboard.CloseClipboard()
clip.setMimeData(mime) clip.setMimeData(mime)
def contextMenuEvent(self, evt): def contextMenuEvent(self, evt):