Changeset 2863

Show
Ignore:
Timestamp:
11/09/07 16:45:31 (1 year ago)
Author:
jstenar
Message:

pyreadline: Fixes to make clipboard work with unicode.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • pyreadline/trunk/doc/ChangeLog

    r2861 r2863  
     12007-11-09 Jörgen Stenarson  <jorgen.stenarson -at- bostream.nu> 
     2    * Fixes to make clipboard play nice with unicode. Quick that treats the clipboard as 
     3      being str with pyreadline_encoding data. Thus convert to unicode when pasting and 
     4      converting to str when copying. 
     5 
    162007-11-09 Jörgen Stenarson  <jorgen.stenarson -at- bostream.nu> 
    27    * More fixes to ensure unicode works when completing on filepaths with non ascii symbols.  
  • pyreadline/trunk/pyreadline/clipboard/win32_clipboard.py

    r2132 r2863  
    3535from ctypes import * 
    3636from pyreadline.keysyms.winconstants import CF_TEXT, GHND 
     37from pyreadline.unicode_helper import ensure_unicode,ensure_text 
    3738 
    3839OpenClipboard = windll.user32.OpenClipboard 
     
    8283            GlobalUnlock(hClipMem) 
    8384        CloseClipboard() 
    84     return text 
     85    return ensure_unicode(text) 
    8586 
    8687def SetClipboardText(text): 
    87     buffer = c_buffer(text
     88    buffer = c_buffer(ensure_text(text)
    8889    bufferSize = sizeof(buffer) 
    8990    hGlobalMem = GlobalAlloc(c_int(GHND), c_int(bufferSize)) 
     
    100101    txt=GetClipboardText()                            # display last text clipped 
    101102    print txt 
    102       
    103       
    104       
    105       
  • pyreadline/trunk/pyreadline/lineeditor/lineobj.py

    r2861 r2863  
    718718                end=max(cursor,mark) 
    719719                toclipboard="".join(self.line_buffer[begin:end]) 
    720                 clipboard.SetClipboardText(str(toclipboard)
     720                clipboard.SetClipboardText(toclipboard
    721721 
    722722    def copy_selection_to_clipboard(self): # () 
     
    730730                end=max(cursor,selection_mark) 
    731731                toclipboard="".join(self.line_buffer[begin:end]) 
    732                 clipboard.SetClipboardText(str(toclipboard)
     732                clipboard.SetClipboardText(toclipboard
    733733 
    734734 
  • pyreadline/trunk/pyreadline/unicode_helper.py

    r2861 r2863  
    2020        return text.decode(pyreadline_codepage, "replace") 
    2121    return text 
     22 
     23def ensure_text(text): 
     24    """Convert unicode to str using pyreadline_codepage""" 
     25    if isinstance(text, str): 
     26        return text.encode(pyreadline_codepage, "replace") 
     27    return text