def addCustomFields(word, prompt=True): '''Take word and allow user to set custom fields. Return completed word. ''' if prompt: another = IOHelper.yesNo("Add custom field") else: another = True while another: options = Library.getFields() options.append("other") field = IOHelper.chooseOption("Enter desired field to add", options) if field == "other": new = input("Enter new field: ") value = input("Enter word value: ") word[new] = value else: values = Library.getFieldOptions(field) values.append("other") v = IOHelper.chooseOption("Enter word value", values) if v == "other": v = input("Enter new word value: ") word[field] = v another = IOHelper.yesNo("Add custom field") return word
def modify(): '''Modify an existing word.''' try: conword = input("Enter word in conlang: ") if Library.wordExists(conlang=conword): word = Library.findConWord(conword, pop=False) outputWord(word) else: print("Word does not exist") return keys = list(word.keys()) keys.remove("id") keys.append("NEW") keys.append("DELETE") another = True while another: key = IOHelper.chooseOption("Enter field to modify", keys) if key == "NEW": word = addCustomFields(word, prompt=False) elif key == "DELETE": keys.remove("NEW") keys.remove("DELETE") keys.remove("english") keys.remove("word") key = IOHelper.chooseOption("Enter field to delete", keys) keys.remove(key) del word[key] keys.insert(0, "english") keys.insert(0, "word") keys.append("NEW") keys.append("DELETE") else: if key in ["word", "english"]: word[key] = input("Enter new value: ") else: values = Library.getFieldOptions(key) values.append("other") v = IOHelper.chooseOption("Enter word value", values) if v == "other": v = input("Enter new value: ") word[key] = v another = not IOHelper.yesNo("Finished modifying") # Delete word if finished modifying and add new word Library.findConWord(conword, pop=True) Library.addWord(word) except KeyboardInterrupt: pass
def add(): '''Interface for addWord().''' word = {} word['english'] = input("Enter meaning in English: ") word['word'] = input("Enter word in conlang: ") forms = Library.getFieldOptions("form") forms.append("other") form = IOHelper.chooseOption("Enter word form", forms) if form == "other": form = input("Enter new word form: ") word['form'] = form word = addCustomFields(word) Library.addWord(word) print("Word saved in database!")
def listwords(): '''Interface for listWords().''' t = IOHelper.chooseOption("Enter list type", ["all", "field"]) if t == "field": fields = Library.getFields() f = IOHelper.chooseOption("Enter desired field", fields) options = Library.getFieldOptions(f) o = IOHelper.chooseOption("Enter option to list", options) l = Library.listWords(t, f, o) else: l = Library.listWords(t) if len(l) > 0: outputWordList(l) else: print("No words to display")
def generate(english=None): '''Interface to generateWord().''' if english is None: english = input("Enter word in English: ") if Library.wordExists(english=english): print("Word already exists!") w = Library.findEnglishWord(english) outputWord(w) return 1 forms = Library.getFieldOptions("form") forms.append("other") form = IOHelper.chooseOption("Enter word form", forms) if form == "other": form = input("Enter new word form: ") finalised = False while finalised is not True: word = Library.generateWord(english, form, wordgensettings) while Library.wordExists(conlang=word['word']): word = Library.generateWord(english, form, wordgensettings) #clearScreen() outputWord(word, "conlang") accepted = IOHelper.chooseOption("Accept word", ["y", "n", "e"]) if accepted == "y": finalised = True elif accepted == "e": word['word'] = input("Enter modified word: ") finalised = True word = addCustomFields(word) Library.addWord(word) print("Word saved in database!")