Beispiel #1
0
    def test_key_to_cfg(self):
        ctrl_s = translate_key_to_config('ctrl s')
        meta_d = translate_key_to_config('meta d')
        esc = translate_key_to_config('esc')
        f4 = translate_key_to_config('f4')

        self.assertEqual(ctrl_s, '<C-s>')
        self.assertEqual(meta_d, '<M-d>')
        self.assertEqual(esc, '<Esc>')
        self.assertEqual(f4, '<F4>')
Beispiel #2
0
    def test_key_to_cfg(self):
        ctrl_s = translate_key_to_config('ctrl s')
        meta_d = translate_key_to_config('meta d')
        esc = translate_key_to_config('esc')
        f4 = translate_key_to_config('f4')

        self.assertEqual(ctrl_s, '<C-s>')
        self.assertEqual(meta_d, '<M-d>')
        self.assertEqual(esc, '<Esc>')
        self.assertEqual(f4, '<F4>')
Beispiel #3
0
    def keypress(self, p_size, p_key):
        urwid.emit_signal(self, 'remove_pending_action')
        requires_further_input = ['postpone', 'postpone_s', 'pri']

        keymap, keystates = self.keymap

        shortcut = self.keystate or ''
        shortcut += translate_key_to_config(p_key)

        try:
            action = keymap[shortcut]
        except KeyError:
            action = None

        if action:
            if shortcut in keystates:
                # Supplied key-shortcut matches keystate and action. Save the
                # keystate in case user will hit another key and add an action
                # waiting for execution if user won't type anything further.
                self.keystate = shortcut
                if action not in requires_further_input:
                    self._add_pending_action(action, p_size)
            else:
                # Only action is matched. Handle it and reset keystate.
                self.resolve_action(action, p_size)
                self.keystate = None
            return
        else:
            if shortcut in keystates:
                self.keystate = shortcut
            else:
                try:
                    # Check whether current keystate matches built-in 'postpone'
                    # action.
                    mode = keymap[self.keystate]
                    if mode in ['postpone', 'postpone_s']:
                        if self._postpone_selected(p_key, mode) is not None:
                            self.keystate = None
                        else:
                            urwid.emit_signal(self, 'show_keystate',
                                              self.keystate + self._pp_offset)
                    else:
                        self.keystate = None
                    return
                except KeyError:
                    if not self.keystate:
                        # Single key that is not described in keymap config.
                        return self.listbox.keypress(p_size, p_key)
                    self.keystate = None
            return
Beispiel #4
0
    def keypress(self, p_size, p_key):
        urwid.emit_signal(self, 'remove_pending_action')
        requires_further_input = ['postpone', 'postpone_s', 'pri']

        keymap, keystates = self.keymap

        shortcut = self.keystate or ''
        shortcut += translate_key_to_config(p_key)

        try:
            action = keymap[shortcut]
        except KeyError:
            action = None

        if action:
            if shortcut in keystates:
                # Supplied key-shortcut matches keystate and action. Save the
                # keystate in case user will hit another key and add an action
                # waiting for execution if user won't type anything further.
                self.keystate = shortcut
                if action not in requires_further_input:
                    self._add_pending_action(action, p_size)
            else:
                # Only action is matched. Handle it and reset keystate.
                self.resolve_action(action, p_size)
                self.keystate = None
            return
        else:
            if shortcut in keystates:
                self.keystate = shortcut
            else:
                try:
                    # Check whether current keystate matches built-in 'postpone'
                    # action.
                    mode = keymap[self.keystate]
                    if mode in ['postpone', 'postpone_s']:
                        if self._postpone_selected(p_key, mode) is not None:
                            self.keystate = None
                        else:
                            urwid.emit_signal(self, 'show_keystate',
                                              self.keystate + self._pp_offset)
                    else:
                        self.keystate = None
                    return
                except KeyError:
                    if not self.keystate:
                        # Single key that is not described in keymap config.
                        return self.listbox.keypress(p_size, p_key)
                    self.keystate = None
            return