def main(): """Main. """ if cutie.prompt_yes_or_no('Are you brave enough to continue?'): # List of names to select from, including some captions names = [ 'Kings:', 'Arthur, King of the Britons', 'Knights of the Round Table:', 'Sir Lancelot the Brave', 'Sir Robin the Not-Quite-So-Brave-as-Sir-Lancelot', 'Sir Bedevere the Wise', 'Sir Galahad the Pure', 'Swedish captions:', 'Møøse' ] # Names which are captions and thus not selectable captions = [0, 2, 7] # Get the name name = names[cutie.select(names, caption_indices=captions, selected_index=8)] print(f'Welcome, {name}') # Get an integer greater or equal to 0 age = cutie.get_number('What is your age?', min_value=0, allow_float=False) nemeses_options = [ 'The French', 'The Police', 'The Knights Who Say Ni', 'Women', 'The Black Knight', 'The Bridge Keeper', 'Especially terrifying:', 'The Rabbit of Caerbannog', ] print('Choose your nemeses') # Choose multiple options from a list nemeses_indices = cutie.select_multiple(nemeses_options, caption_indices=[6]) nemeses = [ nemesis for nemesis_index, nemesis in enumerate(nemeses_options) if nemesis_index in nemeses_indices ] # Get input without showing it being typed quest = cutie.secure_input('What is your quest?') print(f'{name}\'s quest (who is {age}) is {quest}.') if nemeses: if len(nemeses) == 1: print(f'His nemesis is {nemeses[0]}.') else: print(f'His nemeses are {" and ".join(nemeses)}.') else: print('He has no nemesis.')
def _prompt_app_list(self): """Creates the checkbox which one to choose from. """ print("Choose which applications to install:") package_names = self._names(self._package_file) selection = cutie.select_multiple(package_names, ticked_indices=self._default_file, deselected_unticked_prefix=' ⬡ ', deselected_ticked_prefix=self._stat.colored('Green', ' ⬢ '), selected_unticked_prefix=self._stat.colored('Yellow', ' ⬡ '), selected_ticked_prefix=self._stat.colored('Yellow', ' ⬢ '), hide_confirm=True) chosen = [] for i in selection: chosen.append(package_names[i]) self._select(chosen)
def set_format(): format_opts = {"C++": "cpp", "Python": "py", "C#": "cs", "Java": "java"} print(colored('Choose filetype (use up/down keys):', 'yellow')) format_keys = list(format_opts.keys()) answers = cutie.select_multiple(format_keys) ## Store the config file config = configparser.ConfigParser() home = os.path.expanduser("~") config_file = os.path.join(home, "codecomb_config.ini") config.read(config_file) config['FORMAT'] = dict((format_keys[ans], format_opts[format_keys[ans]]) \ for ans in answers) with open(config_file, "w") as fmtFile: config.write(fmtFile)
def delete(self): choiceList = [] idPathList = [] for item in self.items: choiceList.append(item.name) idPathList.append(item.idPath) selected = cutie.select_multiple( choiceList, deselected_unticked_prefix="[ ] ", selected_unticked_prefix='[\033[32;1m‣\033[0m] ', selected_ticked_prefix='\033[32;1m[‣]\033[0m ', deselected_ticked_prefix='\033[32;1m[\033[0m‣\033[32;1m]\033[0m ') for i in range(len(selected)): print("removed : ", choiceList[selected[i]]) os.remove( os.path.join(os.path.abspath('./fichiers'), idPathList[selected[i]])) pass
def _select_courses_to_download(self, courses: [Course]): """ Asks the userer for the courses that should be downloaded. @param courses: All availible courses """ download_course_ids = self.get_download_course_ids() dont_download_course_ids = self.get_dont_download_course_ids() print('') print('To avoid downloading all the Moodle courses you are' + ' enrolled in, you can select which ones you want' + ' to download here. ') print('') choices = [] defaults = [] for i, course in enumerate(courses): choices.append(('%5i\t%s' % (course.id, course.fullname))) if (ResultsHandler._should_download_course( course.id, download_course_ids, dont_download_course_ids)): defaults.append(i) print('Which of the courses should be downloaded?') print('[You can select with space bar or enter key.' + ' All other keys confirm the selection.]') print('') selected_courses = cutie.select_multiple( options=choices, ticked_indices=defaults) download_course_ids = [] for i, course in enumerate(courses): if i in selected_courses: download_course_ids.append(course.id) self.config_helper.set_property('download_course_ids', download_course_ids) self.config_helper.remove_property('dont_download_course_ids')
import cutie import pprint if cutie.prompt_yes_or_no('Are you brave enough to continue?'): # List of names to select from, including some captions names = [ 'Kings:', 'Arthur, King of the Britons', 'Knights of the Round Table:', 'Sir Lancelot the Brave', 'Sir Robin the Not-Quite-So-Brave-as-Sir-Lancelot', 'Sir Bedevere the Wise', 'Sir Galahad the Pure', 'Swedish captions:', 'Møøse' ] # Names which are captions and thus not selectable captions = [0, 2, 7] # Get the name # name = names[cutie.select(names, caption_indices=captions, selected_index=8)] # print(f'Welcome, {name}') # get multiple selected = cutie.select_multiple(names, caption_indices=captions) pprint.pprint(selected) # Get an integer greater or equal to 0 age = cutie.get_number('What is your age?', min_value=0, allow_float=False) # Get input without showing it being typed quest = cutie.secure_input('What is your quest?') print(f'{name}\'s quest (who is {age}) is {quest}.')