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