Changeset 1419
- Timestamp:
- 07/13/06 17:03:17 (2 years ago)
- Files:
-
- pyreadline/branches/refactor/doc/ChangeLog (modified) (1 diff)
- pyreadline/branches/refactor/pyreadline/__init__.py (modified) (1 diff)
- pyreadline/branches/refactor/pyreadline/clipboard/__init__.py (modified) (1 diff)
- pyreadline/branches/refactor/pyreadline/clipboard/clipboard.py (modified) (1 diff)
- pyreadline/branches/refactor/pyreadline/clipboard/common.py (deleted)
- pyreadline/branches/refactor/pyreadline/console/__init__.py (modified) (1 diff)
- pyreadline/branches/refactor/pyreadline/console/console.py (modified) (7 diffs)
- pyreadline/branches/refactor/pyreadline/console/event.py (modified) (1 diff)
- pyreadline/branches/refactor/pyreadline/console/ironpython_console.py (modified) (9 diffs)
- pyreadline/branches/refactor/pyreadline/keysyms/__init__.py (modified) (1 diff)
- pyreadline/branches/refactor/pyreadline/keysyms/common.py (added)
- pyreadline/branches/refactor/pyreadline/keysyms/ironpython_keysyms.py (modified) (2 diffs)
- pyreadline/branches/refactor/pyreadline/keysyms/keysyms.py (modified) (2 diffs)
- pyreadline/branches/refactor/pyreadline/modes/basemode.py (modified) (2 diffs)
- pyreadline/branches/refactor/pyreadline/modes/emacs.py (modified) (3 diffs)
- pyreadline/branches/refactor/pyreadline/modes/notemacs.py (modified) (2 diffs)
- pyreadline/branches/refactor/pyreadline/modes/vi.py (modified) (2 diffs)
- pyreadline/branches/refactor/pyreadline/rlmain.py (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
pyreadline/branches/refactor/doc/ChangeLog
r1385 r1419 1 2006-07-13 Jörgen Stenarson <jorgen.stenarson -at- bostream.nu> 2 * Work to get selection between ironpython and cpython to work 3 * Some editing works but there are issues with control keys for ironpython 4 1 5 2006-07-04 Jörgen Stenarson <jorgen.stenarson -at- bostream.nu> 2 6 * First commit for ironpython. Typing in alphabet works but no special keys. pyreadline/branches/refactor/pyreadline/__init__.py
r1385 r1419 7 7 # the file COPYING, distributed as part of this software. 8 8 #***************************************************************************** 9 10 9 import logger,clipboard,lineeditor,modes 11 10 from rlmain import * pyreadline/branches/refactor/pyreadline/clipboard/__init__.py
r1385 r1419 1 from common import *2 1 success=False 2 3 3 try: 4 4 from clipboard import GetClipboardText,SetClipboardText 5 5 success=True 6 6 except ImportError: 7 pass 8 9 try: 10 from ironpython_clipboard import GetClipboardText,SetClipboardText 11 success=True 12 except ImportError: 13 pass 7 try: 8 from ironpython_clipboard import GetClipboardText,SetClipboardText 9 success=True 10 except ImportError: 11 pass 14 12 15 13 16 14 17 15 16 17 18 def send_data(lists): 19 SetClipboardText(make_tab(lists)) 20 21 22 def set_clipboard_text(toclipboard): 23 SetClipboardText(str(toclipboard)) 24 25 def make_tab(lists): 26 if hasattr(lists,"tolist"): 27 lists=lists.tolist() 28 ut=[] 29 for rad in lists: 30 if type(rad) in [list,tuple]: 31 ut.append("\t".join(["%s"%x for x in rad])) 32 else: 33 ut.append("%s"%rad) 34 return "\n".join(ut) 35 36 def make_list_of_list(txt): 37 def make_num(x): 38 try: 39 return int(x) 40 except ValueError: 41 try: 42 return float(x) 43 except ValueError: 44 try: 45 return complex(x) 46 except ValueError: 47 return x 48 return x 49 ut=[] 50 flag=False 51 for rad in [x for x in txt.split("\r\n") if x!=""]: 52 raden=[make_num(x) for x in rad.split("\t")] 53 if str in map(type,raden): 54 flag=True 55 ut.append(raden) 56 return ut,flag 57 58 59 def get_clipboard_text_and_convert(paste_list=False): 60 """Get txt from clipboard. if paste_list==True the convert tab separated 61 data to list of lists. Enclose list of list in array() if all elements are 62 numeric""" 63 txt=GetClipboardText() 64 if txt: 65 if paste_list and "\t" in txt: 66 array,flag=make_list_of_list(txt) 67 if flag: 68 txt=repr(array) 69 else: 70 txt="array(%s)"%repr(array) 71 txt="".join([c for c in txt if c not in " \t\r\n"]) 72 return txt 73 pyreadline/branches/refactor/pyreadline/clipboard/clipboard.py
r1385 r1419 35 35 36 36 from ctypes import * 37 from keysyms.winconstants import CF_TEXT, GHND37 from pyreadline.keysyms.winconstants import CF_TEXT, GHND 38 38 39 39 OpenClipboard = windll.user32.OpenClipboard pyreadline/branches/refactor/pyreadline/console/__init__.py
r1385 r1419 7 7 success=True 8 8 except ImportError: 9 pass10 9 11 try:12 from ironpython_console import *13 success=True14 except ImportError:15 pass10 try: 11 from ironpython_console import * 12 success=True 13 except ImportError: 14 pass 16 15 17 16 pyreadline/branches/refactor/pyreadline/console/console.py
r1385 r1419 27 27 28 28 # my code 29 from pyreadline.keysyms import make_ keysym, make_keyinfo29 from pyreadline.keysyms import make_KeyPress 30 30 31 31 # some constants we need … … 460 460 while 1: 461 461 e = self.get() 462 log("getKeypress:%s,%s,%s"%(e.keyinfo,e.keycode,e.type))463 462 if e.type == 'KeyPress' and e.keycode not in key_modifiers: 464 463 log(e) … … 470 469 return e 471 470 elif e.type == 'KeyRelease' and e.keyinfo==(True, False, False, 83): 471 log("getKeypress:%s,%s,%s"%(e.keyinfo,e.keycode,e.type)) 472 472 return e 473 473 … … 545 545 from event import Event 546 546 547 VkKeyScan = windll.user32.VkKeyScanA 548 549 547 550 class event(Event): 548 551 '''Represent events from the console.''' … … 558 561 self.keycode = 0 559 562 self.keysym = '??' 560 self.keyinfo = ''# a tuple with (control, meta, shift, keycode) for dispatch563 self.keyinfo = None # a tuple with (control, meta, shift, keycode) for dispatch 561 564 self.width = None 562 565 563 566 if input.EventType == KEY_EVENT: 564 567 if input.Event.KeyEvent.bKeyDown: … … 569 572 self.keycode = input.Event.KeyEvent.wVirtualKeyCode 570 573 self.state = input.Event.KeyEvent.dwControlKeyState 571 self.key sym = make_keysym(self.keycode)572 self.keyinfo = make_keyinfo(self.keycode, self.state) 574 self.keyinfo=make_KeyPress(self.char,self.state,self.keycode) 575 573 576 elif input.EventType == MOUSE_EVENT: 574 577 if input.Event.MouseEvent.dwEventFlags & MOUSE_MOVED: … … 691 694 if __name__ == '__main__': 692 695 import time, sys 696 697 698 def p(char): 699 return chr(VkKeyScan(ord(char)) & 0xff) 700 693 701 c = Console(0) 694 702 sys.stdout = c 695 703 sys.stderr = c 696 704 c.page() 705 print p("d"),p("D") 697 706 c.pos(5, 10) 698 707 c.write('hi there') pyreadline/branches/refactor/pyreadline/console/event.py
r1385 r1419 20 20 s = 'unknown event type' 21 21 return s 22 23 24 # def __str__(self): 25 # return "('%s',%s,%s,%s)"%(self.char,self.key,self.state,self.keyinfo) pyreadline/branches/refactor/pyreadline/console/ironpython_console.py
r1385 r1419 13 13 14 14 import clr 15 clr.AddReference(" IronPythonConsole.exe")15 clr.AddReference("ipy.exe") 16 16 import IronPythonConsole 17 17 … … 26 26 from pyreadline.logger import log 27 27 28 print "Codepage",System.Console.InputEncoding.CodePage29 from pyreadline.keysyms import make_keysym, make_keyinfo 28 #print "Codepage",System.Console.InputEncoding.CodePage 29 from pyreadline.keysyms import make_keysym, make_keyinfo,make_KeyPress 30 30 31 31 color=System.ConsoleColor … … 62 62 self.attr = System.Console.ForegroundColor 63 63 self.saveattr = System.Console.ForegroundColor 64 log('initial attr=% x' % self.attr)64 log('initial attr=%s' % self.attr) 65 65 66 66 def __del__(self): … … 220 220 pass 221 221 #raise NotImplementedError 222 x0, y0, x1, y1 = rect 223 if attr is None: 224 attr = self.attr 225 if fill: 226 rowfill=fill[:1]*abs(x1-x0) 227 else: 228 rowfill=' '*abs(x1-x0) 229 for y in range(y0, y1): 230 System.Console.SetCursorPosition(x0,y) 231 self.write_color(rowfill,attr) 222 232 223 233 def scroll(self, rect, dx, dy, attr=None, fill=' '): … … 264 274 return sc.WindowWidth,sc.WindowHeight 265 275 266 def cursor(self, visible= None, size=None):276 def cursor(self, visible=True, size=None): 267 277 '''Set cursor on or off.''' 268 278 System.Console.CursorVisible=visible … … 286 296 self.x = 0 287 297 self.y = 0 288 self.char = chr(input.KeyChar)298 self.char = str(input.KeyChar) 289 299 self.keycode = input.Key 290 300 self.state = input.Modifiers … … 293 303 294 304 self.keysym = make_keysym(self.keycode) 295 self.keyinfo = make_ keyinfo(self.keycode, self.state)305 self.keyinfo = make_KeyPress(self.char, self.state, self.keycode) 296 306 297 307 … … 316 326 return c 317 327 318 if __name__ == '_ zx_main__':328 if __name__ == '__main__': 319 329 import time, sys 320 330 c = Console(0) … … 334 344 del c 335 345 346 System.Console.Clear() pyreadline/branches/refactor/pyreadline/keysyms/__init__.py
r1385 r1419 6 6 success=True 7 7 except ImportError,x: 8 pass9 8 10 try:11 from ironpython_keysyms import *12 success=True13 except ImportError,x:14 pass9 try: 10 from ironpython_keysyms import * 11 success=True 12 except ImportError,x: 13 pass 15 14 16 15 if not success: pyreadline/branches/refactor/pyreadline/keysyms/ironpython_keysyms.py
r1385 r1419 8 8 #***************************************************************************** 9 9 import System 10 from common import validkey,KeyPress,make_KeyPress_from_keydescr 10 11 11 12 c32=System.ConsoleKey 13 Shift=System.ConsoleModifiers.Shift 14 Control=System.ConsoleModifiers.Control 15 Alt=System.ConsoleModifiers.Alt 12 16 # table for translating virtual keys to X windows key symbols 13 17 code2sym_map = {#c32.CANCEL: 'Cancel', … … 185 189 shift=False 186 190 return (control, meta, shift, keycode) 191 192 193 def make_KeyPress(char,state,keycode): 194 195 shift=bool(int(state)&int(Shift)) 196 control=bool(int(state)&int(Control)) 197 meta=bool(int(state)&int(Alt)) 198 keyname=code2sym_map.get(keycode,"").lower() 199 if control: 200 char=str(keycode) 201 return KeyPress(char,shift,control,meta,keyname) 202 pyreadline/branches/refactor/pyreadline/keysyms/keysyms.py
r1385 r1419 11 11 import ctypes 12 12 # table for translating virtual keys to X windows key symbols 13 code2sym_map = {c32.VK_CANCEL: 'Cancel', 14 c32.VK_BACK: 'BackSpace', 15 c32.VK_TAB: 'Tab', 16 c32.VK_CLEAR: 'Clear', 17 c32.VK_RETURN: 'Return', 18 c32.VK_SHIFT:'Shift_L', 19 c32.VK_CONTROL: 'Control_L', 20 c32.VK_MENU: 'Alt_L', 21 c32.VK_PAUSE: 'Pause', 22 c32.VK_CAPITAL: 'Caps_Lock', 23 c32.VK_ESCAPE: 'Escape', 24 c32.VK_SPACE: 'space', 25 c32.VK_PRIOR: 'Prior', 26 c32.VK_NEXT: 'Next', 27 c32.VK_END: 'End', 28 c32.VK_HOME: 'Home', 29 c32.VK_LEFT: 'Left', 30 c32.VK_UP: 'Up', 31 c32.VK_RIGHT: 'Right', 32 c32.VK_DOWN: 'Down', 33 c32.VK_SELECT: 'Select', 34 c32.VK_PRINT: 'Print', 35 c32.VK_EXECUTE: 'Execute', 36 c32.VK_SNAPSHOT: 'Snapshot', 37 c32.VK_INSERT: 'Insert', 38 c32.VK_DELETE: 'Delete', 39 c32.VK_HELP: 'Help', 40 c32.VK_F1: 'F1', 41 c32.VK_F2: 'F2', 42 c32.VK_F3: 'F3', 43 c32.VK_F4: 'F4', 44 c32.VK_F5: 'F5', 45 c32.VK_F6: 'F6', 46 c32.VK_F7: 'F7', 47 c32.VK_F8: 'F8', 48 c32.VK_F9: 'F9', 49 c32.VK_F10: 'F10', 50 c32.VK_F11: 'F11', 51 c32.VK_F12: 'F12', 52 c32.VK_F13: 'F13', 53 c32.VK_F14: 'F14', 54 c32.VK_F15: 'F15', 55 c32.VK_F16: 'F16', 56 c32.VK_F17: 'F17', 57 c32.VK_F18: 'F18', 58 c32.VK_F19: 'F19', 59 c32.VK_F20: 'F20', 60 c32.VK_F21: 'F21', 61 c32.VK_F22: 'F22', 62 c32.VK_F23: 'F23', 63 c32.VK_F24: 'F24', 64 c32.VK_NUMLOCK: 'Num_Lock,', 65 c32.VK_SCROLL: 'Scroll_Lock', 66 c32.VK_APPS: 'VK_APPS', 67 c32.VK_PROCESSKEY: 'VK_PROCESSKEY', 68 c32.VK_ATTN: 'VK_ATTN', 69 c32.VK_CRSEL: 'VK_CRSEL', 70 c32.VK_EXSEL: 'VK_EXSEL', 71 c32.VK_EREOF: 'VK_EREOF', 72 c32.VK_PLAY: 'VK_PLAY', 73 c32.VK_ZOOM: 'VK_ZOOM', 74 c32.VK_NONAME: 'VK_NONAME', 75 c32.VK_PA1: 'VK_PA1', 76 c32.VK_OEM_CLEAR: 'VK_OEM_CLEAR', 77 c32.VK_NUMPAD0: 'NUMPAD0', 78 c32.VK_NUMPAD1: 'NUMPAD1', 79 c32.VK_NUMPAD2: 'NUMPAD2', 80 c32.VK_NUMPAD3: 'NUMPAD3', 81 c32.VK_NUMPAD4: 'NUMPAD4', 82 c32.VK_NUMPAD5: 'NUMPAD5', 83 c32.VK_NUMPAD6: 'NUMPAD6', 84 c32.VK_NUMPAD7: 'NUMPAD7', 85 c32.VK_NUMPAD8: 'NUMPAD8', 86 c32.VK_NUMPAD9: 'NUMPAD9', 87 c32.VK_DIVIDE: 'Divide', 88 c32.VK_MULTIPLY: 'Multiply', 89 c32.VK_ADD: 'Add', 90 c32.VK_SUBTRACT: 'Subtract', 91 c32.VK_DECIMAL: 'VK_DECIMAL' 13 14 from common import validkey,KeyPress,make_KeyPress_from_keydescr 15 16 code2sym_map = {c32.VK_CANCEL: 'cancel', 17 c32.VK_BACK: 'backspace', 18 c32.VK_TAB: 'tab', 19 c32.VK_CLEAR: 'clear', 20 c32.VK_RETURN: 'return', 21 c32.VK_SHIFT: 'shift_l', 22 c32.VK_CONTROL: 'control_l', 23 c32.VK_MENU: 'alt_l', 24 c32.VK_PAUSE: 'pause', 25 c32.VK_CAPITAL: 'caps_lock', 26 c32.VK_ESCAPE: 'escape', 27 c32.VK_SPACE: 'space', 28 c32.VK_PRIOR: 'prior', 29 c32.VK_NEXT: 'next', 30 c32.VK_END: 'end', 31 c32.VK_HOME: 'home', 32 c32.VK_LEFT: 'left', 33 c32.VK_UP: 'up', 34 c32.VK_RIGHT: 'right', 35 c32.VK_DOWN: 'down', 36 c32.VK_SELECT: 'select', 37 c32.VK_PRINT: 'print', 38 c32.VK_EXECUTE: 'execute', 39 c32.VK_SNAPSHOT: 'snapshot', 40 c32.VK_INSERT: 'insert', 41 c32.VK_DELETE: 'delete', 42 c32.VK_HELP: 'help', 43 c32.VK_F1: 'f1', 44 c32.VK_F2: 'f2', 45 c32.VK_F3: 'f3', 46 c32.VK_F4: 'f4', 47 c32.VK_F5: 'f5', 48 c32.VK_F6: 'f6', 49 c32.VK_F7: 'f7', 50 c32.VK_F8: 'f8', 51 c32.VK_F9: 'f9', 52 c32.VK_F10: 'f10', 53 c32.VK_F11: 'f11', 54 c32.VK_F12: 'f12', 55 c32.VK_F13: 'f13', 56 c32.VK_F14: 'f14', 57 c32.VK_F15: 'f15', 58 c32.VK_F16: 'f16', 59 c32.VK_F17: 'f17', 60 c32.VK_F18: 'f18', 61 c32.VK_F19: 'f19', 62 c32.VK_F20: 'f20', 63 c32.VK_F21: 'f21', 64 c32.VK_F22: 'f22', 65 c32.VK_F23: 'f23', 66 c32.VK_F24: 'f24', 67 c32.VK_NUMLOCK: 'num_lock,', 68 c32.VK_SCROLL: 'scroll_lock', 69 c32.VK_APPS: 'vk_apps', 70 c32.VK_PROCESSKEY: 'vk_processkey', 71 c32.VK_ATTN: 'vk_attn', 72 c32.VK_CRSEL: 'vk_crsel', 73 c32.VK_EXSEL: 'vk_exsel', 74 c32.VK_EREOF: 'vk_ereof', 75 c32.VK_PLAY: 'vk_play', 76 c32.VK_ZOOM: 'vk_zoom', 77 c32.VK_NONAME: 'vk_noname', 78 c32.VK_PA1: 'vk_pa1', 79 c32.VK_OEM_CLEAR :'vk_oem_clear', 80 c32.VK_NUMPAD0: 'numpad0', 81 c32.VK_NUMPAD1: 'numpad1', 82 c32.VK_NUMPAD2: 'numpad2', 83 c32.VK_NUMPAD3: 'numpad3', 84 c32.VK_NUMPAD4: 'numpad4', 85 c32.VK_NUMPAD5: 'numpad5', 86 c32.VK_NUMPAD6: 'numpad6', 87 c32.VK_NUMPAD7: 'numpad7', 88 c32.VK_NUMPAD8: 'numpad8', 89 c32.VK_NUMPAD9: 'numpad9', 90 c32.VK_DIVIDE: 'divide', 91 c32.VK_MULTIPLY: 'multiply', 92 c32.VK_ADD: 'add', 93 c32.VK_SUBTRACT: 'subtract', 94 c32.VK_DECIMAL: 'vk_decimal' 92 95 } 93 94 # function to handle the mapping95 def make_keysym(keycode):96 try:97 sym = code2sym_map[keycode]98 except KeyError:99 sym = ''100 return sym101 102 sym2code_map = {}103 for code,sym in code2sym_map.iteritems():104 sym2code_map[sym.lower()] = code105 106 def key_text_to_keyinfo(keytext):107 '''Convert a GNU readline style textual description of a key to keycode with modifiers'''108 if keytext.startswith('"'): # "109 return keyseq_to_keyinfo(keytext[1:-1])110 else:111 return keyname_to_keyinfo(keytext)112 96 113 97 VkKeyScan = windll.user32.VkKeyScanA 114 98 115 99 def char_to_keyinfo(char, control=False, meta=False, shift=False): 100 k=KeyPress() 116 101 vk = VkKeyScan(ord(char)) 117 102 if vk & 0xffff == 0xffff: … … 119 104 raise ValueError, 'bad key' 120 105 if vk & 0x100: 121 shift = True106 k.shift = True 122 107 if vk & 0x200: 123 control = True108 k.control = True 124 109 if vk & 0x400: 125 meta = True 126 return (control, meta, shift, vk & 0xff) 110 k.meta = True 111 k.char=chr(vk & 0xff) 112 return k 127 113 128 def keyname_to_keyinfo(keyname): 129 control = False 130 meta = False 131 shift = False 132 133 while 1: 134 lkeyname = keyname.lower() 135 if lkeyname.startswith('control-'): 136 control = True 137 keyname = keyname[8:] 138 elif lkeyname.startswith('ctrl-'): 139 control = True 140 keyname = keyname[5:] 141 elif lkeyname.startswith('meta-'): 142 meta = True 143 keyname = keyname[5:] 144 elif lkeyname.startswith('alt-'): 145 meta = True 146 keyname = keyname[4:] 147 elif lkeyname.startswith('shift-'): 148 shift = True 149 keyname = keyname[6:] 150 else: 151 if len(keyname) > 1: 152 return (control, meta, shift, sym2code_map.get(keyname.lower()," ")) 153 else: 154 return char_to_keyinfo(keyname, control, meta, shift) 155 156 def keyseq_to_keyinfo(keyseq): 157 res = [] 158 control = False 159 meta = False 160 shift = False 161 162 while 1: 163 if keyseq.startswith('\\C-'): 164 control = True 165 keyseq = keyseq[3:] 166 elif keyseq.startswith('\\M-'): 167 meta = True 168 keyseq = keyseq[3:] 169 elif keyseq.startswith('\\e'): 170 res.append(char_to_keyinfo('\033', control, meta, shift)) 171 control = meta = shift = False 172 keyseq = keyseq[2:] 173 elif len(keyseq) >= 1: 174 res.append(char_to_keyinfo(keyseq[0], control, meta, shift)) 175 control = meta = shift = False 176 keyseq = keyseq[1:] 177 else: 178 return res[0] 179 180 def make_keyinfo(keycode, state): 114 def make_KeyPress(char,state,keycode): 181 115 control = (state & (4+8)) != 0 182 116 meta = (state & (1+2)) != 0 183 117 shift = (state & 0x10) != 0 184 return (control, meta, shift, keycode) 118 if control: 119 char = chr(VkKeyScan(ord(char)) & 0xff) 120 try: 121 keyname=code2sym_map[keycode] 122 except KeyError: 123 keyname="" 124 return KeyPress(char,shift,control,meta,keyname) 125 126 if __name__=="__main__": 127 import startup 128 pyreadline/branches/refactor/pyreadline/modes/basemode.py
r1267 r1419 10 10 import pyreadline.logger as logger 11 11 from pyreadline.logger import log 12 from pyreadline.keysyms import key_text_to_keyinfo12 from pyreadline.keysyms.common import make_KeyPress_from_keydescr 13 13 import pyreadline.lineeditor.lineobj as lineobj 14 14 import pyreadline.lineeditor.history as history … … 76 76 def _bind_key(self, key, func): 77 77 '''setup the mapping from key to call the function.''' 78 keyinfo = key_text_to_keyinfo(key) 79 # print key,keyinfo,func.__name__ 78 keyinfo = make_KeyPress_from_keydescr(key.lower()).tuple() 80 79 self.key_dispatch[keyinfo] = func 81 80 82 81 def _bind_exit_key(self, key): 83 82 '''setup the mapping from key to call the function.''' 84 keyinfo = key_text_to_keyinfo(key)83 keyinfo = make_KeyPress_from_keydescr(key.lower()).tuple() 85 84 self.exit_dispatch[keyinfo] = None 86 85 pyreadline/branches/refactor/pyreadline/modes/emacs.py
r1385 r1419 10 10 import pyreadline.logger as logger 11 11 from pyreadline.logger import log 12 from pyreadline.keysyms import key_text_to_keyinfo13 12 import pyreadline.lineeditor.lineobj as lineobj 14 13 import pyreadline.lineeditor.history as history 15 14 import basemode 16 17 15 18 16 … … 42 40 43 41 #Process exit keys. Only exit on empty line 44 if event.keyinfo in self.exit_dispatch:42 if event.keyinfo.tuple() in self.exit_dispatch: 45 43 if lineobj.EndOfLine(self.l_buffer) == 0: 46 44 raise EOFError 47 48 dispatch_func = self.key_dispatch.get(event.keyinfo ,self.self_insert)49 log("readline from keyboard:%s"%(event.keyinfo ,))45 46 dispatch_func = self.key_dispatch.get(event.keyinfo.tuple(),self.self_insert) 47 log("readline from keyboard:%s"%(event.keyinfo.tuple(),)) 50 48 r = None 51 49 if dispatch_func: … … 482 480 483 481 #Create key bindings: 484 485 def _bind_key(self, key, func):486 '''setup the mapping from key to call the function.'''487 # print key,func488 keyinfo = key_text_to_keyinfo(key)489 # print key,keyinfo,func.__name__490 self.key_dispatch[keyinfo] = func491 492 def _bind_exit_key(self, key):493 '''setup the mapping from key to call the function.'''494 keyinfo = key_text_to_keyinfo(key)495 self.exit_dispatch[keyinfo] = None496 482 497 483 def init_editing_mode(self, e): # (C-e) pyreadline/branches/refactor/pyreadline/modes/notemacs.py
r1219 r1419 10 10 import pyreadline.logger as logger 11 11 from pyreadline.logger import log 12 from pyreadline.keysyms import key_text_to_keyinfo13 12 import pyreadline.lineeditor.lineobj as lineobj 14 13 import pyreadline.lineeditor.history as history … … 565 564 #Create key bindings: 566 565 567 def _bind_key(self, key, func):568 '''setup the mapping from key to call the function.'''569 keyinfo = key_text_to_keyinfo(key)570 # print key,keyinfo,func.__name__571 self.key_dispatch[keyinfo] = func572 573 def _bind_exit_key(self, key):574 '''setup the mapping from key to call the function.'''575 keyinfo = key_text_to_keyinfo(key)576 self.exit_dispatch[keyinfo] = None577 578 566 def init_editing_mode(self, e): # (C-e) 579 567 '''When in vi command mode, this causes a switch to emacs editing pyreadline/branches/refactor/pyreadline/modes/vi.py
r1237 r1419 11 11 import pyreadline.logger as logger 12 12 from pyreadline.logger import log 13 from pyreadline.keysyms import key_text_to_keyinfo14 13 import pyreadline.lineeditor.lineobj as lineobj 15 14 import pyreadline.lineeditor.history as history … … 114 113 # make ' ' to ~ self insert 115 114 for c in range(ord(' '), 127): 116 self._bind_key(' "%s"' % chr(c), self.vi_key)115 self._bind_key('%s' % chr(c), self.vi_key) 117 116 self._bind_key('BackSpace', self.vi_backspace) 118 117 self._bind_key('Escape', self.vi_escape) pyreadline/branches/refactor/pyreadline/rlmain.py
r1267 r1419 13 13 import sys 14 14 from glob import glob 15 import os 15 import os,pdb 16 16 import re 17 17 import traceback … … 21 21 import clipboard,logger,console 22 22 from logger import log 23 from keysyms import key_text_to_keyinfo23 from pyreadline.keysyms.common import make_KeyPress_from_keydescr 24 24 25 25 import pyreadline.lineeditor.lineobj as lineobj … … 252 252 out.append("%-20s: %s"%("mark_directories",self.mark_directories)) 253 253 out.append("------------- key bindings ------------") 254 out.append("%7s %7s %7s %7s %7s %7s"%("Control","Meta","Shift","Keycode","Character","Function")) 255 bindings=[(k[0],k[1],k[2],k[3],repr(chr(k[3])),v.__name__)for k,v in self.key_dispatch.iteritems()] 254 tablepat="%-7s %-7s %-7s %-15s %-15s " 255 out.append(tablepat%("Control","Meta","Shift","Keycode/char","Function")) 256 bindings=[(k[0],k[1],k[2],k[3],v.__name__)for k,v in self.mode.key_dispatch.iteritems()] 257 #print self.mode.key_dispatch 258 #bindings=[str(v) for k,v in self.mode.key_dispatch.iteritems()] 256 259 bindings.sort() 257 260 for key in bindings: 258 out.append("%7s %7s %7s %7d %7s %7s"%(key)) 261 pass 262 # out.append(str(key)) 263 out.append(tablepat%(key)) 259 264 return out 260 265 … … 332 337 self.mode=modes[name] 333 338 def bind_key(key,name): 339 # print "bind",key,name 334 340 if hasattr(modes[mode],name): 335 #printkey,name341 # print "can bind",key,name 336 342 modes[mode]._bind_key(key,getattr(modes[mode],name)) 337 343 def un_bind_key(key): 338 keyinfo = key_text_to_keyinfo(key)344 keyinfo = make_KeyPress_from_keydescr(key).tuple() 339 345 if keyinfo in modes[mode].key_dispatch: 340 346 del modes[mode].key_dispatch[keyinfo] … … 343 349 modes[mode]._bind_exit_key(key) 344 350 def un_bind_exit_key(key): 345 keyinfo = key_text_to_keyinfo(key)351 keyinfo = make_KeyPress_from_keydescr(key).tuple() 346 352 if keyinfo in modes[mode].exit_dispatch: 347 353 del modes[mode].exit_dispatch[keyinfo] … … 404 410 rl = Readline() 405 411 412 406 413 def GetOutputFile(): 407 414 '''Return the console object used by readline so that it can be used for printing in color.'''
