Skip to content

Commit

Permalink
Merge pull request #10 from teegaar/master
Browse files Browse the repository at this point in the history
fix problems with non-ASCII text in clipboard (issue #9)
  • Loading branch information
jstenar committed Mar 27, 2013
2 parents c1a9ce4 + 514ed19 commit 8edfe8c
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions pyreadline/clipboard/win32_clipboard.py
Expand Up @@ -34,7 +34,7 @@
from __future__ import print_function, unicode_literals, absolute_import

from ctypes import *
from pyreadline.keysyms.winconstants import CF_TEXT, GHND
from pyreadline.keysyms.winconstants import CF_UNICODETEXT, GHND
from pyreadline.unicode_helper import ensure_unicode,ensure_str

OpenClipboard = windll.user32.OpenClipboard
Expand Down Expand Up @@ -83,16 +83,16 @@ def getformatname(format):
def GetClipboardText():
text = ""
if OpenClipboard(0):
hClipMem = GetClipboardData(CF_TEXT)
hClipMem = GetClipboardData(CF_UNICODETEXT)
if hClipMem:
GlobalLock.restype = c_char_p
GlobalLock.restype = c_wchar_p
text = GlobalLock(hClipMem)
GlobalUnlock(hClipMem)
CloseClipboard()
return ensure_unicode(text)

def SetClipboardText(text):
buffer = c_buffer(ensure_str(text))
buffer = create_unicode_buffer(ensure_unicode(text))
bufferSize = sizeof(buffer)
hGlobalMem = GlobalAlloc(c_int(GHND), c_int(bufferSize))
GlobalLock.restype = c_void_p
Expand All @@ -101,7 +101,7 @@ def SetClipboardText(text):
GlobalUnlock(c_int(hGlobalMem))
if OpenClipboard(0):
EmptyClipboard()
SetClipboardData(c_int(CF_TEXT), c_int(hGlobalMem))
SetClipboardData(c_int(CF_UNICODETEXT), c_int(hGlobalMem))
CloseClipboard()

if __name__ == '__main__':
Expand Down

0 comments on commit 8edfe8c

Please sign in to comment.