2010-08-15 2 views
2

내가 발견 한 스 니펫을 사용하여 ListStore 비 텍스트 개체를 유지하려고했습니다. 트 리뷰가 표시행에 GtkListStore 객체 속성을 저장하는 방법은 무엇입니까?

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 

그리고 지금 내가 만들려고 노력 해요 : : 다음은 객체

... 
    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
텍스트 'gchararray' from value of type 데이터의 + TrayIcon + Series',210 window.show_all() 경고 : 재산 text' of type gchararray 설정할 수 없습니다 ' 유형의 값에서을'데이터 + TrayIcon에 + 시리즈 '
gtk.main() gtk.main()

내가해야 작동하게 만드시겠습니까?

답변

1

두 번째 - 마지막 블록에서 두 번의 실수.

  1. GtkWarning : gtk_tree_view_column_cell_layout_set_cell_data_func! 주장`정보 = NULL '은 영어

    ,이 셀 렌더러는 셀 렌더링의 열의 목록에없는 것을 의미한다. set_cell_data_func을 호출하기 전에 먼저 셀 렌더러를 열에 추가해야합니다.

  2. 경고 :`의 값에서 '유형'gchararray의 '속성'텍스트를 설정할 수 없습니다 typedata + TrayIcon에 + 시리즈 '

    add_attribute 라인이 시리즈에 셀 텍스트를 설정하려고 GTK +가 발생하기 때문이다 개체, 물론 실패합니다. 그냥 그 줄을 제거하십시오. 셀 데이터 func는 이미 셀 텍스트 설정을 담당합니다. 코드에서

:

col = gtk.TreeViewColumn(_("Series title")) 
cell = gtk.CellRendererText() 
col.pack_start(cell) 
col.set_cell_data_func(cell, get_series_title) 
관련 문제