Ejemplo n.º 1
0
    def show_words(self):
        # load words from database
        words = Word.retrieve_all()

        # fill list model with words from database
        store = Gtk.ListStore(int, str, str, str)
        for word in words:
            store.append([
                word.id, word.word, word.translation,
                word.date.strftime("%Y-%m-%d %H:%M:%S")
            ])

        # editable cells for each column
        cell = Gtk.CellRendererText(editable=False)
        cell_word = Gtk.CellRendererText(editable=True)
        cell_translation = Gtk.CellRendererText(editable=True)

        # add list view to window
        self.list = Gtk.TreeView(store)
        column_id = Gtk.TreeViewColumn('Id', cell, text=0)
        column_word = Gtk.TreeViewColumn('Word', cell_word, text=1)
        column_translation = Gtk.TreeViewColumn('Translation',
                                                cell_translation,
                                                text=2)
        column_date = Gtk.TreeViewColumn('Date', cell, text=3)
        self.list.append_column(column_id)
        self.list.append_column(column_word)
        self.list.append_column(column_translation)
        self.list.append_column(column_date)
        self.add(self.list)

        # connect text cell edited signals
        cell_word.connect('edited', self.edit_field, 1)
        cell_translation.connect('edited', self.edit_field, 2)