def prepare_questions(self): self.questions_menu = [{ 'type': 'rawlist', 'name': 'user_options', 'message': '***Session Manager***:', 'choices': [ Separator(), self.user_options['restore'], self.user_options['save'], self.user_options['continue'], Separator(), self.user_options['delete'], self.user_options['exit'], Separator() ] }, { 'type': 'rawlist', 'name': 'restore', 'message': 'Select a session to try to restore:', 'choices': [*[session for session in self.data_filenames], '<---Go-back---'], 'when': lambda answers: answers['user_options'] == self.user_options[ 'restore'] }, { 'type': 'input', 'name': 'save', 'message': 'Write your first name or username to save:', 'when': lambda answers: answers['user_options'] == self.user_options['save' ] }, { 'type': 'checkbox', 'name': 'delete', 'message': 'Mark the sessions you want to delete:', 'choices': list(map(lambda e: {'name': e}, self.data_filenames)), 'when': lambda answers: answers['user_options'] == self.user_options[ 'delete'] }] self.question_overwrite = [{ 'type': 'confirm', 'name': 'overwrite_data', 'message': 'There is already a session with that name, overwrite it?', 'default': True }]
def __init__(self, updates: dict): self.updates = updates self.informative = { f'{key.title} ({len(self.updates[key])})': self.updates[key] for key in self.updates.keys() } mangas = list(self.informative.keys()) manga_prompt_list = alphabetic_prompt_list([manga for manga in mangas]) # exit options manga_prompt_list.extend([Separator(' '), 'Exit']) self._menu = Menu("Updates", manga_prompt_list)
Token.Selected: '#5F819D', Token.Pointer: '#FF9D00 bold', Token.Instruction: '', # default Token.Answer: '#5F819D bold', Token.Question: '', }) questions = [ { 'type': 'list', 'name': 'theme', 'message': 'What do you want to do?', 'choices': [ 'Order a pizza', 'Make a reservation', Separator(), 'Ask for opening hours', { 'name': 'Contact support', 'disabled': 'Unavailable at this time' }, 'Talk to the receptionist' ] }, { 'type': 'list', 'name': 'size', 'message': 'What size do you need?', 'choices': ['Jumbo', 'Large', 'Standard', 'Medium', 'Small', 'Micro'], 'filter': lambda val: val.lower() }
def seperator(s=''): return Separator(s)
def save_results(self): style = style_from_dict({ Token.Separator: '#6C6C6C', Token.QuestionMark: '#FF9D00 bold', #Token.Selected: '', # default Token.Selected: '#5F819D', Token.Pointer: '#FF9D00 bold', Token.Instruction: '', # default Token.Answer: '#5F819D bold', Token.Question: '', }) if self.out_filename != None: questions = [{ 'type': 'confirm', 'message': f"Save results to: {self.out_filename}: ", 'name': 'save', 'default': 'True' }] else: # NOT DONE questions = [{ 'type': 'expand', 'message': 'Save file on `file.js`: ', 'name': 'overwrite', 'default': 'a', 'choices': [{ 'key': 'y', 'name': 'Overwrite', 'value': 'overwrite' }, { 'key': 'a', 'name': 'Overwrite this one and all next', 'value': 'overwrite_all' }, { 'key': 'd', 'name': 'Show diff', 'value': 'diff' }, Separator(), { 'key': 'x', 'name': 'Abort', 'value': 'abort' }] }] answer = prompt(questions, style=style) if answer['save']: self.save_json()
Token.Pointer: '#FF9D00 bold', Token.Instruction: '', # default Token.Answer: '#5F819D bold', Token.Question: '', }) questions = [{ 'type': 'rawlist', 'name': 'theme', 'message': 'What do you want to do?', 'choices': [ 'Order a pizza', 'Make a reservation', Separator(), 'Ask opening hours', 'Talk to the receptionist' ] }, { 'type': 'rawlist', 'name': 'size', 'message': 'What size do you need', 'choices': ['Jumbo', 'Large', 'Standard', 'Medium', 'Small', 'Micro'], 'filter': lambda val: val.lower() }] answers = prompt(questions, style=style) print_json(answers)
def settings_configure(): def print_value(value): if value is False: return "False" elif value is True: return "True" elif value is None: return "None" else: return str(value) def int_input(current): question = [{ 'type': 'input', 'name': 'value_list', 'message': "Current value is " + print_value(current) + ".\nEnter new integer value, enter -1 for inf" }] answer = int(prompt(question)["value_list"]) if answer == -1: answer = float("inf") return answer def bool_input(current): answer = confirm("Current value is " + print_value(current) + ". Enter new boolean value") return answer with open(settings_path) as file: settings = load(file) question = [{ 'type': 'checkbox', 'message': 'Select options', 'name': 'key_list', 'choices': [ Separator('= Verbosity ='), { 'name': 'Word verbosity' }, { 'name': 'Dictionary verbosity' }, { 'name': 'Word scraping verbosity' }, Separator('= Other ='), { 'name': 'Default dictionary: ' + print_value(settings["default_dictionary"]) }, { 'name': 'History capacity: ' + print_value(settings["history_capacity"]) } ], }] verbosity_translator = { "Short definition": ("short", "bool"), "Long definition": ("long", "bool"), "Play audio": ("audio", "bool"), "Part of speech": ("title", "bool"), "Definition": ("definition", "bool"), "Example sentence": ("example", "bool"), "Antonym": ("antonyms", "int"), "Synonym": ("synonyms", "int"), "Type of": ("type of", "int"), "Type": ("types", "int"), "Example": ("examples", "int"), "Word family length": ("family", "int"), "Word frequency": ("freq", "bool"), "Usage length": ("usage", "int") } translator = { "Word scraping verbosity": 0, "Word verbosity": 1, "Dictionary verbosity": 2 } key_list = prompt(question)["key_list"] for key in key_list: key = key.split(":")[0] if key == "Default dictionary": choices = [{ "name": str(path), "disabled": "search history" if path.name == "History.json" else "" } for path in (Path("Vocabot") / "dictionaries").rglob("*.json")] question = [{ "type": "checkbox", "message": "Select default dictionary", "name": "default_dictionary", "choices": choices, "validate": lambda ans: True if len(ans) == 1 else False }] settings["default_dictionary"] = str( Path(prompt(question)["default_dictionary"][0]).relative_to( Path("Vocabot") / "dictionaries")) with open(settings_path, "w") as file: dump(settings, file, indent=4, ensure_ascii=False) elif key == "History capacity": print("Change history capacity") new_value = int_input(settings["history_capacity"]) settings["history_capacity"] = new_value with open(settings_path, "w") as file: dump(settings, file, indent=4, ensure_ascii=False) else: print(key + ":") subkey = translator[key] verbosity_settings = settings_check(subkey) question = [{ 'type': 'checkbox', 'message': 'Select options', 'name': 'key_list', "choices": [{ "name": verbosity_key + ": " + print_value(verbosity_settings[ verbosity_translator[verbosity_key][0]]) } for verbosity_key in verbosity_translator] }] verbosity_key_list = prompt(question)["key_list"] for verbosity_key in verbosity_key_list: verbosity_key = verbosity_key[:verbosity_key.find(":")] key_name, key_type = verbosity_translator[verbosity_key] print(verbosity_key + ":") key_value = print_value( verbosity_settings[verbosity_translator[verbosity_key][0]]) if key_type == "int": new_value = int_input(key_value) elif key_type == "bool": new_value = bool_input(key_value) settings["verbosity"][key_name][subkey] = new_value with open(settings_path, "w") as file: dump(settings, file, indent=4, ensure_ascii=False) print("Saved.")
skip_menu, args = parse() while True: menuoption = {} if not skip_menu: mainmenu = { 'type': 'list', 'name': 'dialog', 'message': 'what do you wanna do?', 'choices': [ 'Search for manga', 'Open manga using direct url', 'View the manga', Separator('-'), 'Compose', 'Database', 'Settings', 'Exit' ], 'filter': lambda val: mainmenu['choices'].index(val) } menuoption = prompt(mainmenu) else: if args.view: menuoption['dialog'] = 2 if menuoption['dialog'] == 0: try: dialog = MangaDialog(search()) dialog.prompt() except Exception:
Token.QuestionMark: '#FF9D00 bold', Token.Selected: '', # default Token.Pointer: '#FF9D00 bold', Token.Instruction: '', # default Token.Answer: '#5F819D bold', Token.Question: '', }) questions = [ { 'type': 'checkbox', 'message': 'Select toppings', 'name': 'toppings', 'choices': [ Separator(' = The Meats ='), { 'name': 'Ham' }, { 'name': 'Ground Meat' }, { 'name': 'Bacon' }, Separator(' = The Cheeses ='), { 'name': 'Mozzarella', 'checked': True }, {