python-gtk cellrenderer combobox for each row

853 views Asked by At

I have a row like that -> [name],[mp3names],[suggested_names] suggested_names is a list for combobox and each row has different suggested names. So I need a combobox for them. but I dont know how to do.

edit: I read my csv file at first, then I add all them in a list, then I handle all columns. I have name suggestions for every row, but i don't know how to add this suggestions. Now I can only once define the suggestions and use for all rows, but it is not correct, I need different suggestions for every row. enter image description here

            for i in range(self.row_len):
                outliers_list.append([str(self.columns[1][i])]+[str(self.columns[self.col_count-2][i])]+[str(self.columns[self.col_count-1][i])]+[corrected]+[audio_name])

            self.col_len = len(outliers_list[0]);

    #dynamically liststore column adding
            self.liststore = Gtk.ListStore(*([str] * 5))
    # You need to use self.fillStore() instead.
            for item in outliers_list:
                self.liststore.append(item)
            liststore_suggestions = Gtk.ListStore(str)
            suggestions = correct("axse") 
            for item in suggestions:
                liststore_suggestions.append([item])


            renderer_text = Gtk.CellRendererText()
            column = Gtk.TreeViewColumn("Name", renderer_text, text=0)
            treeview.append_column(column)

            renderer_text = Gtk.CellRendererText()
            column = Gtk.TreeViewColumn("mp3Names", renderer_text, text=1)
            treeview.append_column(column)
            renderer_combo = Gtk.CellRendererCombo()
            renderer_combo.set_property("editable", True)
            renderer_combo.set_property("model",liststore_suggestions)
            renderer_combo.set_property("text-column", 0)
            renderer_combo.set_property("has-entry", True)
            renderer_combo.connect("edited", self.on_combo_changed)

            column_combo = Gtk.TreeViewColumn("Suggest", renderer_combo, text=2)
            treeview.append_column(column_combo)

here suggestions = correct("axse") would change for every row, I only defined it for showing you, the correct one ise :

suggestions = correct(str(self.columns[1][i]))

At last, what I want is changing this code, because it stores only one list and use it for every row.

renderer_combo.set_property("model",liststore_suggestions)

But what I want is something like that. Loading dynamically combobox liststores for every row.

renderer_combo.set_property("model",liststore_suggestions[i])
1

There are 1 answers

0
earlymorningtea On BEST ANSWER

Finally I found my way. So at first I added

 select = self.treeview.get_selection()
 select.connect("changed", self.on_tree_selection_changed)

Then I added the new function. It gets the first column value of row and do correction, suggests names and update combobox.

def on_tree_selection_changed(self, selection):
    model, treeiter = selection.get_selected()

    name = str(model[treeiter][0])
    liststore_suggestions = Gtk.ListStore(str)
    suggestions = correct(name)
    for item in suggestions:
        liststore_suggestions.append([item])
    self.renderer_combo.set_property("model",liststore_suggestions)