Original doc: Present the user with a list of choices.
        return the choice that he selects.
        return None if he cancels the selection selection.
977917
def choicebox(message='Pick something.', title='', choices=['program logic error - no choices specified']):
    
    return psidialogs.choice(message=message, title=title, choices=choices)
1298746
def get_option_choices(opt_name, opt_value, default_value, all_choices):
    

    choices = []
    if isinstance(opt_value, six.string_types):
        choices = [opt_value]
    elif isinstance(opt_value, (list, tuple)):
        choices = list(opt_value)
    elif opt_value is None:
        choices = default_value
    else:
        raise InvalidOption('Option %s has invalid'
                            ' value: %s' % (opt_name, opt_value))
    if 'all' in choices:
        choices = all_choices
    for item in choices:
        if item not in all_choices:
            raise InvalidOption('Choices of option %s contains invalid'
                                ' item: %s' % (opt_name, item))
    return choices
838083
def choose(items, title_text, question_text):
    
    print(title_text)

    for i, item in enumerate(items, start=1):
        print('%d) %s' % (i, item))
    print('%d) Abort' % (i + 1))

    selected = input(question_text)
    try:
        index = int(selected)
    except ValueError:
        index = -1
    if not (index - 1) in range(len(items)):
        print('Aborting.')
        return None

    return items[index - 1]
1254335
def process_user_input(self):
        
        user_input = self.get_input()

        try:
            num = int(user_input)
        except Exception:
            return
        if 0 < num < len(self.items) + 1:
            self.current_option = num - 1
            self.select()

        return user_input
494137
def get_field_choices(self, field, field_name):
        
        if self.request.GET.get('select2'):
            names = ['id', 'text']
        else:
            names = ['value', 'text']
        choices_getter = getattr(self, 'get_field_%s_choices', None)
        if choices_getter is None:
            if isinstance(field, ForeignKey):
                choices_getter = self._get_foreignkey_choices
            else:
                choices_getter = self._get_default_choices
        return [dict(zip(names, choice)) for choice in choices_getter(field, field_name)]
1190566
def user_portals_picker(self):
        
        # print("Getting Portals list. This could take a few seconds...")
        portals = self.get_portals_list()
        done = False
        while not done:
            opts = [ (i, p) for i, p in enumerate(portals) ]
            # print('')
            for opt, portal in opts:
                print("\t{0} - {1}".format(opt, portal[1]))
            # print('')
            valid_choices = [o[0] for o in opts]
            choice = _input("Enter choice ({0}): ".format(valid_choices) )
            if int(choice) in valid_choices:
                done = True

                # loop through all portals until we find an 'id':'rid' match
                self.set_portal_name( opts[int(choice)][1][1] )
                self.set_portal_id( opts[int(choice)][1][0] )
                # self.set_portal_rid( opts[int(choice)][1][2][1]['info']['key'] )
                # self.__portal_sn_rid_dict = opts[int(choice)][1][2][1]['info']['aliases']

            else:
                print("'{0}' is not a valid choice. Please choose from {1}".format(
                    choice, valid_choices))
1038636
def choose(self, choose_from):
        

        for choice in self.elements:
            if choice in choose_from:
                return ImplementationChoice(choice, choose_from[choice])
        raise LookupError(self.elements, choose_from.keys())
958188
def list():
    
    choice_len = max(map(len, _input_choices.keys()))
    tmpl = "  {:<%d}: {}\n" % choice_len
    text = ''.join(map(
        lambda k_v: tmpl.format(k_v[0], k_v[1][0]), six.iteritems(_input_choices)))
    click.echo(text)
847154
def find_selected(self, event):
        ''''''
        first = self.id()
        last = first + len(self.items) - 1
        evid = event.GetId()
        if evid >= first and evid <= last:
            self.choice = evid - first
            return self
        return None
1049379
def choices(self, cl):
        
        #: Just tidy up standard implementation for the sake of DRY principle.
        def _choice_item(is_selected, query_string, title):
            return {
                'selected': is_selected,
                'query_string': query_string,
                'display': force_text(title),
            }

        yield _choice_item(
            self.lookup_val is None,
            cl.get_query_string({}, [self.lookup_kwarg]),
            _('All'))

        container = (self.field.choices
                     if isinstance(self.field, ChoicesField) else
                     self.field.flatchoices)

        for lookup, title in container:
            yield _choice_item(
                smart_text(lookup) == self.lookup_val,
                cl.get_query_string({self.lookup_kwarg: lookup}),
                title)
358138
def choices(self, choices):
        

        if choices is not None and len(choices) > 0:
            self.has_choices = True

        self._choices = choices
309915
def selected(self, new):
        
        def preprocess(item):
            if isinstance(item, str):
                return self.options[item]
            return item
        items = coerce_to_list(new, preprocess)
        self.widget.value = items
1326508
def get_choices(cls, category):
        """"""
        value = cls._DEFAULTS[category]
        if not isinstance(value, list):
            raise ValueError("{} does not offer choices".format(category))
        return value
1021141
def selected(self, ids):
        
        result = copy(self.choices)
        result = filter(lambda x: x[0] in ids, result)
        # result = ((item, item) for item in result)
        return list(result)
889381
def typed_choice(name, choices = [], options = {})
      field name, TypedChoiceField.new(choices, options)
    end
168875
def selection(self):
        """"""
        sel = QtGui.QItemSelection()
        for index in self.selectedIndexes():
            sel.select(index, index)
        return sel
1240101
def _choose(self):
        
        answer = "all"

        if not self.force:
            for i, value in enumerate(self.current_values):
                self.out("{:>2d}. {}".format(i + 1, value))

            answer = self.prompt(
                'Which value to remove? Enter number or "all": ')

        if answer != "all":
            try:
                answer = int(answer) - 1

                if answer < 0 or answer >= len(self.current_values):
                    answer = None
            except ValueError:
                answer = None

        return answer