mirror of
https://github.com/wassname/pyreadline.git
synced 2026-07-09 00:20:08 +08:00
pyreadline: Fixes to make clipboard work with unicode.
This commit is contained in:
@@ -1,3 +1,8 @@
|
||||
2007-11-09 Jörgen Stenarson <jorgen.stenarson -at- bostream.nu>
|
||||
* Fixes to make clipboard play nice with unicode. Quick that treats the clipboard as
|
||||
being str with pyreadline_encoding data. Thus convert to unicode when pasting and
|
||||
converting to str when copying.
|
||||
|
||||
2007-11-09 Jörgen Stenarson <jorgen.stenarson -at- bostream.nu>
|
||||
* More fixes to ensure unicode works when completing on filepaths with non ascii symbols.
|
||||
This fix assumes sys.stdout.encoding is valid for the filesystem. A more correct fix
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
|
||||
from ctypes import *
|
||||
from pyreadline.keysyms.winconstants import CF_TEXT, GHND
|
||||
from pyreadline.unicode_helper import ensure_unicode,ensure_text
|
||||
|
||||
OpenClipboard = windll.user32.OpenClipboard
|
||||
EmptyClipboard = windll.user32.EmptyClipboard
|
||||
@@ -81,10 +82,10 @@ def GetClipboardText():
|
||||
text = GlobalLock(hClipMem)
|
||||
GlobalUnlock(hClipMem)
|
||||
CloseClipboard()
|
||||
return text
|
||||
return ensure_unicode(text)
|
||||
|
||||
def SetClipboardText(text):
|
||||
buffer = c_buffer(text)
|
||||
buffer = c_buffer(ensure_text(text))
|
||||
bufferSize = sizeof(buffer)
|
||||
hGlobalMem = GlobalAlloc(c_int(GHND), c_int(bufferSize))
|
||||
GlobalLock.restype = c_void_p
|
||||
@@ -99,7 +100,3 @@ def SetClipboardText(text):
|
||||
if __name__ == '__main__':
|
||||
txt=GetClipboardText() # display last text clipped
|
||||
print txt
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -717,7 +717,7 @@ class ReadLineTextBuffer(TextLine):
|
||||
begin=min(cursor,mark)
|
||||
end=max(cursor,mark)
|
||||
toclipboard="".join(self.line_buffer[begin:end])
|
||||
clipboard.SetClipboardText(str(toclipboard))
|
||||
clipboard.SetClipboardText(toclipboard)
|
||||
|
||||
def copy_selection_to_clipboard(self): # ()
|
||||
'''Copy the text in the region to the windows clipboard.'''
|
||||
@@ -729,7 +729,7 @@ class ReadLineTextBuffer(TextLine):
|
||||
begin=min(cursor,selection_mark)
|
||||
end=max(cursor,selection_mark)
|
||||
toclipboard="".join(self.line_buffer[begin:end])
|
||||
clipboard.SetClipboardText(str(toclipboard))
|
||||
clipboard.SetClipboardText(toclipboard)
|
||||
|
||||
|
||||
def cut_selection_to_clipboard(self): # ()
|
||||
|
||||
@@ -19,3 +19,9 @@ def ensure_unicode(text):
|
||||
if isinstance(text, str):
|
||||
return text.decode(pyreadline_codepage, "replace")
|
||||
return text
|
||||
|
||||
def ensure_text(text):
|
||||
"""Convert unicode to str using pyreadline_codepage"""
|
||||
if isinstance(text, str):
|
||||
return text.encode(pyreadline_codepage, "replace")
|
||||
return text
|
||||
|
||||
Reference in New Issue
Block a user