Update of /cvsroot/pywin32/pywin32/Pythonwin/pywin/scintilla
In directory sfp-cvsdas-2.v30.ch3.sourceforge.com:/tmp/cvs-serv17893/Pythonwin/pywin/scintilla
Modified Files:
bindings.py config.py keycodes.py
Log Message:
Pythonwin: Better support for international keyboard. (Bug 896502 and
help from kxroberto)
Index: config.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/Pythonwin/pywin/scintilla/config.py,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** config.py 25 Aug 2010 07:55:10 -0000 1.10
--- config.py 28 Oct 2010 01:52:49 -0000 1.11
***************
*** 21,24 ****
--- 21,26 ----
import imp
+ import win32api
+
debugging = 0
if debugging:
***************
*** 29,33 ****
trace = lambda *args: None
! compiled_config_version = 2
def split_line(line, lineno):
--- 31,35 ----
trace = lambda *args: None
! compiled_config_version = 3
def split_line(line, lineno):
***************
*** 89,96 ****
--- 91,100 ----
ok = compiled_config_version == ver
if ok:
+ kblayoutname = marshal.load(cf)
magic = marshal.load(cf)
size = marshal.load(cf)
mtime = marshal.load(cf)
if magic == imp.get_magic() and \
+ win32api.GetKeyboardLayoutName() == kblayoutname and \
src_stat[stat.ST_MTIME] == mtime and \
src_stat[stat.ST_SIZE] == size:
***************
*** 135,138 ****
--- 139,143 ----
cf = open(compiled_name, "wb")
marshal.dump(compiled_config_version, cf)
+ marshal.dump(win32api.GetKeyboardLayoutName(), cf)
marshal.dump(imp.get_magic(), cf)
marshal.dump(src_stat[stat.ST_SIZE], cf)
Index: bindings.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/Pythonwin/pywin/scintilla/bindings.py,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** bindings.py 4 Jan 2009 22:37:36 -0000 1.9
--- bindings.py 28 Oct 2010 01:52:49 -0000 1.10
***************
*** 169,186 ****
event = self.keymap.get( keyinfo )
if event is None:
- ## if key == 220: # Dead key
- ## return 1
- ## # Translate the raw scancode into an Ascii character.
- ## print "translating", key, "(with state)", keyState,
- ## key = win32ui.TranslateVirtualKey(key)
- ## print "Got back key", `key`,
- #### if key is None:
- #### return 1 # Dead-key - don't handle at all!!!
- ## if key:
- ## # Then back to a "normalized" scan-code.
- ## key = keycodes.get_scan_code(key[0])
- ## keyinfo = key, keyState
- ## event = self.keymap.get( keyinfo )
- ## if event is None:
return 1
return self.fire(event, None)
--- 169,172 ----
Index: keycodes.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/Pythonwin/pywin/scintilla/keycodes.py,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** keycodes.py 4 Dec 2008 07:02:55 -0000 1.7
--- keycodes.py 28 Oct 2010 01:52:49 -0000 1.8
***************
*** 1,54 ****
import string
import win32con
! char_ranges = [
! (string.ascii_lowercase, -32),
! (string.digits, 0),
! ("?><:[]\\", 128),
! (";", 127),
! ("=", 126),
! ("/.,", 144),
! ("`{}|", 96),
! ("_", 94),
! ("-+", 144),
! ("'", 183),
! ('"', 188),
! ("~", 66),
! ("!",16),
! ("#$%&", 18),
! ("()", 17),
! ]
! key_name_to_code = {}
key_code_to_name = {}
! _better_names = [
! ("esc", win32con.VK_ESCAPE),
! ("enter", win32con.VK_RETURN),
! ("pgup", win32con.VK_BACK),
! ("pgdn", win32con.VK_NEXT),
! ]
! def _fillmap():
# Pull the VK_names from win32con
names = [entry for entry in win32con.__dict__ if entry.startswith("VK_")]
for name in names:
n = name[3:].lower()
! val = getattr(win32con, name)
! key_name_to_code[n] = val
! key_code_to_name[val] = n
! # Some better named we know about
! for name, code in _better_names:
! key_name_to_code[name] = code
! key_code_to_name[code] = name
! # And the char_ranges map above
! for chars, offset in char_ranges:
! for char in chars:
! key_name_to_code[char] = ord(char)+offset
! key_code_to_name[ord(char)+offset] = char
- _fillmap()
! def get_scan_code(chardesc):
! return key_name_to_code.get(chardesc.lower())
modifiers = {
--- 1,52 ----
import string
import win32con
+ import win32api
+ import win32ui
! MAPVK_VK_TO_CHAR = 2
! key_name_to_vk = {}
key_code_to_name = {}
! _better_names = {
! "escape": "esc",
! "return": "enter",
! "back": "pgup",
! "next": "pgdn",
! }
!
! def _fillvkmap():
# Pull the VK_names from win32con
names = [entry for entry in win32con.__dict__ if entry.startswith("VK_")]
for name in names:
+ code = getattr(win32con, name)
n = name[3:].lower()
! key_name_to_vk[n] = code
! if n in _better_names:
! n = _better_names[n]
! key_name_to_vk[n] = code
! key_code_to_name[code] = n
! _fillvkmap()
!
! def get_vk(chardesc):
! if len(chardesc)==1:
! # it is a character.
! info = win32api.VkKeyScan(chardesc)
! if info==-1:
! return None, None
! vk = win32api.LOBYTE(info)
! state = win32api.HIBYTE(info)
! modifiers = 0
! if state & 0x1:
! modifiers |= win32con.SHIFT_PRESSED
! if state & 0x2:
! modifiers |= win32con.LEFT_CTRL_PRESSED | win32con.RIGHT_CTRL_PRESSED
! if state & 0x4:
! modifiers |= win32con.LEFT_ALT_PRESSED | win32con.RIGHT_ALT_PRESSED
! return vk, modifiers
! # must be a 'key name'
! return key_name_to_vk.get(chardesc.lower()), 0
modifiers = {
***************
*** 71,89 ****
start = pos = 0
max = len(name)
! flags = 0
! scancode = None
while pos<max:
if name[pos] in "+-":
! tok = name[start:pos].lower()
! mod = modifiers.get(tok)
! if mod is None:
! # Its a key name
! scancode = get_scan_code(tok)
! else:
! flags = flags | mod
! pos = pos + 1 # skip the sep
start = pos
! pos = pos + 1
! return scancode, flags
_checks = [
--- 69,89 ----
start = pos = 0
max = len(name)
! toks = []
while pos<max:
if name[pos] in "+-":
! tok = name[start:pos]
! toks.append(tok)
! pos += 1 # skip the sep
start = pos
! pos += 1
! flags = 0
! # do the modifiers
! for tok in toks[:-1]:
! mod = modifiers.get(tok.lower())
! if mod is not None:
! flags |= mod
! # the key name
! vk, this_flags = get_vk(toks[-1])
! return vk, flags | this_flags
_checks = [
***************
*** 103,107 ****
]
! def make_key_name(scancode, flags):
# Check alt keys.
flags_done = 0
--- 103,107 ----
]
! def make_key_name(vk, flags):
# Check alt keys.
flags_done = 0
***************
*** 116,123 ****
parts.append(hex( flags & ~flags_done ) )
# Now the key name.
! try:
! parts.append(key_code_to_name[scancode])
! except KeyError:
! parts.append( "<Unknown scan code %s>" % scancode )
sep = "+"
if sep in parts: sep = "-"
--- 116,129 ----
parts.append(hex( flags & ~flags_done ) )
# Now the key name.
! if vk is None:
! parts.append("<Unknown scan code>")
! else:
! try:
! parts.append(key_code_to_name[vk])
! except KeyError:
! # Not in our virtual key map - ask Windows what character this
! # key corresponds to.
! scancode = win32api.MapVirtualKey(vk, MAPVK_VK_TO_CHAR)
! parts.append(unichr(scancode))
sep = "+"
if sep in parts: sep = "-"
***************
*** 125,129 ****
def _psc(char):
! sc = get_scan_code(char)
print "Char %s -> %d -> %s" % (repr(char), sc, key_code_to_name.get(sc))
--- 131,135 ----
def _psc(char):
! sc, mods = get_vk(char)
print "Char %s -> %d -> %s" % (repr(char), sc, key_code_to_name.get(sc))
***************
*** 135,140 ****
def _pkn(n):
! scancode, flags = parse_key_name(n)
! print "%s -> %s,%s -> %s" % (n, scancode, flags, make_key_name(scancode, flags))
def test2():
--- 141,146 ----
def _pkn(n):
! vk, flags = parse_key_name(n)
! print "%s -> %s,%s -> %s" % (n, vk, flags, make_key_name(vk, flags))
def test2():
***************
*** 152,160 ****
_pkn("Alt+BadKeyName")
_pkn("A")
_pkn("(")
_pkn("Ctrl+(")
_pkn("{")
_pkn("!")
if __name__=='__main__':
! test2()
\ No newline at end of file
--- 158,170 ----
_pkn("Alt+BadKeyName")
_pkn("A")
+ _pkn("a")
_pkn("(")
_pkn("Ctrl+(")
+ _pkn("Ctrl+Shift-8")
+ _pkn("Ctrl+*")
_pkn("{")
_pkn("!")
+ _pkn(".")
if __name__=='__main__':
! test2()
|