Esempio n. 1
0
def switch_mode(mode = 'operation'):
 """Switch the mode."""
 modes = globals().get('%s_modes' % mode)
 if mode == 'operation':
  modes = [x.name for x in modes]
 m = modes.index(application.config.get('settings', '%s_mode' % mode)) + 1
 if m == len(modes):
  m = 0
 application.config.set('settings', '%s_mode' % mode, modes[m])
 output.output(modes[m])
Esempio n. 2
0
 def handle_hotkey(self, key):
  """Does the actual handling in a platform-independant way."""
  if self.key_timer:
   self.key_timer.cancel()
  key = key.lower()
  mode = modes.get_current_mode()
  if key == 'subtract':
   get_menu()
  elif key in ['divide', 'decimal']:
   modes.switch_mode({'divide': 'operation', 'decimal': 'shift'}[key])
   if key == 'decimal':
    self.autocapitalise = False
  elif key == 'add':
   if mode in [modes.MODE_OPERATION_STANDARD, modes.MODE_OPERATION_NUMBERS]:
    self.press_current_key()
    press('backspace')
   else:
    pressHoldRelease(application.config.get(mode.name, key, 'alt'))
  elif key == 'multiply':
   self.press_current_key()
  else:
   if mode == modes.MODE_OPERATION_NUMBERS: # Pass numbers straight through.
    press(key[-1])
   elif mode == modes.MODE_OPERATION_STANDARD:
    if key == 'enter':
     self.key_value = 'enter'
    elif key == self.last_key:
     self.index += 1
    else:
     self.press_current_key()
     self.index = 0
    possible_keys = application.config.get('keys', key)
    if self.index >= len(possible_keys):
     self.index = 0
    self.key_value = possible_keys[self.index]
    if self.key_value == ' ': # A space must be converted before sending.
     self.key_value = 'spacebar'
    output.output(self.key_value)
   else:
    pressHoldRelease(application.config.get(mode.name, key))
  self.last_key = key
  if mode == modes.MODE_OPERATION_STANDARD:
   t = time()
   self.key_timer = Timer(application.config.get('settings', 'timeout'), self.press_current_key, args = [t])
   self.key_timer.start()
   self.last_key_time = t