wxgoodies/keys.py
def str_to_key(value, key_table = wx, accel_format = 'ACCEL_%s', key_format = 'WXK_%s', key_transpositions = {}):
 """
 Turns a string like "CTRL_ALT+K" into (3, 75).
 
 To get a global hotkey, try passing:
 key_table = win32con, accel_format = 'MOD_%s', key_format = 'VK_%s', key_transpositions = {'CTRL': 'CONTROL'}
 """
 logger.debug('Converting "%s" to integers.', value)
 modifiers = 0
 key = 0
 split = value.split('+')
 for v in split:
  v = v.upper()
  a = accel_format % key_transpositions.get(v, v)
  logger.debug('Accelerator format = %s.', a)
  k = key_format % key_transpositions.get(v, v)
  logger.debug('Key format = %s.', k)
  if hasattr(key_table, a):
   logger.debug('Found accelerator on %r.', key_table)
   modifiers = modifiers | getattr(key_table, a)
  elif hasattr(key_table, k):
   logger.debug('Found key on %r.', key_table)
   if key:
    raise ValueError('Multiple keys specified.')
   else:
    key = getattr(key_table, k)
 if not key:
  logger.debug('No key yet, falling back to ord.')
  key = ord(split[-1])
 logger.debug('modifiers = %d, key = %d.', modifiers, key)
 return (modifiers, key)
def str_to_key(value, key_table = wx, accel_format = 'ACCEL_%s', key_format = 'WXK_%s', key_transpositions = {}):
 """
 Turns a string like "CTRL_ALT+K" into (3, 75).
 
 To get a global hotkey, try passing:
 key_table = win32con, accel_format = 'MOD_%s', key_format = 'VK_%s', key_transpositions = {'CTRL': 'CONTROL'}
 """
 logger.debug('Converting "%s" to integers.', value)
 modifiers = 0
 key = 0
 split = value.split('+')
 for v in split:
  v = v.upper()
  a = accel_format % key_transpositions.get(v, v)
  logger.debug('Accelerator format = %s.', a)
  k = key_format % key_transpositions.get(v, v)
  logger.debug('Key format = %s.', k)
  if hasattr(key_table, a):
   logger.debug('Found accelerator on %r.', key_table)
   modifiers = modifiers | getattr(key_table, a)
  elif hasattr(key_table, k):
   logger.debug('Found key on %r.', key_table)
   if key:
    raise ValueError('Multiple keys specified.')
   else:
    key = getattr(key_table, k)
 if not key:
  logger.debug('No key yet, falling back to ord.')
  key = ord(split[-1])
 logger.debug('modifiers = %d, key = %d.', modifiers, key)
 return (modifiers, key)
def str_to_key ( value , key_table = wx , accel_format = 'ACCEL_%s' , key_format = 'WXK_%s' , key_transpositions = { } ) : logger . debug ( 'Converting "%s" to integers.' , value ) modifiers = 0 key = 0 split = value . split ( '+' ) for v in split : v = v . upper ( ) a = accel_format % key_transpositions . get ( v , v ) logger . debug ( 'Accelerator format = %s.' , a ) k = key_format % key_transpositions . get ( v , v ) logger . debug ( 'Key format = %s.' , k ) if hasattr ( key_table , a ) : logger . debug ( 'Found accelerator on %r.' , key_table ) modifiers = modifiers | getattr ( key_table , a ) elif hasattr ( key_table , k ) : logger . debug ( 'Found key on %r.' , key_table ) if key : raise ValueError ( 'Multiple keys specified.' ) else : key = getattr ( key_table , k ) if not key : logger . debug ( 'No key yet, falling back to ord.' ) key = ord ( split [ - 1 ] ) logger . debug ( 'modifiers = %d, key = %d.' , modifiers , key ) return ( modifiers , key )
Turns a string like "CTRL_ALT+K" into (3, 75).
 
 To get a global hotkey, try passing:
 key_table = win32con, accel_format = 'MOD_%s', key_format = 'VK_%s', key_transpositions = {'CTRL': 'CONTROL'}
Turns a string like CTRL_ALT + K into ( 3 75 ) . To get a global hotkey try passing : key_table = win32con accel_format = MOD_%s key_format = VK_%s key_transpositions = { CTRL : CONTROL }