コード例 #1
0
ファイル: Interface.py プロジェクト: kdelwat/Lexeme
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
コード例 #2
0
ファイル: Interface.py プロジェクト: kdelwat/Lexeme
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
コード例 #3
0
ファイル: Interface.py プロジェクト: kdelwat/Lexeme
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")
コード例 #4
0
ファイル: Interface.py プロジェクト: kdelwat/Lexeme
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!")
コード例 #5
0
ファイル: Interface.py プロジェクト: kdelwat/Lexeme
def decline():
    ''' Allows user to select word to decline and declension, then outputs the
    declined word.
    '''
    word = input("Enter word (in conlang) to decline: ")

    try:
        result = Library.findConWord(word)
    except LookupError:
        print("Word not found in database")
        return 1

    prompt = "Select declension"
    dec = IOHelper.createMenu(prompt, Library.getAvailableDeclensions())

    output = Library.declineWord(result, dec)

    outputWord(output, "conlang")
コード例 #6
0
ファイル: Interface.py プロジェクト: kdelwat/Lexeme
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!")
コード例 #7
0
ファイル: Interface.py プロジェクト: kdelwat/Lexeme
def loadData(filename=None):
    '''Loads data from config file and passes it to Library.'''
    try:
        result = IOHelper.parseConfig(filename)
    except KeyError:
        print("Config file is malformed or does not exist")
        quit()

    phonemes = result[0]
    allophones = result[1]
    declensions = result[2]
    exportformat = result[4]

    global wordgensettings
    wordgensettings = result[3]

    global formatString
    formatString = exportformat

    Library.setPhonemes(phonemes)
    Library.setAllophones(allophones)
    Library.setDeclensions(declensions)

    return 0