Hi, I need to dynamically modify TreeViews, e.g. to determine which attributes are set in the GtkBuilder-file, and to show a different model-column in a view-column. But I don't know how:
When I create GtkTreeViewColumns and GtkCellRenderers, I can set "attributes", to tell the renderer which data to display, e.g. (in Python, see end-of-mail for complete example): store = Gtk.ListStore(str, str, int) tree = Gtk.Treeview(store) renderer = Gtk.CellRendererText() column = Gtk.TreeViewColumn("Test", renderer, text=0, weight=2) tree.append_column(column) The attributes here are "text=0" and "weight=2" Now: - How can I determine which attributes are set? I would like something like: >>> attrs = column.get_attributes(renderer) >>> print(attrs) {"text": 0, "weight": 2} - How can I retrieve the attributes back from the tree/column/renderer? I would like something like: >>> textattr = column.get_attribute(renderer, "text") >>> print(textattr) 0 - How can I modify a single attribute without clearing the others? I would like something like: >>> column.add_attribute(renderer, "text", 1) But this fails since the "text"-attribute is already set. thanks, Roland PS: Complete example: #!/usr/bin/python from gi.repository import Gtk # create window win = Gtk.Window() win.connect("delete-event", Gtk.main_quit) # create treestore store = Gtk.ListStore(str, str, int, int) store.append(["Text", "Other text", 400, 1000]) store.append(["Text2", "Other text2", 1000, 400]) # create treeview tree = Gtk.TreeView(store) renderer = Gtk.CellRendererText() column = Gtk.TreeViewColumn("Test", renderer, text=0, weight=2) tree.append_column(column) # TODO: get attribute-list #attrs = column.get_attributes() #print(attrs) # -> {"text": 0, "weight": 2} # TODO: get attribute #textattr = column.get_attributes("text") #print(textattr) # -> 0 # TODO: modify attributes column.add_attribute(renderer, "text", 1) # fails with "...Cannot connect attribute `text' for cell renderer class `GtkCellRendererText' since `text' is already attributed to column 0" # run win.add(tree) win.show_all() Gtk.main() _______________________________________________ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list