def edit_word(self, widget): # get selected row store, iter_list = self.list.get_selection().get_selected() pk = store[iter_list][0] record = Word.retrieve_by_id(pk) # show dialog and get button clicked code dialog = Dialog(self, record.word, record.translation) response = dialog.run() dialog.destroy() if response != Gtk.ResponseType.OK: return # get entered word & translation word = dialog.word.strip() translation = dialog.translation.strip() if word == '' or translation == '': return # update database field according to given column Word.update_by_id(pk, word, translation) # update edited list row store[iter_list][1] = word store[iter_list][2] = translation
def add_word(self, widget): # show dialog and get button clicked code dialog = Dialog(self) response = dialog.run() dialog.destroy() if response != Gtk.ResponseType.OK: return # get entered word & translation word = dialog.word.strip() translation = dialog.translation.strip() if word == '' or translation == '': return # insert new word entered in database record = Word(word=word, translation=translation, date=datetime.now()) pk = Word.insert(record) record = Word.retrieve_by_id(pk) # add inserted word to list view store = self.list.get_model() store.append([ record.id, record.word, record.translation, record.date.strftime("%Y-%m-%d %H:%M:%S") ])