Пример #1
0
    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
Пример #2
0
    def edit_field(self, widget, path, text, column):
        # get edited row & its old values
        store = self.list.get_model()
        row = store[path]
        pk, word, translation = row[0], row[1], row[2]

        # update database field according to given column
        word = text if column == 1 else word
        translation = text if column == 2 else translation
        Word.update_by_id(pk, word, translation)

        # update model with edited text
        row[column] = text