edit and use treeview cell
Friends, I am writing a gtk3(in C) code, that uses treeview. store = gtk_list_store_new (NUM_COLS, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); tree = gtk_tree_view_new_with_model (GTK_TREE_MODEL (store)); cell = gtk_cell_renderer_text_new (); col_pub=gtk_tree_view_column_new_with_attributes ( Title, cell, text, COL_BIB_PUB, NULL); gtk_tree_view_column_set_sort_column_id( col_pub, ID_PUB); gtk_tree_view_append_column (GTK_TREE_VIEW (tree), col_pub); The problem is I want each cell of the treeview to be editable, so I need something like: g_object_set(cell, editable, TRUE, NULL); but I have no idea of how to connect the edited flag to file/buffer. It will be very helpful if someone kindly show the way...a very short example may be. Please help. ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: edit and use treeview cell
On Thu, Jan 24, 2013 at 09:41:20AM +, Rudra Banerjee wrote: g_object_set(cell, editable, TRUE, NULL); but I have no idea of how to connect the edited flag to file/buffer. It will be very helpful if someone kindly show the way...a very short example may be. Have you read the tutorial? http://scentric.net/tutorial/sec-editable-cells.html Yeti ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: edit and use treeview cell
On Thu, 2013-01-24 at 10:45 +0100, David Nečas wrote: Have you read the tutorial? http://scentric.net/tutorial/sec-editable-cells.html David, Thanks for your reply. Yes, I have read that tutorial. After reading that I have learned how to make the cell editable. But the problem still confuses me. And also, as I said, how to use this. That tut says I need a function cell_edited_callback to make the edit in file. But bit clueless about how to do that. ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: edit and use treeview cell
On Thursday 24 January 2013 11:02:37 Rudra Banerjee wrote: On Thu, 2013-01-24 at 10:45 +0100, David Nečas wrote: Have you read the tutorial? http://scentric.net/tutorial/sec-editable-cells.html David, Thanks for your reply. Yes, I have read that tutorial. After reading that I have learned how to make the cell editable. But the problem still confuses me. And also, as I said, how to use this. That tut says I need a function cell_edited_callback to make the edit in file. But bit clueless about how to do that. ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list Hi, i used something like that in gtk2 and it used to work, hope it helps and is understandable as my code is sometimes a little bit convoluted as I'm self-taught, Ciao, ZZ static void list_edited(GtkCellRendererText * cell, gchar * path_string, gchar * new_text, gpointer user_data) { GtkTreeView *treeview = (GtkTreeView *)user_data; GtkTreeModel *model; GtkTreeIter iter; guint column; /* Column number is passed as renderer object data */ gpointer columnptr = g_object_get_data(G_OBJECT(cell), column); column = GPOINTER_TO_UINT(columnptr); /* Get the iterator */ model = gtk_tree_view_get_model(treeview); gtk_tree_model_get_iter_from_string(model, iter, path_string); /* Update the model */ gtk_list_store_set(GTK_LIST_STORE(model), iter, column, new_text, -1); } static void text_editing_started (GtkCellRenderer ATTRIBUTE_UNUSED *cell, GtkCellEditable *editable, const gchar *path, GCallback data) { debug_err_msg(%s: started, __FUNCTION__); if (GTK_IS_ENTRY (editable)) { GtkEntry *entry = GTK_ENTRY (editable); GCallback cb_func = data; g_signal_connect(GTK_OBJECT(entry), activate, (GCallback)cb_func, (char *)xstrdup(path)); } } GtkWidget *string_list_create(int num, GCallback func, int show_hide, int editable,...) { GtkCellRenderer *renderer; GtkTreeViewColumn *column; GtkListStore *store; GtkWidget *tree; GtkTreeSelection *selection; GType *types; va_list titles; int i; char *tmp; char *label; double align; types = (GType *) malloc((num + 1) * sizeof(GType)); for (i = 0; i num; i++) { types[i] = G_TYPE_STRING; } store = gtk_list_store_newv(num, types); xfree(types); tree = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(tree), TRUE); /* Setup the selection handler */ selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree)); gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE); if (func) { g_signal_connect(selection, changed, G_CALLBACK(func), NULL); } /* The view now holds a reference. We can get rid of our own reference */ g_object_unref(G_OBJECT(store)); va_start(titles, editable); for (i = 0; i num; i++) { /* Create a cell renderer */ renderer = gtk_cell_renderer_text_new(); tmp = va_arg(titles, char *); align = va_arg(titles, double); if (editable == EDITABLE || (editable == CUSTOM va_arg(titles, int) == EDITABLE)) { g_object_set(renderer,editable, TRUE, NULL); g_object_set_data(G_OBJECT(renderer), column, GUINT_TO_POINTER(i)); g_signal_connect(GTK_OBJECT(renderer), edited, G_CALLBACK(list_edited), tree); if (editable == CUSTOM) { g_signal_connect(GTK_OBJECT(renderer), editing-started, G_CALLBACK(text_editing_started), (gpointer) va_arg(titles, void*)); } } if (!tmp || show_hide == HIDE ) tmp = ; if (g_utf8_validate(tmp, -1, NULL) != TRUE) { label = g_locale_to_utf8(tmp , -1, NULL, NULL, NULL); /* Create a column, associating the text attribute of the cell_renderer to the column of the model */ column = gtk_tree_view_column_new_with_attributes(label, renderer, text, i, NULL); xfree(label); } else { column = gtk_tree_view_column_new_with_attributes(tmp, renderer, text, i, NULL); } g_object_set (renderer,xalign, align, NULL); /* Add the column to the view. */ gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column); } va_end(titles);
Re: edit and use treeview cell
Thanks ZZ, your code helped me making my code more general. Thanks a lot. Now I can edit the cells well. But my final goal is to write them in a file. I will check a bit and come back if I need further help. On Thu, 2013-01-24 at 15:18 +0100, z...@excite.it wrote: On Thursday 24 January 2013 11:02:37 Rudra Banerjee wrote: On Thu, 2013-01-24 at 10:45 +0100, David Nečas wrote: Have you read the tutorial? http://scentric.net/tutorial/sec-editable-cells.html David, Thanks for your reply. Yes, I have read that tutorial. After reading that I have learned how to make the cell editable. But the problem still confuses me. And also, as I said, how to use this. That tut says I need a function cell_edited_callback to make the edit in file. But bit clueless about how to do that. ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list Hi, i used something like that in gtk2 and it used to work, hope it helps and is understandable as my code is sometimes a little bit convoluted as I'm self-taught, Ciao, ZZ static void list_edited(GtkCellRendererText * cell, gchar * path_string, gchar * new_text, gpointer user_data) { GtkTreeView *treeview = (GtkTreeView *)user_data; GtkTreeModel *model; GtkTreeIter iter; guint column; /* Column number is passed as renderer object data */ gpointer columnptr = g_object_get_data(G_OBJECT(cell), column); column = GPOINTER_TO_UINT(columnptr); /* Get the iterator */ model = gtk_tree_view_get_model(treeview); gtk_tree_model_get_iter_from_string(model, iter, path_string); /* Update the model */ gtk_list_store_set(GTK_LIST_STORE(model), iter, column, new_text, -1); } static void text_editing_started (GtkCellRenderer ATTRIBUTE_UNUSED *cell, GtkCellEditable *editable, const gchar *path, GCallback data) { debug_err_msg(%s: started, __FUNCTION__); if (GTK_IS_ENTRY (editable)) { GtkEntry *entry = GTK_ENTRY (editable); GCallback cb_func = data; g_signal_connect(GTK_OBJECT(entry), activate, (GCallback)cb_func, (char *)xstrdup(path)); } } GtkWidget *string_list_create(int num, GCallback func, int show_hide, int editable,...) { GtkCellRenderer *renderer; GtkTreeViewColumn *column; GtkListStore *store; GtkWidget *tree; GtkTreeSelection *selection; GType *types; va_list titles; int i; char *tmp; char *label; double align; types = (GType *) malloc((num + 1) * sizeof(GType)); for (i = 0; i num; i++) { types[i] = G_TYPE_STRING; } store = gtk_list_store_newv(num, types); xfree(types); tree = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(tree), TRUE); /* Setup the selection handler */ selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree)); gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE); if (func) { g_signal_connect(selection, changed, G_CALLBACK(func), NULL); } /* The view now holds a reference. We can get rid of our own reference */ g_object_unref(G_OBJECT(store)); va_start(titles, editable); for (i = 0; i num; i++) { /* Create a cell renderer */ renderer = gtk_cell_renderer_text_new(); tmp = va_arg(titles, char *); align = va_arg(titles, double); if (editable == EDITABLE || (editable == CUSTOM va_arg(titles, int) == EDITABLE)) { g_object_set(renderer,editable, TRUE, NULL); g_object_set_data(G_OBJECT(renderer), column, GUINT_TO_POINTER(i)); g_signal_connect(GTK_OBJECT(renderer), edited, G_CALLBACK(list_edited), tree); if (editable == CUSTOM) { g_signal_connect(GTK_OBJECT(renderer), editing-started, G_CALLBACK(text_editing_started), (gpointer) va_arg(titles, void*)); } } if (!tmp || show_hide == HIDE ) tmp = ; if (g_utf8_validate(tmp, -1, NULL) != TRUE) { label = g_locale_to_utf8(tmp , -1, NULL, NULL, NULL); /* Create a column, associating the text attribute of the cell_renderer to the column of the model */ column = gtk_tree_view_column_new_with_attributes(label, renderer, text, i, NULL); xfree(label); } else { column = gtk_tree_view_column_new_with_attributes(tmp, renderer, text, i,
change treeview's cell height
Dear friends, How can I change cell (and hence row) height of a given row? In my treeview, I have cells of fixed width, and I want texts longer than that should be wrapped with height increased. Any solution anyone? ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: change treeview's cell height
On Thu, Jan 24, 2013 at 1:53 PM, Rudra Banerjee rudra.baner...@aol.co.ukwrote: In my treeview, I have cells of fixed width, and I want texts longer than that should be wrapped with height increased. Get a pointer to the GtkCellRendererText for the column in question; depending on how you construct your TreeView there are different methods. When you have that you can experiment with changing different properties, such as wrap-mode and wrap-width. See http://developer.gnome.org/gtk3/stable/GtkCellRendererText.html ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: change treeview's cell height
Andrew, If I am not demanding to much, will you mind to have a look at the treeview defination that I posted? the problem is in treeview as written, store = gtk_list_store_new (NUM_COLS, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); tree = gtk_tree_view_new_with_model (GTK_TREE_MODEL (store)); gtk_tree_view_set_rules_hint (GTK_TREE_VIEW(tree), TRUE); the rules_hint are not working, i.e. I am not getteing alternative color for each row. On Thu, 2013-01-24 at 23:47 +, Rudra Banerjee wrote: Thanks a lot! worked great! On Thu, 2013-01-24 at 15:42 -0800, Andrew Potter wrote: On Thu, Jan 24, 2013 at 3:33 PM, Rudra Banerjee rudra.baner...@aol.co.ukwrote: cell = gtk_cell_renderer_text_new (); col_auth=gtk_tree_view_column_new_with_attributes ( Author, cell, text, COL_BIB_NAME, NULL); gtk_tree_view_column_set_sort_column_id( col_auth, ID_NAME); gtk_tree_view_append_column (GTK_TREE_VIEW (tree), col_auth); gtk_tree_view_column_set_max_width (col_auth,350); I googled the wrap_mode, but I haven't have any example. Please give me a short example(even one liner) try: g_object_set(G_OBJECT(cell), wrap-mode, PANGO_WRAP_WORD, wrap-width, 10, NULL); If the cell has more than 10 characters, it might wrap. Good luck! ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: change treeview's cell height
On Thu, Jan 24, 2013 at 4:00 PM, Rudra Banerjee rudra.baner...@aol.co.ukwrote: gtk_tree_view_set_rules_hint (GTK_TREE_VIEW(tree), TRUE); the rules_hint are not working, i.e. I am not getteing alternative color for each row. I'm not an expert, but it probably means your default theme does not pay attention to that hint. This could be harder to diagnose since every Gtk3 release has had an evolved theme, and your distro may be changing it as well. What I would do is learn how to use the GtkCssProvider and make the rows the color you want. http://developer.gnome.org/gtk3/stable/GtkCssProvider.html Someone more knowledgeable than I might speak up though. ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: change treeview's cell height
Ok, no problem. Thanks for your time though. On Thu, 2013-01-24 at 16:21 -0800, Andrew Potter wrote: On Thu, Jan 24, 2013 at 4:00 PM, Rudra Banerjee rudra.baner...@aol.co.ukwrote: gtk_tree_view_set_rules_hint (GTK_TREE_VIEW(tree), TRUE); the rules_hint are not working, i.e. I am not getteing alternative color for each row. I'm not an expert, but it probably means your default theme does not pay attention to that hint. This could be harder to diagnose since every Gtk3 release has had an evolved theme, and your distro may be changing it as well. What I would do is learn how to use the GtkCssProvider and make the rows the color you want. http://developer.gnome.org/gtk3/stable/GtkCssProvider.html Someone more knowledgeable than I might speak up though. ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list