示例#1
0
    def matches(self, user_input):
        r'''True when menu entry matches `user_input` string.

        ::

            >>> menu_entry.matches('update')
            True

        ::

            >>> menu_entry.matches('up')
            True

        Otherwise false:

        ::

            >>> menu_entry.matches('foo')
            False

        Returns boolean.
        '''
        if self.key is not None and user_input == self.key:
            return True
        if self.menu_section.is_numbered and user_input == str(self.number):
            return True
        if 3 <= len(user_input):
            normalized_display_string = \
                stringtools.strip_diacritics_from_binary_string(
                self.display_string)
            normalized_display_string = normalized_display_string.lower()
            if normalized_display_string.startswith(user_input):
                return True
        return False 
示例#2
0
 def _change_user_input_to_directive(self, user_input):
     user_input = stringtools.strip_diacritics_from_binary_string(
         user_input)
     user_input = user_input.lower()
     if self._user_enters_nothing(user_input):
         default_value = None
         for menu_section in self.menu_sections:
             if menu_section._has_default_value:
                 default_value = menu_section._default_value
         if default_value is not None:
             return self._enclose_in_list(default_value)
     elif self._user_enters_argument_range(user_input):
         return self._handle_argument_range_user_input(user_input)
     elif user_input == 'r':
         return 'r'
     else:
         for menu_section in self.menu_sections:
             for menu_entry in menu_section.menu_entries:
                 if menu_entry.display_string == 'redraw':
                     continue
                 if menu_entry.matches(user_input):
                     return self._enclose_in_list(
                         menu_entry.return_value)
示例#3
0
文件: Menu.py 项目: willingc/abjad
 def _change_user_input_to_directive(self, user_input):
     user_input = stringtools.strip_diacritics_from_binary_string(
         user_input)
     if self._user_enters_nothing(user_input):
         default_value = None
         for menu_section in self.menu_sections:
             if menu_section._has_default_value:
                 default_value = menu_section._default_value
         if default_value is not None:
             return self._enclose_in_list(default_value)
     elif user_input in ('s', 'h', 'q', 'b', 'n', '?', 'r'):
         return user_input
     elif user_input.startswith('!'):
         return user_input
     for menu_section in self.menu_sections:
         for menu_entry in menu_section.menu_entries:
             if menu_entry.matches(user_input):
                 return self._enclose_in_list(menu_entry.return_value)
     for menu_section in self.menu_sections:
         for menu_entry in menu_section.menu_entries:
             if menu_entry.matches(user_input.lower()):
                 return self._enclose_in_list(menu_entry.return_value)
     if self._user_enters_argument_range(user_input):
         return self._handle_argument_range_user_input(user_input)