mirror of https://github.com/kivy/kivy.git
clipboard_winctype fixes for windows
This commit is contained in:
parent
faefe5629c
commit
605601636f
|
@ -1,3 +1,4 @@
|
||||||
|
|
||||||
'''
|
'''
|
||||||
Clipboard
|
Clipboard
|
||||||
=========
|
=========
|
||||||
|
@ -119,11 +120,6 @@ _platform = platform
|
||||||
if _platform == 'android':
|
if _platform == 'android':
|
||||||
_clipboards.append(
|
_clipboards.append(
|
||||||
('android', 'clipboard_android', 'ClipboardAndroid'))
|
('android', 'clipboard_android', 'ClipboardAndroid'))
|
||||||
_clipboards.append(
|
|
||||||
('sdl2', 'clipboard_sdl2', 'ClipboardSDL2'))
|
|
||||||
elif _platform == 'ios':
|
|
||||||
_clipboards.append(
|
|
||||||
('sdl2', 'clipboard_sdl2', 'ClipboardSDL2'))
|
|
||||||
elif _platform in ('macosx', 'linux', 'win'):
|
elif _platform in ('macosx', 'linux', 'win'):
|
||||||
if _platform == 'macosx':
|
if _platform == 'macosx':
|
||||||
_clipboards.append(
|
_clipboards.append(
|
||||||
|
@ -136,8 +132,9 @@ elif _platform in ('macosx', 'linux', 'win'):
|
||||||
|
|
||||||
_clipboards.append(
|
_clipboards.append(
|
||||||
('pygame', 'clipboard_pygame', 'ClipboardPygame'))
|
('pygame', 'clipboard_pygame', 'ClipboardPygame'))
|
||||||
_clipboards.append(
|
|
||||||
('sdl2', 'clipboard_sdl2', 'ClipboardSDL2'))
|
_clipboards.append(
|
||||||
|
('sdl2', 'clipboard_sdl2', 'ClipboardSDL2'))
|
||||||
_clipboards.append(
|
_clipboards.append(
|
||||||
('dummy', 'clipboard_dummy', 'ClipboardDummy'))
|
('dummy', 'clipboard_dummy', 'ClipboardDummy'))
|
||||||
|
|
||||||
|
@ -145,3 +142,4 @@ Clipboard = core_select_lib('clipboard', _clipboards, True)
|
||||||
|
|
||||||
del _clipboards
|
del _clipboards
|
||||||
del _platform
|
del _platform
|
||||||
|
|
||||||
|
|
|
@ -10,10 +10,12 @@ from kivy.core.clipboard import ClipboardBase
|
||||||
if platform != 'win':
|
if platform != 'win':
|
||||||
raise SystemError('unsupported platform for Windows clipboard')
|
raise SystemError('unsupported platform for Windows clipboard')
|
||||||
|
|
||||||
|
import ctypes
|
||||||
user32 = ctypes.windll.user32
|
user32 = ctypes.windll.user32
|
||||||
kernel32 = ctypes.windll.kernel32
|
kernel32 = ctypes.windll.kernel32
|
||||||
msvcrt = ctypes.cdll.msvcrt
|
msvcrt = ctypes.cdll.msvcrt
|
||||||
c_char_p = ctypes.c_char_p
|
c_char_p = ctypes.c_char_p
|
||||||
|
c_wchar_p = ctypes.c_wchar_p
|
||||||
|
|
||||||
|
|
||||||
class ClipboardWindows(ClipboardBase):
|
class ClipboardWindows(ClipboardBase):
|
||||||
|
@ -21,37 +23,26 @@ class ClipboardWindows(ClipboardBase):
|
||||||
def get(self, mimetype='text/plain'):
|
def get(self, mimetype='text/plain'):
|
||||||
user32.OpenClipboard(0)
|
user32.OpenClipboard(0)
|
||||||
# 1 is CF_TEXT
|
# 1 is CF_TEXT
|
||||||
pcontents = user32.GetClipboardData(1)
|
pcontents = user32.GetClipboardData(13)
|
||||||
data = c_char_p(pcontents).value
|
data = c_wchar_p(pcontents).value.encode('utf-16')
|
||||||
#ctypes.windll.kernel32.GlobalUnlock(pcontents)
|
#ctypes.windll.kernel32.GlobalUnlock(pcontents)
|
||||||
user32.CloseClipboard()
|
user32.CloseClipboard()
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def put(self, data, mimetype='text/plain'):
|
def put(self, text, mimetype='text/plain'):
|
||||||
|
print text, type(text)
|
||||||
GMEM_DDESHARE = 0x2000
|
GMEM_DDESHARE = 0x2000
|
||||||
user32.OpenClipboard(0)
|
CF_UNICODETEXT = 13
|
||||||
|
user32.OpenClipboard(None)
|
||||||
user32.EmptyClipboard()
|
user32.EmptyClipboard()
|
||||||
try:
|
hCd = kernel32.GlobalAlloc(GMEM_DDESHARE, len(text) + 2)
|
||||||
# works on Python 2 (bytes() only takes one argument)
|
|
||||||
hCd = kernel32.GlobalAlloc(
|
|
||||||
GMEM_DDESHARE, len(bytes(text)) + 1)
|
|
||||||
except TypeError:
|
|
||||||
# works on Python 3 (bytes() requires an encoding)
|
|
||||||
hCd = kernel32.GlobalAlloc(
|
|
||||||
GMEM_DDESHARE, len(bytes(text, 'ascii')) + 1)
|
|
||||||
pchData = kernel32.GlobalLock(hCd)
|
pchData = kernel32.GlobalLock(hCd)
|
||||||
try:
|
msvcrt.wcscpy(c_wchar_p(pchData), text)
|
||||||
# works on Python 2 (bytes() only takes one argument)
|
|
||||||
msvcrt.strcpy(
|
|
||||||
c_char_p(pchData), bytes(text))
|
|
||||||
except TypeError:
|
|
||||||
# works on Python 3 (bytes() requires an encoding)
|
|
||||||
msvcrt.strcpy(
|
|
||||||
c_char_p(pchData), bytes(text, 'ascii'))
|
|
||||||
kernel32.GlobalUnlock(hCd)
|
kernel32.GlobalUnlock(hCd)
|
||||||
user32.SetClipboardData(1, hCd)
|
user32.SetClipboardData(CF_UNICODETEXT, hCd)
|
||||||
user32.CloseClipboard()
|
user32.CloseClipboard()
|
||||||
|
|
||||||
def get_types(self):
|
def get_types(self):
|
||||||
return list('text/plain',)
|
return list('text/plain',)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue