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
|
||||
=========
|
||||
|
@ -119,11 +120,6 @@ _platform = platform
|
|||
if _platform == 'android':
|
||||
_clipboards.append(
|
||||
('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'):
|
||||
if _platform == 'macosx':
|
||||
_clipboards.append(
|
||||
|
@ -136,8 +132,9 @@ elif _platform in ('macosx', 'linux', 'win'):
|
|||
|
||||
_clipboards.append(
|
||||
('pygame', 'clipboard_pygame', 'ClipboardPygame'))
|
||||
_clipboards.append(
|
||||
('sdl2', 'clipboard_sdl2', 'ClipboardSDL2'))
|
||||
|
||||
_clipboards.append(
|
||||
('sdl2', 'clipboard_sdl2', 'ClipboardSDL2'))
|
||||
_clipboards.append(
|
||||
('dummy', 'clipboard_dummy', 'ClipboardDummy'))
|
||||
|
||||
|
@ -145,3 +142,4 @@ Clipboard = core_select_lib('clipboard', _clipboards, True)
|
|||
|
||||
del _clipboards
|
||||
del _platform
|
||||
|
||||
|
|
|
@ -10,10 +10,12 @@ from kivy.core.clipboard import ClipboardBase
|
|||
if platform != 'win':
|
||||
raise SystemError('unsupported platform for Windows clipboard')
|
||||
|
||||
import ctypes
|
||||
user32 = ctypes.windll.user32
|
||||
kernel32 = ctypes.windll.kernel32
|
||||
msvcrt = ctypes.cdll.msvcrt
|
||||
c_char_p = ctypes.c_char_p
|
||||
c_wchar_p = ctypes.c_wchar_p
|
||||
|
||||
|
||||
class ClipboardWindows(ClipboardBase):
|
||||
|
@ -21,37 +23,26 @@ class ClipboardWindows(ClipboardBase):
|
|||
def get(self, mimetype='text/plain'):
|
||||
user32.OpenClipboard(0)
|
||||
# 1 is CF_TEXT
|
||||
pcontents = user32.GetClipboardData(1)
|
||||
data = c_char_p(pcontents).value
|
||||
pcontents = user32.GetClipboardData(13)
|
||||
data = c_wchar_p(pcontents).value.encode('utf-16')
|
||||
#ctypes.windll.kernel32.GlobalUnlock(pcontents)
|
||||
user32.CloseClipboard()
|
||||
return data
|
||||
|
||||
def put(self, data, mimetype='text/plain'):
|
||||
def put(self, text, mimetype='text/plain'):
|
||||
print text, type(text)
|
||||
GMEM_DDESHARE = 0x2000
|
||||
user32.OpenClipboard(0)
|
||||
CF_UNICODETEXT = 13
|
||||
user32.OpenClipboard(None)
|
||||
user32.EmptyClipboard()
|
||||
try:
|
||||
# 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)
|
||||
hCd = kernel32.GlobalAlloc(GMEM_DDESHARE, len(text) + 2)
|
||||
pchData = kernel32.GlobalLock(hCd)
|
||||
try:
|
||||
# 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'))
|
||||
msvcrt.wcscpy(c_wchar_p(pchData), text)
|
||||
kernel32.GlobalUnlock(hCd)
|
||||
user32.SetClipboardData(1, hCd)
|
||||
user32.SetClipboardData(CF_UNICODETEXT, hCd)
|
||||
user32.CloseClipboard()
|
||||
|
||||
def get_types(self):
|
||||
return list('text/plain',)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue