pyreadline: patch to get swedish characters working.

This commit is contained in:
jstenar
2006-01-21 18:59:28 +00:00
parent 15e3bd1255
commit 70638c4e3c
3 changed files with 28 additions and 5 deletions
+8
View File
@@ -1,3 +1,11 @@
2006-01-21 Jörgen Stenarson <jorgen.stenarson -at- bostream.nu>
* Patch to get swedish characters working when python
is executed in a cmd window with codepage set to 1252.
Example: issue command chcp 1252. Then change the font to
lucida terminal, this is done in the properties dialog of
the terminal.
2006-01-21 Jörgen Stenarson <jorgen.stenarson -at- bostream.nu>
* Changed all python files to conform to 4 space indent.
+11 -4
View File
@@ -13,10 +13,12 @@ import win32con as c32
import Console
from Console import log
from keysyms import key_text_to_keyinfo
from keysyms import key_text_to_keyinfo,printable_chars_in_codepage
def quote_char(c):
if ' ' <= c <= '~':
if c in printable_chars_in_codepage:
return c
elif ' ' <= c <= '~':
return c
else:
return repr(c)[1:-1]
@@ -622,8 +624,9 @@ class Readline:
def self_insert(self, e): # (a, b, A, 1, !, ...)
'''Insert yourself. '''
self.line_buffer.insert(self.line_cursor, e.char)
self.line_cursor += 1
if ord(e.char)!=0: #don't insert null character in buffer, can happen with dead keys.
self.line_buffer.insert(self.line_cursor, e.char)
self.line_cursor += 1
def transpose_chars(self, e): # (C-t)
'''Drag the character before the cursor forward over the character
@@ -1003,6 +1006,10 @@ class Readline:
def emacs_editing_mode(self, e): # (C-e)
'''When in vi command mode, this causes a switch to emacs editing
mode.'''
#insert printable chars available from codepage
for char in printable_chars_in_codepage:
self._bind_key(char, self.self_insert)
# make ' ' to ~ self insert
for c in range(ord(' '), 127):
self._bind_key('"%s"' % chr(c), self.self_insert)
+9 -1
View File
@@ -1,6 +1,6 @@
import win32con as c32
from ctypes import windll
import ctypes
# table for translating virtual keys to X windows key symbols
code2sym_map = {c32.VK_CANCEL: 'Cancel',
c32.VK_BACK: 'BackSpace',
@@ -104,6 +104,14 @@ def key_text_to_keyinfo(keytext):
VkKeyScan = windll.user32.VkKeyScanA
codepage=windll.kernel32.GetConsoleCP()
outputcodepage=windll.kernel32.GetConsoleOutputCP()
#This method does not seem to work for use of swedish characters on codepage 850
#VkKeyScan results in -1 for those keys
printable_chars_in_codepage={1252:"\xe5\xe4\xf6\xc5\xc4\xd6\xa8\xb4\xa7\xbd\xa4\xa3",
}.get(codepage,"")
def char_to_keyinfo(char, control=False, meta=False, shift=False):
vk = VkKeyScan(ord(char))
if vk & 0xffff == 0xffff: