Как заставить GtkListStore хранить атрибут объекта в строке?

Я пытаюсь сохранить в ListStore нетекстовые объекты, используя найденный фрагмент. Это объекты:

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

И теперь я пытаюсь заставить 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)
    ...

Но вылетает с ошибками:

GtkWarning: gtk_tree_view_column_cell_layout_set_cell_data_func: утверждение info != NULL' failed
col.set_cell_data_func(cell, get_series_title) Warning: unable to set property
text' типа gchararray' from value of typedata+TrayIcon+Series'
window.show_all() Предупреждение: невозможно установить свойство text' of typegchararray из значения типа `data+TrayIcon+Series'
gtk.main() gtk.main()

Что я должен сделать, чтобы заставить его работать?


person Enchantner    schedule 15.08.2010    source источник


Ответы (1)


Две ошибки в предпоследнем блоке.

  1. GtkWarning: gtk_tree_view_column_cell_layout_set_cell_data_func: утверждение `info != NULL'
    #P2#
  2. Предупреждение: невозможно установить свойство text типа gchararray из значения typedata+TrayIcon+Series
    #P3#

В коде:

col = gtk.TreeViewColumn(_("Series title"))
cell = gtk.CellRendererText()
col.pack_start(cell)
col.set_cell_data_func(cell, get_series_title)
person Johannes Sasongko    schedule 16.08.2010