Re: GtkTreeView isn't updating when GtkListStore appended and set

2014-01-07 Thread Colomban Wendling
Le 07/01/2014 22:48, Jordan H. a écrit :
> 
> Man, sorry, but I guess I'm still not getting this.
> 
> I've added a GtkTreeViewColumn and GtkCellRenderer to the GtkTreeView:
> 
> 
> Button Label
> True
> True
> 
> 
> 
> 

Actually the patch should look like this:

> --- button-actions.glade
> +++ button-actions.glade
> @@ -122,6 +122,17 @@
>  0
>   name="show_expanders">False
>   name="enable_grid_lines">horizontal
> +
> +   id="treeviewcolumn1">
> +Test
> +
> +   id="cellrenderertext1"/>
> +  
> +0
> +  
> +
> +  
> +
>
>  
>


> [...]
> 
> tree_view = GTK_TREE_VIEW( gtk_builder_get_object(builder,
> "treeview_button_order"));
> list_store = GTK_LIST_STORE( gtk_builder_get_object(builder,
> "liststore_button_list"));
> cell_renderer = GTK_CELL_RENDERER_TEXT(gtk_builder_get_object(builder,
> "cr_button"));
> column = GTK_TREE_VIEW_COLUMN(gtk_builder_get_object(builder,
> "tvcol_button"));
> 
> gtk_tree_view_column_pack_start(column,
> GTK_CELL_RENDERER(cell_renderer),
> TRUE);

why do you need to do all this?  Normally you add the column as a child
of the tree view so it works directly, no need to do it manually again.

> gtk_list_store_set(list_store, &iter, 0, last->title, -1);
> gtk_list_store_append(list_store, &iter);

This is wrong, you need to append to the store *before* setting the
values.  "iter" is only a mean of representing a position, nothing
holding your data.  So first, you append(), which sets the iter to the
newly added row, and then you set that row's data using set().

> g_object_set(G_OBJECT(cell_renderer), "text", last->title, NULL);

That's not correct.  The cell renderer object is used to *render* cells,
and only that.  The same will be used to render all rows, so setting the
property like that changes the one use to display all rows.  What you
should do is set up the column to set a particular property of the
renderer to the value of the cell it will render.

https://developer.gnome.org/gtk3/stable/GtkTreeViewColumn.html#gtk-tree-view-column-add-attribute

But if you had followed exactly what I told you, it should have been all
setup, to use the value of your "label" column.

> g_object_set(G_OBJECT(cell_renderer), "sensitive", TRUE, NULL);
> 
>
> gtk_tree_selection_set_mode(gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_view)),
>   GTK_SELECTION_NONE);
> }
> 
> +++
> 
> But I get odd behavior when I add stuff to the list. I know for a fact
> that last->title is being incremented (from "Button 1" to "Button 2",
> etc.). However, when the GtkTreeView is updated I get ["Button 1"] on
> the first click, ["Button 2", "Button 2"] on the second click, etc.

That's because you set the property on the cell renderer directly.  You
shouldn't do that for a property that should display a column's value.
Only do that for a property that should always be the same.

> I've followed the example at
> http://scentric.net/tutorial/sec-treeviewcol-renderer.html. From what I
> can tell GtkCellRenderer controls the entire GtkTreeView (I think the
> article says so, too). So then there doesn't seem to be any way to set
> individual elements.

That's right.  To set individual elements, you bind a column to a cell
renderer through the TreeViewColumn.

> Again, sorry for asking this question. Are GtkTreeViews supposed to be
> difficult or am I just not understanding something?

They are not so simple, because they try to be generic MVC, that's right.

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: GtkTreeView isn't updating when GtkListStore appended and set

2014-01-06 Thread Colomban Wendling
Le 06/01/2014 22:10, jorda...@fastmail.fm a écrit :
> I suppose an attachment would be helpful (weird that it didn't send).

OK, better now indeed.

So, your problem is that you don't add columns to your tree view.  A
TreeView [1] displays TreeViewColumns [2], which itself contain
CellRenderer [3].  Your UI definition lacks the columns and cell
renderers, so it effectively displays nothing, although the data is there.

You need to add a TreeViewColumn child to your TreeView widget, and a
CellRendererText to your column.

In Glade, right click on your tree view, go to the Hierarchy tab, and
click Add.
Now, right click on the column, and choose "Add a child Text" (or
something else, depending on what you want to display).
Finally, you need to define what that renderer displays, so you change
its "Text" property to your label column (change the "unset" dropdown to
"label - gchararray").

Now you should be all set and see your content.  You can of course add
several columns, and cells in each columns.  That will only depend on
your needs.


Regards,
Colomban


[1]
https://developer.gnome.org/gtk3/stable/GtkTreeView.html#GtkTreeView.description
[2]
https://developer.gnome.org/gtk3/stable/GtkTreeViewColumn.html#GtkTreeViewColumn.description
[3]
https://developer.gnome.org/gtk3/stable/GtkCellRenderer.html#GtkCellRenderer.description
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: GtkTreeView isn't updating when GtkListStore appended and set

2014-01-06 Thread jordannh
I suppose an attachment would be helpful (weird that it didn't send).
-- 
  
  jorda...@fastmail.fm


On Mon, Jan 6, 2014, at 08:50 AM, Colomban Wendling wrote:
> Hi,
> 
> Le 06/01/2014 17:26, Jordan H. a écrit :
> > Attached is the Glade file. The GtkListStore ("liststore_button_list")
> > is assigned the GtkTreeView ("treeview_button_order").
> 
> Looks like the attachment is missing.
> 
> > The GtkTreeView doesn't seem to reflect the changes made to the
> > GtkListStore.
> 
> No idea if it could be this, but someone recently had a similar issue
> because he's TreeView wasn't inside a ScrolledWindow, and GTK3 TreeView
> has a resizing bug in this case (so the value where there but the view
> was too small to show them).  So, is your TreeView in a ScrolledWindow,
> or does it help?
> 
> > I iterated through the GtkListStore itself and found that
> > values were being added.
> > 
> > if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(list_store), &iter)){
> > gtk_tree_model_get(GTK_TREE_MODEL(list_store), &iter, 0,
> > &test_value, -1);
> > g_debug(" - Value: \"%s\"", test_value);
> > }else{
> > g_warning("GtkTreeModel contains no elements!");
> > }
> > while (gtk_tree_model_iter_next(GTK_TREE_MODEL(list_store), &iter)){
> > memset(test_value, 0, sizeof(gchararray));
> > gtk_tree_model_get(GTK_TREE_MODEL(list_store), &iter, 0,
> > test_value, -1);
> > g_debug(" - Value: \"%s\"", test_value);
> 
> Wow, I don't know what you are trying to do here with the memset() and
> stuff.  "gchararray" in this context actually means "a C string",
> `gchar*`.  Also, gtk_tree_model_get() *duplicates* the data, so you want
> to free the memory afterwards.
> 
>   gchar *str;
>   gtk_tree_model_get(model, &iter, 0, &str, -1);
>   // ...
>   g_free(str);
> 
> 
> Not to duplicate code you also probably would rather implement iteration
> like this:
> 
>   if (gtk_tree_model_get_iter_first(...)) {
>   do {
>   ...
>   } while (gtk_tree_model_iter_next(...));
>   }
> 
> > I'm wondering if the mutilated strings is what's causing my problem. I'm
> > expecting the values to be "Button 1", "Button 2", etc., and the button
> > labels reflect this change (as expected).
> 
> This may be a reason if the data is actually wrong (I mean, if it's not
> your fetching when printing that is), because GtkCellRendererText
> requires UTF-8-encoded text.  But if this was the error, you'd see a lot
> of warnings in the terminal.
> 
> I see 3 possibilities:
> 
> 1) the tree model is not properly connected to the tree view;
> 
> 2) you didn't add CellRenderers;
> 
> 3) your tree view isn't packed in a ScrolledWindow and you experience
> the above-mentioned bug.
> 
> 
> Hope it helps.  Regards,
> Colomban
> ___
> 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: GtkTreeView isn't updating when GtkListStore appended and set

2014-01-06 Thread Colomban Wendling
Hi,

Le 06/01/2014 17:26, Jordan H. a écrit :
> Attached is the Glade file. The GtkListStore ("liststore_button_list")
> is assigned the GtkTreeView ("treeview_button_order").

Looks like the attachment is missing.

> The GtkTreeView doesn't seem to reflect the changes made to the
> GtkListStore.

No idea if it could be this, but someone recently had a similar issue
because he's TreeView wasn't inside a ScrolledWindow, and GTK3 TreeView
has a resizing bug in this case (so the value where there but the view
was too small to show them).  So, is your TreeView in a ScrolledWindow,
or does it help?

> I iterated through the GtkListStore itself and found that
> values were being added.
> 
> if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(list_store), &iter)){
> gtk_tree_model_get(GTK_TREE_MODEL(list_store), &iter, 0,
> &test_value, -1);
> g_debug(" - Value: \"%s\"", test_value);
> }else{
> g_warning("GtkTreeModel contains no elements!");
> }
> while (gtk_tree_model_iter_next(GTK_TREE_MODEL(list_store), &iter)){
> memset(test_value, 0, sizeof(gchararray));
> gtk_tree_model_get(GTK_TREE_MODEL(list_store), &iter, 0,
> test_value, -1);
> g_debug(" - Value: \"%s\"", test_value);

Wow, I don't know what you are trying to do here with the memset() and
stuff.  "gchararray" in this context actually means "a C string",
`gchar*`.  Also, gtk_tree_model_get() *duplicates* the data, so you want
to free the memory afterwards.

gchar *str;
gtk_tree_model_get(model, &iter, 0, &str, -1);
// ...
g_free(str);


Not to duplicate code you also probably would rather implement iteration
like this:

if (gtk_tree_model_get_iter_first(...)) {
do {
...
} while (gtk_tree_model_iter_next(...));
}

> I'm wondering if the mutilated strings is what's causing my problem. I'm
> expecting the values to be "Button 1", "Button 2", etc., and the button
> labels reflect this change (as expected).

This may be a reason if the data is actually wrong (I mean, if it's not
your fetching when printing that is), because GtkCellRendererText
requires UTF-8-encoded text.  But if this was the error, you'd see a lot
of warnings in the terminal.

I see 3 possibilities:

1) the tree model is not properly connected to the tree view;

2) you didn't add CellRenderers;

3) your tree view isn't packed in a ScrolledWindow and you experience
the above-mentioned bug.


Hope it helps.  Regards,
Colomban
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: GtkTreeView isn't updating when GtkListStore appended and set

2014-01-06 Thread Jordan H.
Thank you. I'll look into templates.

Attached is the Glade file. The GtkListStore ("liststore_button_list")
is assigned the GtkTreeView ("treeview_button_order").

The GtkTreeView doesn't seem to reflect the changes made to the
GtkListStore. I iterated through the GtkListStore itself and found that
values were being added.

if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(list_store), &iter)){
gtk_tree_model_get(GTK_TREE_MODEL(list_store), &iter, 0,
&test_value, -1);
g_debug(" - Value: \"%s\"", test_value);
}else{
g_warning("GtkTreeModel contains no elements!");
}
while (gtk_tree_model_iter_next(GTK_TREE_MODEL(list_store), &iter)){
memset(test_value, 0, sizeof(gchararray));
gtk_tree_model_get(GTK_TREE_MODEL(list_store), &iter, 0,
test_value, -1);
g_debug(" - Value: \"%s\"", test_value);
}

After 4 additions I get this:

** (punch:20412): DEBUG:  - Value: "Button 1"
** (punch:20412): DEBUG:  - Value: " \xce\xda\u0001"
** (punch:20412): DEBUG:  - Value: " P\xda\u0001"
** (punch:20412): DEBUG:  - Value: "@P\xda\u0001"

I'm wondering if the mutilated strings is what's causing my problem. I'm
expecting the values to be "Button 1", "Button 2", etc., and the button
labels reflect this change (as expected).

Thanks for your help, guys!

Tristan Van Berkom:
> On Sat, 2014-01-04 at 23:46 -0600, Michael Cronenworth wrote:
>> On 01/04/2014 05:21 PM, Jordan H. wrote:
>>> In Glade I've defined column "0" in the list store as a "gchararray"
>>> cell. I even tried forcing the assignment of GtkListStore to GtkTreeView
>>> (knowing full well I wouldn't need to) to no avail.
>>>
>>> I don't get any errors, but the GtkTreeView doesn't reflect the changes
>>> made to the GtkListStore. Any suggestions? Thanks in advance!
>> I haven't used Glade/GtkBuilder, but I'm not sure if it automatically 
>> assigns 
>> the ListStore column to the TreeView like you are thinking. You can make 
>> sure by 
>> calling a few functions.
>>
>> gtk_tree_view_set_model( tree_view, GTK_TREE_MODEL( list_store ) );
>> gtk_tree_view_column_add_attribute( column, cell, "text", 0 );
>> // 0 being the column you want to assign to the column in the GtkTreeView
> The treeview editor does indeed set these attributes for you and
> GtkBuilder properly sets them up.
>
> If you've declared the liststore with Glade before adding your cell
> renderers then Glade should let you set the column by name, even
> (Glade saves 'named' columns of the liststore in the form of xml
> comments, even if columns names are not a part of the GtkTreeModel 
> API). 
>
> Jordan, can your provide some more information ?
>
> For instance, are you certain that the treeview is not "updating"
> at the time you append only ? or is it not showing any of the data
> you added to the liststore "at all" ?
>
> Can you also show us the Glade file in question so I can see if
> it's indeed setup properly ?
>
> Also, instead of using GtkBuilder API directly (and even worse,
> needlessly keeping a GtkBuilder instance around for the life cycle
> of your UI component), please consider using the composite templates
> features introduced in GTK+ 3.10, it's a much cleaner way of using
> GtkBuilder (but only available in 3.10 so that might still be an
> issue for you)
>
> See this file for a quick example of a dialog:
> https://git.gnome.org/browse/glade/tree/src/glade-preferences.c#n172
>
> For more info on how composite templates work, see these posts:
> Vala:http://blogs.gnome.org/tvb/2013/05/29/composite-templates-lands-in-vala/
> C:http://blogs.gnome.org/tvb/2013/04/09/announcing-composite-widget-templates/
>
> Cheers,
> -Tristan
>
>> ___
>> 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: GtkTreeView isn't updating when GtkListStore appended and set

2014-01-05 Thread Tristan Van Berkom
On Sat, 2014-01-04 at 23:46 -0600, Michael Cronenworth wrote:
> On 01/04/2014 05:21 PM, Jordan H. wrote:
> > In Glade I've defined column "0" in the list store as a "gchararray"
> > cell. I even tried forcing the assignment of GtkListStore to GtkTreeView
> > (knowing full well I wouldn't need to) to no avail.
> >
> > I don't get any errors, but the GtkTreeView doesn't reflect the changes
> > made to the GtkListStore. Any suggestions? Thanks in advance!
> 
> I haven't used Glade/GtkBuilder, but I'm not sure if it automatically assigns 
> the ListStore column to the TreeView like you are thinking. You can make sure 
> by 
> calling a few functions.
> 
> gtk_tree_view_set_model( tree_view, GTK_TREE_MODEL( list_store ) );
> gtk_tree_view_column_add_attribute( column, cell, "text", 0 );
> // 0 being the column you want to assign to the column in the GtkTreeView

The treeview editor does indeed set these attributes for you and
GtkBuilder properly sets them up.

If you've declared the liststore with Glade before adding your cell
renderers then Glade should let you set the column by name, even
(Glade saves 'named' columns of the liststore in the form of xml
comments, even if columns names are not a part of the GtkTreeModel 
API). 

Jordan, can your provide some more information ?

For instance, are you certain that the treeview is not "updating"
at the time you append only ? or is it not showing any of the data
you added to the liststore "at all" ?

Can you also show us the Glade file in question so I can see if
it's indeed setup properly ?

Also, instead of using GtkBuilder API directly (and even worse,
needlessly keeping a GtkBuilder instance around for the life cycle
of your UI component), please consider using the composite templates
features introduced in GTK+ 3.10, it's a much cleaner way of using
GtkBuilder (but only available in 3.10 so that might still be an
issue for you)

See this file for a quick example of a dialog:
https://git.gnome.org/browse/glade/tree/src/glade-preferences.c#n172

For more info on how composite templates work, see these posts:
Vala:http://blogs.gnome.org/tvb/2013/05/29/composite-templates-lands-in-vala/
C:http://blogs.gnome.org/tvb/2013/04/09/announcing-composite-widget-templates/

Cheers,
-Tristan

> 
> ___
> 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: GtkTreeView isn't updating when GtkListStore appended and set

2014-01-04 Thread Michael Cronenworth

On 01/04/2014 05:21 PM, Jordan H. wrote:

In Glade I've defined column "0" in the list store as a "gchararray"
cell. I even tried forcing the assignment of GtkListStore to GtkTreeView
(knowing full well I wouldn't need to) to no avail.

I don't get any errors, but the GtkTreeView doesn't reflect the changes
made to the GtkListStore. Any suggestions? Thanks in advance!


I haven't used Glade/GtkBuilder, but I'm not sure if it automatically assigns 
the ListStore column to the TreeView like you are thinking. You can make sure by 
calling a few functions.


gtk_tree_view_set_model( tree_view, GTK_TREE_MODEL( list_store ) );
gtk_tree_view_column_add_attribute( column, cell, "text", 0 );
// 0 being the column you want to assign to the column in the GtkTreeView

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list