How to make an attribute of a GtkListStore storage object in a string?

I am trying to save non-text objects in ListStore objects using a found fragment. These are the objects:

class Series(gobject.GObject, object): def __init__(self, title): super(Series, self).__init__() self.title = title gobject.type_register(Series) class SeriesListStore(gtk.ListStore): def __init__(self): super(SeriesListStore, self).__init__(Series) self._col_types = [Series] def get_n_columns(self): return len(self._col_types) def get_column_type(self, index): return self._col_types[index] def get_value(self, iter, column): obj = gtk.ListStore.get_value(self, iter, 0) return obj 

And now I'm trying to show a TreeView:

  ... liststore = SeriesListStore() liststore.clear() for title in full_conf['featuring']: series = Series(title) liststore.append([series]) def get_series_title(column, cell, model, iter): cell.set_property('text', liststore.get_value(iter, column).title) return selected = builder.get_object("trvMain") selected.set_model(liststore) col = gtk.TreeViewColumn(_("Series title")) cell = gtk.CellRendererText() col.set_cell_data_func(cell, get_series_title) col.pack_start(cell) col.add_attribute(cell, "text", 0) selected.append_column(col) ... 

But he is not mistaken:

GtkWarning: gtk_tree_view_column_cell_layout_set_cell_data_func: statement info != NULL' failed
col.set_cell_data_func(cell, get_series_title) Warning: unable to set property
info != NULL' failed
col.set_cell_data_func(cell, get_series_title) Warning: unable to set property
info != NULL' failed
col.set_cell_data_func(cell, get_series_title) Warning: unable to set property
text 'type gchararray' from value of type data + TrayIcon + Series'
window.show_all () Warning: cannot set the text' of type gchararray' property from the value of type `data + TrayIcon + Series'
gtk.main () gtk.main ()

What to do to make it work?

+2
source share
1 answer

Two errors in the second-last block.

  • GtkWarning: gtk_tree_view_column_cell_layout_set_cell_data_func: statement `info! = NULL '

    In English, this means that the cell renderer is not on the list of cell rendering columns. Before calling set_cell_data_func you need to add a cell handler to the column.

  • Warning: it is not possible to set the `text 'property of type` gchararray' from the value of `typedata + TrayIcon + Series'

    This is due to the fact that the add_attribute line causes GTK + to try to set the text of the cell to the series object, which, of course, does not work. Just delete this line; the cell data function is already adjusting the cell text.

In code:

 col = gtk.TreeViewColumn(_("Series title")) cell = gtk.CellRendererText() col.pack_start(cell) col.set_cell_data_func(cell, get_series_title) 
+1
source

Source: https://habr.com/ru/post/918880/


All Articles