GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Fri Aug 29, 2014 12:00 pm

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Begginner C/GTK treeview/listview question
PostPosted: Sat May 10, 2008 2:16 pm 
Offline
GTK+ Geek

Joined: Sat May 10, 2008 1:52 pm
Posts: 54
Dear GTK Gurus,
I am just starting at GTK on Linux (I have been doing Windows programming...)
and I am running into some problem. I have a treeview widget in my main window and a button.
Upon creation I fill the treeview with value using the below code. It puts the
SigName character strings in the list.
Now my problem is that when I call LISTALL_Tree() from the button callback
again (when SigName strings are different) instead of displaint it in a single column it
adds as a new column to the existing list.
All I want is to refresh the list with the new value s.

Can anyone help, please:
Thanks.
Peter


v
Code:
oid LISTALL_Tree(GtkWidget *window) {
    GtkTreeIter iter, itersel;
    GtkWidget *treeview, *scrolled_win;
    GtkCellRenderer *renderer;
    GtkTreeViewColumn *column;
    GtkTreeModel *model;
     int i, j, R, Ndata, click = 0, n;
     char edtext[80];
   
    treeview = lookup_widget (window, "Signaltree");
    model = gtk_tree_view_get_model (GTK_TREE_VIEW (treeview));
    Ndata = sizeof(SigNames)/sizeof(SigNames[0]);
    store = gtk_list_store_new (1, G_TYPE_STRING);
    renderer = gtk_cell_renderer_text_new ();   
    column = gtk_tree_view_column_new_with_attributes ("Signal", renderer, "text",             
                 SIGNAME_COLUMN, NULL);
    gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
   // fill the tree
    for (i = 0; i < Ndata; i++) {
         /* Add a new row to the model */
       gtk_list_store_append (store, &iter);
       gtk_list_store_set (store, &iter, SIGNAME_COLUMN, SigNames[i], -1);
    }  // i
    treeview = lookup_widget (window, "Signaltree");
    gtk_tree_view_set_model(GTK_TREE_VIEW(treeview),
                                    GTK_TREE_MODEL(store));
    g_object_unref(store);
   gtk_widget_show(treeview);
}

// the button calback function:
on_ListAllbutton_clicked (GtkButton       *button,
                                        gpointer         user_data)
{
char edtext[80];
static int clicks = 0;
GtkWidget *InfoLabel, *treeview;
GtkTreeModel *model;


   treeview = lookup_widget (Mainwindow, "Signaltree");
   model = gtk_tree_view_get_model(treeview);
   store = GTK_LIST_STORE ( model );

   gtk_list_store_clear(store);
   LISTALL_Tree(Mainwindow);
}


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 10, 2008 4:06 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 12:07 am
Posts: 563
Location: Portland, OR USA
You only need to create the model and append columns once, typically when the application is first started. To repopulate, you'll only need to clear the model and then run through that little loop that puts data into the model:

Code:
for (i = 0; i < Ndata; i++) {
          /* Add a new row to the model */
       gtk_list_store_append (store, &iter);
       gtk_list_store_set (store, &iter, SIGNAME_COLUMN, SigNames[i], -1);
    }

_________________
Micah Carrick - Forum Administrator
http://www.micahcarrick.com


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 10, 2008 9:31 pm 
Offline
GTK+ Geek

Joined: Sat May 10, 2008 1:52 pm
Posts: 54
Micah Carrick wrote:
You only need to create the model and append columns once, typically when the application is first started. To repopulate, you'll only need to clear the model and then run through that little loop that puts data into the model:

Code:
for (i = 0; i < Ndata; i++) {
          /* Add a new row to the model */
       gtk_list_store_append (store, &iter);
       gtk_list_store_set (store, &iter, SIGNAME_COLUMN, SigNames[i], -1);
    }


Micah, thank you for the fast reply.
Queston about model:
Should I keep the model as global? Or in the callback recreate before the
little loop to populate the list:
treeview = lookup_widget (Mainwindow, "Signaltree");
model = gtk_tree_view_get_model(treeview);
store = GTK_LIST_STORE ( model );
for (....)...etc
Or set model as static in the Treesetupo function and call
Treesetup from the callback (bypassing the tree creation part) ?
Peter


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 10, 2008 10:50 pm 
Offline
GTK+ Geek

Joined: Sat May 10, 2008 1:52 pm
Posts: 54
Micah Carrick wrote:
You only need to create the model and append columns once, typically when the application is first started. To repopulate, you'll only need to clear the model and then run through that little loop that puts data into the model:

Code:
for (i = 0; i < Ndata; i++) {
          /* Add a new row to the model */
       gtk_list_store_append (store, &iter);
       gtk_list_store_set (store, &iter, SIGNAME_COLUMN, SigNames[i], -1);
    }


Deam Micah,

Still no go...
My button callback looks like this (see below);
When I start up the treview is created and shown with all list items in OK.
But when I press the button. only one item is shown in it and when I move the mouse pointer over the treeview list soem items pop up\out of the nowhere... strange.
What's going on?
Peter
PS: the compiler is complaining about the argument type of gtk_label_set_text(InfoLabel, edtext); What is the proper cast?
Here is is button press callback:
l:

Code:
void
on_LISTALLbutton_clicked               (GtkButton       *button,
                                        gpointer         user_data)
{
GtkWidget *InfoLabel;
char edtext[80];
static int clicks = 0, i, R;
GtkWidget *treeview;
GtkTreeModel *model;
GtkTreeIter iter;
GtkListStore *store;


  treeview = lookup_widget (Mainwindow, "Signaltree");
  model = gtk_tree_view_get_model(GTK_TREE_VIEW(treeview));
  store = GTK_LIST_STORE ( model );
  gtk_list_store_clear (store);
  for (i = 0; i < 7; i++) {
       gtk_list_store_append (store, &iter);
       gtk_list_store_set (store, &iter, SIGNAME_COLUMN, SigNames[i], -1);
  }
  InfoLabel = lookup_widget (Mainwindow, "Infolabel");
  clicks++;
  sprintf(edtext, "LISTALL:number of clicks:%d", clicks);
  gtk_label_set_text(InfoLabel, edtext);
  g_object_unref(store);
  gtk_widget_show(treeview);
}
[/code]


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group