Beispiel #1
0
    def on_import_button(self):
        """ Method called when the import button in the toolbar is pressed. """
        filenames = tkFileDialog.askopenfilenames(filetypes=[("Word List", ".tldr")])

        for filename in filenames:
            try:
                with open(filename, "r") as f:
                    list_Id = database.add_list(filename)
                    data = list(parse_tldr(f))  
                    for word in data:
                        try:
                            word_Id = database.add_word(word.word,
                                                        word.definition,
                                                        word.example,
                                                        word.difficulty)
                        except Exception:
                            pass
                        else:
                            database.add_wordlist_mappings(list_Id, word_Id)
            except IOError as e:
                tkMessageBox.showwarning(
                    "Import Error",
                    "Could not open {0}".format(filename)
                )
                logging.warn(e)  
            else:
                self.view.left_list.model[os.path.relpath(filename)] = data
        self.populate()
Beispiel #2
0
 def on_create_button(self):
     """ Method called when the create new word button in the toolbar is
     pressed. """
     word = new_word_prompt()
     if word is not None:
         try:
             word_Id = database.add_word(word.word,
                                         word.definition,
                                         word.example,
                                         word.difficulty)
         except Exception:
             pass
         else:
             database.add_wordlist_mappings(1, word_Id)
     self.populate()
     self.on_left_list_select()
Beispiel #3
0
def add_word():
    db.add_word(f.request.get_json()["word"])
    return ""